React-table: Unexpected sorting of alphanumeric strings

Created on 30 Apr 2020  路  2Comments  路  Source: tannerlinsley/react-table

Describe the bug (required)
There seems to be an issue with sorting alphanumeric strings -- I'd expect the order of the values to match that of Array.sort but it is not the case.

Provide an example via Codesandbox! (required)
https://codesandbox.io/s/patient-water-rhi33?file=/src/App.js

Steps To Reproduce (required)

  1. Go to the CodeSandbox
  2. Click on the "colName" header
  3. See that the order of the rows is ["bmlnbwj6bo5", "c9zh0gxho9rp", "c47jyh9le3v1"]

Expected behavior (Recommended)
I'd expect the order of the values to match that of Array.sort. That is,

["bmlnbwj6bo5", "c47jyh9le3v1", "c9zh0gxho9rp"]

Most helpful comment

This will be the new default in the next major version.

All 2 comments

@tannerlinsley This seems to be due to the default sortType "alphanumeric" which is splitting by numbers in strings: https://github.com/tannerlinsley/react-table/blob/dd8da8877cace91ca365d33d34c5544bc2b59a59/src/sortTypes.js#L13-L16

I'm wondering if this is necessary out-of-the-box. Especially if the mixed sorting is slow, as the comments in that file suggest. Could the default sort be with the browser's Array.sort()? The sortType "alphanumeric" could still be an option, for use cases that need it.

This will be the new default in the next major version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

monarajhans picture monarajhans  路  3Comments

bdkersey picture bdkersey  路  3Comments

panfiva picture panfiva  路  3Comments

kieronsutton00 picture kieronsutton00  路  3Comments

esetnik picture esetnik  路  3Comments