Minimalistic table sorter
$ component install jb55/tablesort
var tablesort = require('tablesort')
var table = document.querySelector('table')
var sorter = tablesort(table);
sorter.on('sort', function(order, header, index){
header.style.backgroundColor = order === 'asc'? 'red' : 'blue';
});
var sorter = tablesort(el, {
sort: function(header, index){
var title = header.textContent;
if (title === 'complicatedColumn')
return complicatedSort;
return tablesort.defaultSort;
}
});
The table requires thead
and tbody
elements.
MIT