Sort objects by property instead of value
This commit is contained in:
parent
5416676735
commit
224e436828
10
src/Main.js
10
src/Main.js
|
@ -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
|
||||||
|
|
||||||
|
if (entry.type === 'array') {
|
||||||
ordered.sort((a, b) => compare(a.value, b.value))
|
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
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue