jQuery Plugin For Multi-column Table Sorting - tablesort.js

File Size: 12.2 KB
Views Total: 6980
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin For Multi-column Table Sorting - tablesort.js

Just another jQuery plugin for muitl-column table sorting that allows you to sort table cells using string comparison or custom sort functions.

How to use it:

1. Load the latest version of jQuery library and the jQuery tablesort.js script in the html page.

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="jquery.tablesort.min.js"></script>

2. Call the function on the target table element and done.

$('table').tablesort();

3. Custom the sort value using data-sort-value attribute.

<td data-sort-value="2">October 7, 1968</td>

4. Disable the sort functionality on a specific column using no-sort attribute.

<th class="no-sort">NO SORT</th>

5. Custom sort function.

// Sort by dates in YYYY-MM-DD format
$('thead th.date').data('sortBy', function(th, td, tablesort) {
    return new Date(td.text());
});

// Sort hex values, ie: "FF0066":
$('thead th.hex').data('sortBy', function(th, td, tablesort) {
    return parseInt(td.text(), 16);
});

// Sort by an arbitrary object, ie: a Backbone model:
$('thead th.personID').data('sortBy', function(th, td, tablesort) {
    return App.People.get(td.text());
});

Change log:

2016-10-02

  • v0.0.11

2016-08-21

  • v0.0.10: Support jQuery 2.2.x

This awesome jQuery plugin is developed by kylefox. For more Advanced Usages, please check the demo page or visit the official website.