Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Expects a string with a ':' delimiter. Meant for Vue.js select markup elements and table rendering
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));
});
},
@staghouse

This comment has been minimized.

Copy link
Owner Author

@staghouse staghouse commented Feb 13, 2019

Based on original code here: https://jsbin.com/wowezadolo/edit?js,console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment