Skip to content

Commit c737b37

Browse files
committed
chore(Table): fixed incorrect sorting in demo
1 parent 58c9fa4 commit c737b37

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

packages/react-table/src/demos/examples/TableSortableResponsive.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ export const TableSortableResponsive: React.FunctionComponent = () => {
4949
const sortRows = (rows: SampleDataRow[], sortIndex: number, sortDirection: Direction) =>
5050
[...rows].sort((a, b) => {
5151
let returnValue = 0;
52-
if (sortIndex === 0 || sortIndex === 7) {
53-
returnValue = 1;
54-
} else if (typeof Object.values(a)[sortIndex] === 'number') {
52+
if (typeof Object.values(a)[sortIndex] === 'number') {
5553
// numeric sort
5654
returnValue = Object.values(a)[sortIndex] - Object.values(b)[sortIndex];
5755
} else {
58-
// string sort
59-
returnValue = Object.values(a)[sortIndex].localeCompare(Object.values(b)[sortIndex]);
56+
// string sort using natural sort
57+
returnValue = Object.values(a)[sortIndex].localeCompare(Object.values(b)[sortIndex], undefined, {numeric: true});
6058
}
6159
if (sortDirection === 'desc') {
6260
return returnValue * -1;

0 commit comments

Comments
 (0)