Add click-to-sort capability to any table.
Supports sorting by numbers, strings, dates, checkboxes, and input values.
A table can be set up for sorting just by passing the table element (or its ID) to the TableSorter constructor:
<table id="dataTable"> <tr> <th>ID</th> <th>Name</th> <th>Balance</th> <th>DatAdded</th> </tr> ... table data ... </table> #JS var tableSorter = new TableSorter('dataTable');
To enable the more specialized data-type awareness for sort comparisons, we explicitly name them as an option:
var tableSorter = new TableSorter('dataTable', { columnDataTypes: 'int, string, money, date' });
To enable persistent sort state for this column (via cookie), we supply a cookie name:
var tableSorter = new TableSorter('dataTable', { cookieName: 'tableSortState' });
Tables should be styled via CSS however you usually would style them, but TableSorter suggests adding two more classes to visually highlight columns which are sorted:
table th.sortAsc { background: #a8d4e3 url(../images/headerRowBGSortAsc.png) 100% 0 repeat-x; color: #fff; } table th.sortDesc { background: #a8d4e3 url(../images/headerRowBGSortDesc.png) 100% 0 repeat-x; color: #fff; }
There are a few options of TableSorter to customize its behavior:
core:1.4.2/Events core:1.4.2/Options
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus