Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 688 Bytes

Readme.md

File metadata and controls

40 lines (28 loc) · 688 Bytes

tablesort

Minimalistic table sorter

Installation

$ component install jb55/tablesort

Example

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';
});

Custom sort

var sorter = tablesort(el, {
  sort: function(header, index){
    var title = header.textContent;
    if (title === 'complicatedColumn')
      return complicatedSort;
    return tablesort.defaultSort;
  }
});

Gotchas

The table requires thead and tbody elements.

License

MIT