Skip to content

Commit 3a503e9

Browse files
chore(Table): fixed incorrect sorting in table demo (#11894)
* chore(Table): fixed incorrect sorting in demo * Fixed lint error * Update TableSortableResponsive.tsx --------- Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>
1 parent 5d51afa commit 3a503e9

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ 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, {
58+
numeric: true
59+
});
6060
}
6161
if (sortDirection === 'desc') {
6262
return returnValue * -1;

0 commit comments

Comments
 (0)