Skip to content

Commit

Permalink
sort table alternative correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahfossheim committed Nov 8, 2024
1 parent 0d062cc commit aea33e1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/js/techreport/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ function formatData(tableConfig, data) {
table.push(row);
}

return table;
const sorted = sortTableBy(table, 'date');

return sorted;
}

function sortTableBy(dataset, key) {
return dataset.sort((a, b) => {
const selectedA = a.find(obj => obj.key === key);
const selectedB = b.find(obj => obj.key === key);

return selectedA.value > selectedB.value ? -1 : 1;
});
}

function getColumnCell(columnConfig, data, date) {
Expand Down

0 comments on commit aea33e1

Please sign in to comment.