Open
Description
TanStack Table version
8.20.5
Framework/Library version
"react": "^18.2.0",
Describe the bug and the steps to reproduce it
Code Logic: The getAutoSortDir function dynamically determines the initial sort direction based on the type of the first row's value in the column.
-
If it's a string, the sort direction is asc.
-
If it's not a string (e.g., null or number), the sort direction defaults to desc.
Problem: When the first row's value changes due to sorting, the logic re-evaluates, potentially toggling between sort states unpredictably. In your case:
-
Initial value in the first row is not a string → sort starts as desc.
-
After sorting, the first value changes to a string → subsequent toggle resets or disables sorting.
column.getAutoSortDir = () => {
const firstRow = table.getFilteredRowModel().flatRows[0]
const value = firstRow?.getValue(column.id)
if (typeof value === 'string') {
return 'asc'
}
return 'desc'
}
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
nda
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
None
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.
Metadata
Metadata
Assignees
Labels
No labels