Created
March 13, 2019 11:51
-
-
Save tomaash/3df0a5cce745493f8f9397fe6fd97c69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HACK: restore sort order, which has been lost by react admin for some reason | |
const asc = currentSort.order === 'ASC' | |
const topValue = asc ? 1 : -1 | |
const bottomValue = asc ? -1 : 1 | |
const { field } = currentSort | |
// Data is passed as an object, which is not sorted | |
const keys = Object.keys(data || {}) | |
const dataArray = keys | |
.map(k => data[k]) | |
.sort((a, b) => { | |
if (a[field] > b[field]) return topValue | |
if (a[field] < b[field]) return bottomValue | |
return 0 | |
}) | |
const ids = dataArray.map(item => item.id) | |
const total = ids.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment