You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Automatic datetime sorting function crashes when null values exist #4041
A column with mostly Date values will automatically use the datetime sort function, but that function does not handle nulls and crashes on the call to getTime().
The datetime sorting function should not crash with null / undefined values.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
All
react-table version
8.0.0-beta.9
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct
I agree to follow this project's Code of Conduct
I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@pavlos256 A workaround would be to add your own sortingFn and use that, like below:
Define your custom sortingFn
let table = createTable()
.setOptions({
sortingFns: {
sortNullableDate: (rowA: any, rowB: any, columnId: any): number => {
function compareBasic(a: any, b: any) {
return a === b ? 0 : a > b ? 1 : -1
}
return compareBasic(
(rowA.getValue(columnId) as Date)?.getTime(), // added "?." on this line
(rowB.getValue(columnId) as Date)?.getTime() // added "?." on this line
)
},
},
})
Activity
abdullahtariq1171 commentedon Jun 24, 2022
Should we check for nullish values in sortinFns? @tannerlinsley
This is where it is crashing
table/packages/table-core/src/sortingFns.ts
Lines 39 to 40 in cc9ff13
@pavlos256 A workaround would be to add your own sortingFn and use that, like below:
Define your custom sortingFn
use it for desired column
tannerlinsley commentedon Jul 7, 2022
I think we should handle it in the core. PRs are welcome :)