Created
February 13, 2019 11:08
-
-
Save staghouse/3af947d9c519adc31995160febc558f0 to your computer and use it in GitHub Desktop.
Expects a string with a ':' delimiter. Meant for Vue.js select markup elements and table rendering
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
sortBy(event = '') { | |
let values = event.currentTarget | |
? event.currentTarget.value.split(':') | |
: event.split(':'); | |
let cfg = { | |
prop: values[0], | |
desc: values[1] ? -1 : 1, | |
parser: function(x) { | |
return x; | |
}, | |
}; | |
let parse = function(x) { | |
return x; | |
}; | |
let getItem = function(x) { | |
var isObject = x != null && typeof x === 'object'; | |
var isProp = isObject && this.prop in x; | |
return this.parser(isProp ? x[this.prop] : x); | |
}; | |
return this.defaultList.sort((a, b) => { | |
a = getItem.call(cfg, a); | |
b = getItem.call(cfg, b); | |
return cfg.desc * (a < b ? -1 : +(a > b)); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment