Skip to content

jb55/tablesort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Minimalistic table sorting component

Resources

Stars

Watchers

Forks

Packages

No packages published