Category Archives: Javascript

Tablesorter Size Display Plugin

After using the tablesorter Javascript JQuery plugin a number of times, I finally wrote a nifty little widget to get the size of the table once you sort it.
This plugin works with the Bootstrap Tablesorter version.


// Custom Widget to display current list size of the sortable table
$.tablesorter.addWidget({
// give the widget a id
id: "tableRowDisplayCount",
// format is called when the on init and when a sorting has finished
format: function(table) {
var totalRows = table.tBodies[0].rows.length;
var totalRowsHidden = 0;
for (var i=0; i < totalRows; i++) { if (table.tBodies[0].rows[i].style.display === "none") totalRowsHidden++; } var displayText = "(" + (totalRows - totalRowsHidden) + ")"; $('#table_row_display').html(displayText); } });