Skip to content

Instantly share code, notes, and snippets.

@RobertAKARobin
Created October 2, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertAKARobin/e4717d4140a8ae608c0c76d696416e62 to your computer and use it in GitHub Desktop.
Save RobertAKARobin/e4717d4140a8ae608c0c76d696416e62 to your computer and use it in GitHub Desktop.
var people = [/*some data*/];
var sortable = function(callback){
return {
isSorting: false,
onclick: function(event){
var element = this;
people.sort(function(personA, personB){
var valA = callback(personA);
var valB = callback(personB);
if(valA > valB){
return -1
}else if(valA < valB){
return 1
}else{
return 0;
}
});
element.setAttribute('isSorting', true);
}
}
}
return {
view: function(){
m('th', sortable(function(person){
return person.name.toLowerCase().replace(/[^a-zA-Z0-9]/g,'');
}), 'Name'),
m('th', sortable(function(person){
return person.age;
}), 'Age')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment