TanStack Table version#
8.21.3
Framework/Library version#
React 19
Describe the bug and the steps to reproduce it#
In TanStack table, sorting is case insensitive by default for alphanumeric or text columns, unless the user specifies that it should be case sensitive. However, the getAutoSortingFn function does not work as intended when there are fewer than 10 rows in a table. In that case, the sorting function becomes basic by default, which uses JavaScript’s native < and > operators. Therefore, the case sensitivity becomes inconsistent, even for the same type of data.
The bug is entirely caused by the improper use of the .slice() function when sampling rows in https://github.com/TanStack/table/blob/main/packages/table-core/src/features/RowSorting.ts#L308:
const firstRows = table.getFilteredRowModel().flatRows.slice(10)
When only one parameter is supplied to Array.prototype.slice(), it represents the starting index rather than the ending index. So unless the table has at least 10 rows, nothing gets sampled and sortingFns.basic is returned.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
https://codesandbox.io/p/sandbox/6dcrjq
Screenshots or Videos (Optional)#
No response
Do you intend to try to help solve this bug with your own PR?#
Yes, I am also opening a PR that solves the problem along side this issue
Terms & Code of Conduct#
It looks like it has been resolved in the alpha branch. We can close the issue.