Tablesorter - simultaneous table sorting & filtering
All options included, as well as the uitheme widget
by Mottie
HTML
<script src="http://mottie.github.com/tablesorter/js/jquery.tablesorter.js"></script>
<script src="http://mottie.github.com/tablesorter/js/jquery.tablesorter.widgets.js"></script>
<link rel="stylesheet" href="http://mottie.github.com/tablesorter/css/theme.blue.css">
<table class="tablesorter">
<thead>
<tr>
<th>AlphaNumeric</th>
<th>Numeric</th>
<th>Animals</th>
<th>Sites</th>
</tr>
</thead>
<tfoot>
<tr>
<th>AlphaNumeric</th>
<th>Numeric</th>
<th>Animals</th>
<th>Sites</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>abc 123</td>
<td>10</td>
<td>Koala</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>abc 1</td>
<td>234</td>
<td>Ox</td>
<td>http://www.yahoo.com</td>
</tr>
<tr>
<td>abc 9</td>
<td>10</td>
<td>Girafee</td>
<td>http://www.facebook.com</td>
</tr>
<tr>
<td>zyx 24</td>
<td>767</td>
<td>Bison</td>
<td>http://www.whitehouse.gov/</td>
</tr>
</tbody>
</table>
<br>
<table class="tablesorter">
<thead>
<tr>
<th>AlphaNumeric</th>
<th>Numeric</th>
<th>Animals</th>
<th>Sites</th>
</tr>
</thead>
<tfoot>
<tr>
<th>AlphaNumeric</th>
<th>Numeric</th>
<th>Animals</th>
<th>Sites</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>abc 11</td>
<td>3</td>
<td>Chimp</td>
<td>http://www.ucla.edu/</td>
</tr>
<tr>
<td>abc 2</td>
<td>56</td>
<td>Elephant</td>
<td>http://www.wikipedia.org/</td>
</tr>
<tr>
<td>abc...
JavaScript
var ts = $.tablesorter,
sorting = false,
searching = false;
$('table')
.tablesorter({
theme: 'blue',
widthFixed: true,
widgets: ['filter']
})
.on('sortBegin filterEnd', function (e, filters) {
if (!(sorting || searching)) {
var table = this,
c = table.config,
filters = ts.getFilters(table),
$sibs = $('.tablesorter').not( c.$table );
if (!sorting) {
sorting = true;
$sibs.trigger('sorton', [c.sortList, function () {
setTimeout(function () {
sorting = false;
}, 500);
}]);
}
if (!searching) {
$sibs.each(function () {
if (this.hasInitialized) {
ts.setFilters(this, filters, true);
}
});
setTimeout(function () {
searching = false;
}, 500);
}
}
});