Sort objects by property instead of value

This commit is contained in:
jos 2016-07-30 20:37:00 +02:00
parent 5416676735
commit 224e436828
1 changed files with 9 additions and 3 deletions

View File

@ -159,14 +159,15 @@ export default class Main extends Component {
this.handleHideContextMenu() // TODO: should be handled by the contextmenu itself this.handleHideContextMenu() // TODO: should be handled by the contextmenu itself
const entry = this._getIn(path)
let _order let _order
if (order === 'asc' || order === 'desc') { if (order === 'asc' || order === 'desc') {
_order = order _order = order
} }
else { else {
// toggle previous order // toggle previous order
const current = this._getIn(path, ['order']) _order = entry.order !== 'asc' ? 'asc' : 'desc'
_order = current !== 'asc' ? 'asc' : 'desc'
this._setIn(path, ['order'], _order) this._setIn(path, ['order'], _order)
} }
@ -174,7 +175,12 @@ export default class Main extends Component {
const ordered = childs.slice(0) const ordered = childs.slice(0)
const compare = _order === 'desc' ? compareDesc : compareAsc const compare = _order === 'desc' ? compareDesc : compareAsc
ordered.sort((a, b) => compare(a.value, b.value)) if (entry.type === 'array') {
ordered.sort((a, b) => compare(a.value, b.value))
}
else { // entry.type === 'object'
ordered.sort((a, b) => compare(a.prop, b.prop))
}
return ordered return ordered
}) })