Skip to content

Commit 98f52f3

Browse files
[docs] Fix the broken Table sorting logic (#12569)
1 parent c96ce73 commit 98f52f3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/src/pages/demos/tables/EnhancedTable.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ function createData(name, calories, fat, carbs, protein) {
2525
return { id: counter, name, calories, fat, carbs, protein };
2626
}
2727

28+
function desc(a, b, orderBy) {
29+
if (b[orderBy] < a[orderBy]) {
30+
return -1;
31+
}
32+
if (b[orderBy] > a[orderBy]) {
33+
return 1;
34+
}
35+
return 0;
36+
}
37+
2838
function getSorting(order, orderBy) {
29-
return order === 'desc' ? (a, b) => b[orderBy] - a[orderBy] : (a, b) => a[orderBy] - b[orderBy];
39+
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) => -desc(a, b, orderBy);
3040
}
3141

3242
const rows = [

0 commit comments

Comments
 (0)