Created
October 2, 2017 14:27
-
-
Save RobertAKARobin/e4717d4140a8ae608c0c76d696416e62 to your computer and use it in GitHub Desktop.
This file contains 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
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