-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined being included in sorting when setting sortUndefined to false. #4113
Comments
I think what you are looking for is |
@tannerlinsley thanks for your reply. It took me some time to figure out why my custom sorting is not working. I have percentage data that reaches from negative to positive values. If a value is missing, this item should never be on top of the sorting (since I do not know if it should be there). When setting I think what I would need is Or am I doing something wrong at all? |
I have similar issue |
Me too |
Okay, I was able to do this. You should set (a: Row<ITableDataRow>, b: Row<ITableDataRow>, column: string): number => {
const aValue = a.getValue<number | undefined>(column);
const bValue = b.getValue<number | undefined>(column);
if (aValue === undefined && bValue === undefined) {
return 0;
}
if (aValue === undefined) {
return desc ? -1 : 1;
}
if (bValue === undefined) {
return desc ? 1 : -1;
}
return aValue - bValue;
}
|
It is also possible to pass the Copy-paste it from table-core utils - https://github.com/TanStack/table/blob/main/packages/table-core/src/utils/getSortedRowModel.ts remove the inversion of the undefined sorted values It was introduced in this commit. It is not a big change |
This is a bit of a blocker for us too. Even passing |
Describe the bug
Setting up a table of data with the latest table release. When having the following:
Sorting the column places all of the cells with "-" which should be undefined, at the top of the list.
I'm trying to have a way where any undefined accessorFn is always placed at the end of the table, irrespective of the direction being sorted.
Your minimal, reproducible example
N/A
Steps to reproduce
Create a standard table with sorting and try to have the undefined cells places last at the end of the table rows when sorting.
Expected behavior
Have all undefined values in cells places at the end of the list irrespective of sort direction
How often does this bug happen?
No response
Screenshots or Videos
No response
Platform
Windows
react-table version
8.1.4
TypeScript version
4.7.4
Additional context
No response
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: