React-table: Number sorting not "working" as expected

Created on 16 Nov 2017  路  2Comments  路  Source: tannerlinsley/react-table

I have a column that is numbered .. 1, 2, 3, 4,...8, 9, 10. 11, 12, etc

I would expect when sorted it would sort 1-12.

Instead I get it sorts like this:
1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9

I wouldn't think this is the intention, am I wrong?

Most helpful comment

First check to ensure your number is actually a number and not a string. A string will not sort numerically and would need to be converted to a number (similarly with dates). For example:

            {
              Header: 'Record Number',
              id: 'recordNumber',
              accessor: d=>Number(d.recordNumber),
            },

NOTE: you require id because the accessor needs to be a function (and react-table actually operates on the id internally but usually creates it from the accessor if it is string-based).

Other than that, I can't really say what would be wrong without a working example of the problem.

I also suggest you join the #react-table channel on Slack. The github issues are only monitored by a small group of people that are trying to triage the requests. The Slack channel is full of a lot of developers using react-table in various stack environments. There is a badge at the top of the README in the doco. Thanks.

All 2 comments

First check to ensure your number is actually a number and not a string. A string will not sort numerically and would need to be converted to a number (similarly with dates). For example:

            {
              Header: 'Record Number',
              id: 'recordNumber',
              accessor: d=>Number(d.recordNumber),
            },

NOTE: you require id because the accessor needs to be a function (and react-table actually operates on the id internally but usually creates it from the accessor if it is string-based).

Other than that, I can't really say what would be wrong without a working example of the problem.

I also suggest you join the #react-table channel on Slack. The github issues are only monitored by a small group of people that are trying to triage the requests. The Slack channel is full of a lot of developers using react-table in various stack environments. There is a badge at the top of the README in the doco. Thanks.

@gary-menzel what if we have data like version numbers ['1.0.6', '1.0.8', '17.9.1'] how could you suggest sorting here? Please let me know

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agray5 picture agray5  路  39Comments

sshaginyan picture sshaginyan  路  21Comments

Codar97 picture Codar97  路  17Comments

BenMGilman picture BenMGilman  路  22Comments

visarts picture visarts  路  36Comments