Skip to content
Source
Sign inSign up
TanStack/table

Sorting is case sensitive for tables with fewer than 10 rows #6290

Send to my agent
ClosedTao-X02(GitHub profile, opens in a new tab) opened this issue 1 comment

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.

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

  • 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.
  1. It looks like it has been resolved in the alpha branch. We can close the issue.

Sign in to join this conversation.