Skip to content

Commit

Permalink
[docs] Fix the broken Table sorting logic (#12569)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Aug 18, 2018
1 parent c96ce73 commit 98f52f3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/src/pages/demos/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ function createData(name, calories, fat, carbs, protein) {
return { id: counter, name, calories, fat, carbs, protein };
}

function desc(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}

function getSorting(order, orderBy) {
return order === 'desc' ? (a, b) => b[orderBy] - a[orderBy] : (a, b) => a[orderBy] - b[orderBy];
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) => -desc(a, b, orderBy);
}

const rows = [
Expand Down

0 comments on commit 98f52f3

Please sign in to comment.