Skip to content

Instantly share code, notes, and snippets.

@tomaash
Created March 13, 2019 11:51
Show Gist options
  • Save tomaash/3df0a5cce745493f8f9397fe6fd97c69 to your computer and use it in GitHub Desktop.
Save tomaash/3df0a5cce745493f8f9397fe6fd97c69 to your computer and use it in GitHub Desktop.
// 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