diff --git a/README.markdown b/README.markdown index 3ada87fc..ad2d6863 100644 Binary files a/README.markdown and b/README.markdown differ diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index 31bd2be4..6ed40c98 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -1,485 +1,497 @@ -/*! - * tablesorter pager plugin - * updated 10/13/2012 - */ -/*jshint browser:true, jquery:true */ -;(function($) { - "use strict"; - $.extend({tablesorterPager: new function() { - - this.defaults = { - // target the pager markup - container: null, - - // use this format: "http:/mydatabase.com?page={page}&size={size}" - // where {page} is replaced by the page number and {size} is replaced by the number of records to show - ajaxUrl: null, - - // process ajax so that the following information is returned: - // [ total_rows (number), rows (array of arrays), headers (array; optional) ] - // example: - // [ - // 100, // total rows - // [ - // [ "row1cell1", "row1cell2", ... "row1cellN" ], - // [ "row2cell1", "row2cell2", ... "row2cellN" ], - // ... - // [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] - // ], - // [ "header1", "header2", ... "headerN" ] // optional - // ] - ajaxProcessing: function(ajax){ return [ 0, [], null ]; }, - - // output default: '{page}/{totalPages}' - // possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows} - output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}' - - // apply disabled classname to the pager arrows when the rows at either extreme is visible - updateArrows: true, - - // starting page of the pager (zero based index) - page: 0, - - // Number of visible rows - size: 10, - - // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty - // table row set to a height to compensate; default is false - fixedHeight: false, - - // remove rows from the table to speed up the sort of large tables. - // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled. - removeRows: false, // removing rows in larger tables speeds up the sort - - // css class names of pager arrows - cssFirst: '.first', // go to first page arrow - cssPrev: '.prev', // previous page arrow - cssNext: '.next', // next page arrow - cssLast: '.last', // go to last page arrow - cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page - cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed - cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option - - // class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page) - cssDisabled: 'disabled', // Note there is no period "." in front of this class name - - // stuff not set by the user - totalRows: 0, - totalPages: 0, - filteredRows: 0, - filteredPages : 0 - - }; - - var $this = this, - - // hide arrows at extremes - pagerArrows = function(c, disable) { - var a = 'addClass', - r = 'removeClass', - d = c.cssDisabled, - dis = !!disable, - // tr = Math.min( c.totalRows, c.filteredRows ), - tp = Math.min( c.totalPages, c.filteredPages ); - if ( c.updateArrows ) { - $(c.cssFirst + ',' + c.cssPrev, c.container)[ ( dis || c.page === 0 ) ? a : r ](d); - $(c.cssNext + ',' + c.cssLast, c.container)[ ( dis || c.page === tp - 1 ) ? a : r ](d); - } - }, - - updatePageDisplay = function(table, c) { - var i, p, s, t, out, f = $(table).hasClass('hasFilters'); - c.filteredRows = (f) ? $(table).find('tbody tr:not(.filtered)').length : c.totalRows; - c.filteredPages = (f) ? Math.ceil( c.filteredRows / c.size ) : c.totalPages; - if ( Math.min( c.totalPages, c.filteredPages ) > 0 ) { - t = (c.size * c.page > c.filteredRows); - c.startRow = (t) ? 1 : ( c.size * c.page ) + 1; - c.page = (t) ? 0 : c.page; - c.endRow = Math.min( c.filteredRows, c.totalRows, c.size * ( c.page + 1 ) ); - out = $(c.cssPageDisplay, c.container); - // form the output string - s = c.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi, function(m){ - return { - '{page}' : c.page + 1, - '{filteredRows}' : c.filteredRows, - '{filteredPages}' : c.filteredPages, - '{totalPages}' : c.totalPages, - '{startRow}' : c.startRow, - '{endRow}' : c.endRow, - '{totalRows}' : c.totalRows - }[m]; - }); - if (out[0]) { - out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s); - if ( $(c.cssGoto, c.container).length ) { - t = ''; - p = Math.min( c.totalPages, c.filteredPages ); - for ( i = 1; i <= p; i++ ) { - t += ''; - } - $(c.cssGoto, c.container).html(t).val(c.page + 1); - } - } - } - pagerArrows(c); - $(table).trigger('pagerComplete', c); - }, - - fixHeight = function(table, c) { - var d, h, $b = $(table.tBodies[0]); - if (c.fixedHeight) { - $b.find('tr.pagerSavedHeightSpacer').remove(); - h = $.data(table, 'pagerSavedHeight'); - if (h) { - d = h - $b.height(); - if ( d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.find('tr:visible').length < c.size ) { - $b.append(''); - } - } - } - }, - - changeHeight = function(table, c) { - var $b = $(table.tBodies[0]); - $b.find('tr.pagerSavedHeightSpacer').remove(); - $.data(table, 'pagerSavedHeight', $b.height()); - fixHeight(table, c); - $.data(table, 'pagerLastSize', c.size); - }, - - hideRows = function(table, c){ - if (!c.ajaxUrl) { - var i, - rows = $('tr:not(.' + table.config.cssChildRow + ')', table.tBodies), - l = rows.length, - s = ( c.page * c.size ), - e = s + c.size, - j = 0; // size counter - for ( i = 0; i < l; i++ ){ - if (!/filtered/.test(rows[i].className)) { - rows[i].style.display = ( j >= s && j < e ) ? '' : 'none'; - j++; - } - } - } - }, - - hideRowsSetup = function(table, c){ - c.size = parseInt( $(c.cssPageSize, c.container).val(), 10 ) || c.size; - $.data(table, 'pagerLastSize', c.size); - pagerArrows(c); - if ( !c.removeRows ) { - hideRows(table, c); - $(table).bind('sortEnd.pager filterEnd.pager', function(){ - hideRows(table, c); - }); - } - }, - - renderAjax = function(data, table, c, exception){ - // process data - if ( typeof(c.ajaxProcessing) === "function" ) { - // ajaxProcessing result: [ total, rows, headers ] - var i, j, hsh, $f, $sh, - $t = $(table), - tc = table.config, - $b = $(table.tBodies).filter(':not(.' + tc.cssInfoBlock + ')'), - hl = $t.find('thead th').length, tds = '', - err = '' + - (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '', - result = c.ajaxProcessing(data) || [ 0, [] ], - d = result[1] || [], - l = d.length, - th = result[2]; - if ( l > 0 ) { - for ( i = 0; i < l; i++ ) { - tds += ''; - for ( j = 0; j < d[i].length; j++ ) { - // build tbody cells - tds += '' + d[i][j] + ''; - } - tds += ''; - } - } - // only add new header text if the length matches - if ( th && th.length === hl ) { - hsh = $t.hasClass('hasStickyHeaders'); - $sh = $t.find('.' + ((tc.widgetOptions && tc.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader')); - $f = $t.find('tfoot tr:first').children(); - $t.find('th.' + tc.cssHeader).each(function(j){ - var $t = $(this), tar, icn; - // add new test within the first span it finds, or just in the header - if ( $t.find('.' + tc.cssIcon).length ) { - icn = $t.find('.' + tc.cssIcon).clone(true); - $t.find('.tablesorter-header-inner').html( th[j] ).append(icn); - if ( hsh && $sh.length ) { - icn = $sh.find('th').eq(j).find('.' + tc.cssIcon).clone(true); - $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icn); - } - } else { - $t.find('.tablesorter-header-inner').html( th[j] ); - $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ); - } - $f.eq(j).html( th[j] ); - // update sticky headers - if ( hsh && $sh.length ){ - tar = $sh.find('th').eq(j); - tar = ( tar.find('span').length ) ? tar.find('span:first') : tar; - tar.html( th[j] ); - } - }); - } - if ( exception ) { - // add error row to thead instead of tbody, or clicking on the header will result in a parser error - $t.find('thead').append(err); - } else { - $b.html( tds ); // add tbody - } - c.temp.remove(); // remove loading icon - $t.trigger('update'); - c.totalRows = result[0] || 0; - c.totalPages = Math.ceil( c.totalRows / c.size ); - updatePageDisplay(table, c); - fixHeight(table, c); - $t.trigger('pagerChange', c); - } - }, - - getAjax = function(table, c){ - var $t = $(table), - url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size); - if ( url !== '' ) { - // loading icon - c.temp = $('
', { - 'class' : 'tablesorter-processing', - width : $t.outerWidth(true), - height: $t.outerHeight(true) - }); - $t.before( c.temp ); - $(document).ajaxError(function(e, xhr, settings, exception) { - renderAjax(null, table, c, exception); - }); - $.getJSON(url, function(data) { - renderAjax(data, table, c); - }); - } - }, - - renderTable = function(table, rows, c) { - var i, j, o, - f = document.createDocumentFragment(), - l = rows.length, - s = ( c.page * c.size ), - e = ( s + c.size ); - if ( l < 1 ) { return; } // empty table, abort! - $(table).trigger('pagerChange', c); - if ( !c.removeRows ) { - hideRows(table, c); - } else { - if ( e > rows.length ) { - e = rows.length; - } - $(table.tBodies[0]).addClass('tablesorter-hidden'); - $.tablesorter.clearTableBody(table); - for ( i = s; i < e; i++ ) { - o = rows[i]; - l = o.length; - for ( j = 0; j < l; j++ ) { - f.appendChild(o[j]); - } - } - table.tBodies[0].appendChild(f); - $(table.tBodies[0]).removeClass('tablesorter-hidden'); - } - if ( c.page >= c.totalPages ) { - moveToLastPage(table, c); - } - updatePageDisplay(table, c); - if ( !c.isDisabled ) { fixHeight(table, c); } - $(table).trigger('applyWidgets'); - }, - - showAllRows = function(table, c){ - if ( c.ajax ) { - pagerArrows(c, true); - } else { - c.isDisabled = true; - $.data(table, 'pagerLastPage', c.page); - $.data(table, 'pagerLastSize', c.size); - c.page = 0; - c.size = c.totalRows; - c.totalPages = 1; - $('tr.pagerSavedHeightSpacer', table.tBodies[0]).remove(); - renderTable(table, table.config.rowsCopy, c); - } - // disable size selector - $(c.cssPageSize, c.container).addClass(c.cssDisabled)[0].disabled = true; - }, - - moveToPage = function(table, c) { - if ( c.isDisabled ) { return; } - var p = Math.min( c.totalPages, c.filteredPages ); - if ( c.page < 0 || c.page > ( p - 1 ) ) { - c.page = 0; - } - $.data(table, 'pagerLastPage', c.page); - if ( c.ajax ) { - getAjax(table, c); - } else { - renderTable(table, table.config.rowsCopy, c); - } - - $(table).trigger('pageMoved', c); - }, - - setPageSize = function(table, size, c) { - c.size = size; - $.data(table, 'pagerLastPage', c.page); - $.data(table, 'pagerLastSize', c.size); - c.totalPages = Math.ceil( c.totalRows / c.size ); - moveToPage(table, c); - }, - - moveToFirstPage = function(table, c) { - c.page = 0; - moveToPage(table, c); - }, - - moveToLastPage = function(table, c) { - c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); - moveToPage(table, c); - }, - - moveToNextPage = function(table, c) { - c.page++; - if ( c.page >= ( Math.min( c.totalPages, c.filteredPages ) - 1 ) ) { - c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); - } - moveToPage(table, c); - }, - - moveToPrevPage = function(table, c) { - c.page--; - if ( c.page <= 0 ) { - c.page = 0; - } - moveToPage(table, c); - }, - - destroyPager = function(table, c){ - showAllRows(table, c); - $(c.container).hide(); // hide pager - table.config.appender = null; // remove pager appender function - $(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager'); - }, - - enablePager = function(table, c, triggered){ - var p = $(c.cssPageSize, c.container).removeClass(c.cssDisabled).removeAttr('disabled'); - c.isDisabled = false; - c.page = $.data(table, 'pagerLastPage') || c.page || 0; - c.size = $.data(table, 'pagerLastSize') || parseInt(p.val(), 10) || c.size; - c.totalPages = Math.ceil( Math.min( c.totalPages, c.filteredPages ) / c.size); - if ( triggered ) { - $(table).trigger('update'); - setPageSize(table, c.size, c); - hideRowsSetup(table, c); - fixHeight(table, c); - } - }; - - $this.appender = function(table, rows) { - var c = table.config.pager; - if ( !c.ajax ) { - table.config.rowsCopy = rows; - c.totalRows = rows.length; - c.size = $.data(table, 'pagerLastSize') || c.size; - c.totalPages = Math.ceil(c.totalRows / c.size); - renderTable(table, rows, c); - } - }; - - $this.construct = function(settings) { - return this.each(function() { - var config = this.config, - c = config.pager = $.extend( {}, $.tablesorterPager.defaults, settings ), - table = this, - $t = $(table), - pager = $(c.container).addClass('tablesorter-pager').show(); // added in case the pager is reinitialized after being destroyed. - config.appender = $this.appender; - enablePager(table, c, false); - if ( typeof(c.ajaxUrl) === 'string' ) { - // ajax pager; interact with database - c.ajax = true; - getAjax(table, c); - } else { - c.ajax = false; - // Regular pager; all rows stored in memory - $(this).trigger("appendCache", true); - hideRowsSetup(table, c); - } - - if ( $(table).hasClass('hasFilters') ) { - $(table).unbind('filterEnd.pager').bind('filterEnd.pager', function() { - c.page = 0; - updatePageDisplay(table, c); - moveToPage(table, c); - changeHeight(table, c); - }); - } - if ( $(c.cssGoto, pager).length ) { - $(c.cssGoto, pager).bind('change', function(){ - c.page = $(this).val() - 1; - moveToPage(table, c); - }); - updatePageDisplay(table, c); - } - $(c.cssFirst,pager).unbind('click.pager').bind('click.pager', function() { - if ( !$(this).hasClass(c.cssDisabled) ) { moveToFirstPage(table, c); } - return false; - }); - $(c.cssNext,pager).unbind('click.pager').bind('click.pager', function() { - if ( !$(this).hasClass(c.cssDisabled) ) { moveToNextPage(table, c); } - return false; - }); - $(c.cssPrev,pager).unbind('click.pager').bind('click.pager', function() { - if ( !$(this).hasClass(c.cssDisabled) ) { moveToPrevPage(table, c); } - return false; - }); - $(c.cssLast,pager).unbind('click.pager').bind('click.pager', function() { - if ( !$(this).hasClass(c.cssDisabled) ) { moveToLastPage(table, c); } - return false; - }); - $(c.cssPageSize,pager).unbind('change.pager').bind('change.pager', function() { - $(c.cssPageSize,pager).val( $(this).val() ); // in case there are more than one pagers - if ( !$(this).hasClass(c.cssDisabled) ) { - setPageSize(table, parseInt( $(this).val(), 10 ), c); - changeHeight(table, c); - } - return false; - }); - - $t - .unbind('disable.pager enable.pager destroy.pager update.pager') - .bind('disable.pager', function(){ - showAllRows(table, c); - }) - .bind('enable.pager', function(){ - enablePager(table, c, true); - }) - .bind('destroy.pager', function(){ - destroyPager(table, c); - }) - .bind('update.pager', function(){ - hideRows(table, c); - }); - }); - }; - - }() -}); -// extend plugin scope -$.fn.extend({ - tablesorterPager: $.tablesorterPager.construct -}); - +/*! + * tablesorter pager plugin + * updated 10/15/2012 + */ +/*jshint browser:true, jquery:true */ +;(function($) { + "use strict"; + $.extend({tablesorterPager: new function() { + + this.defaults = { + // target the pager markup + container: null, + + // use this format: "http:/mydatabase.com?page={page}&size={size}" + // where {page} is replaced by the page number and {size} is replaced by the number of records to show + ajaxUrl: null, + + // process ajax so that the following information is returned: + // [ total_rows (number), rows (array of arrays), headers (array; optional) ] + // example: + // [ + // 100, // total rows + // [ + // [ "row1cell1", "row1cell2", ... "row1cellN" ], + // [ "row2cell1", "row2cell2", ... "row2cellN" ], + // ... + // [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] + // ], + // [ "header1", "header2", ... "headerN" ] // optional + // ] + ajaxProcessing: function(ajax){ return [ 0, [], null ]; }, + + // output default: '{page}/{totalPages}' + // possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows} + output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}' + + // apply disabled classname to the pager arrows when the rows at either extreme is visible + updateArrows: true, + + // starting page of the pager (zero based index) + page: 0, + + // Number of visible rows + size: 10, + + // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty + // table row set to a height to compensate; default is false + fixedHeight: false, + + // remove rows from the table to speed up the sort of large tables. + // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled. + removeRows: false, // removing rows in larger tables speeds up the sort + + // css class names of pager arrows + cssFirst: '.first', // go to first page arrow + cssPrev: '.prev', // previous page arrow + cssNext: '.next', // next page arrow + cssLast: '.last', // go to last page arrow + cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page + cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed + cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option + + // class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page) + cssDisabled: 'disabled', // Note there is no period "." in front of this class name + + // stuff not set by the user + totalRows: 0, + totalPages: 0, + filteredRows: 0, + filteredPages : 0 + + }; + + var $this = this, + + // hide arrows at extremes + pagerArrows = function(c, disable) { + var a = 'addClass', + r = 'removeClass', + d = c.cssDisabled, + dis = !!disable, + // tr = Math.min( c.totalRows, c.filteredRows ), + tp = Math.min( c.totalPages, c.filteredPages ); + if ( c.updateArrows ) { + $(c.cssFirst + ',' + c.cssPrev, c.container)[ ( dis || c.page === 0 ) ? a : r ](d); + $(c.cssNext + ',' + c.cssLast, c.container)[ ( dis || c.page === tp - 1 ) ? a : r ](d); + } + }, + + updatePageDisplay = function(table, c) { + var i, p, s, t, out, f = $(table).hasClass('hasFilters'); + c.filteredRows = (f) ? $(table).find('tbody tr:not(.filtered)').length : c.totalRows; + c.filteredPages = (f) ? Math.ceil( c.filteredRows / c.size ) : c.totalPages; + if ( Math.min( c.totalPages, c.filteredPages ) > 0 ) { + t = (c.size * c.page > c.filteredRows); + c.startRow = (t) ? 1 : ( c.size * c.page ) + 1; + c.page = (t) ? 0 : c.page; + c.endRow = Math.min( c.filteredRows, c.totalRows, c.size * ( c.page + 1 ) ); + out = $(c.cssPageDisplay, c.container); + // form the output string + s = c.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi, function(m){ + return { + '{page}' : c.page + 1, + '{filteredRows}' : c.filteredRows, + '{filteredPages}' : c.filteredPages, + '{totalPages}' : c.totalPages, + '{startRow}' : c.startRow, + '{endRow}' : c.endRow, + '{totalRows}' : c.totalRows + }[m]; + }); + if (out[0]) { + out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s); + if ( $(c.cssGoto, c.container).length ) { + t = ''; + p = Math.min( c.totalPages, c.filteredPages ); + for ( i = 1; i <= p; i++ ) { + t += ''; + } + $(c.cssGoto, c.container).html(t).val(c.page + 1); + } + } + } + pagerArrows(c); + if (c.initialized) { $(table).trigger('pagerComplete', c); } + }, + + fixHeight = function(table, c) { + var d, h, $b = $(table.tBodies[0]); + if (c.fixedHeight) { + $b.find('tr.pagerSavedHeightSpacer').remove(); + h = $.data(table, 'pagerSavedHeight'); + if (h) { + d = h - $b.height(); + if ( d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.find('tr:visible').length < c.size ) { + $b.append(''); + } + } + } + }, + + changeHeight = function(table, c) { + var $b = $(table.tBodies[0]); + $b.find('tr.pagerSavedHeightSpacer').remove(); + $.data(table, 'pagerSavedHeight', $b.height()); + fixHeight(table, c); + $.data(table, 'pagerLastSize', c.size); + }, + + hideRows = function(table, c){ + if (!c.ajaxUrl) { + var i, + rows = $('tr:not(.' + table.config.cssChildRow + ')', table.tBodies), + l = rows.length, + s = ( c.page * c.size ), + e = s + c.size, + j = 0; // size counter + for ( i = 0; i < l; i++ ){ + if (!/filtered/.test(rows[i].className)) { + rows[i].style.display = ( j >= s && j < e ) ? '' : 'none'; + j++; + } + } + } + }, + + hideRowsSetup = function(table, c){ + c.size = parseInt( $(c.cssPageSize, c.container).val(), 10 ) || c.size; + $.data(table, 'pagerLastSize', c.size); + pagerArrows(c); + if ( !c.removeRows ) { + hideRows(table, c); + $(table).bind('sortEnd.pager filterEnd.pager', function(){ + hideRows(table, c); + }); + } + }, + + renderAjax = function(data, table, c, exception){ + // process data + if ( typeof(c.ajaxProcessing) === "function" ) { + // ajaxProcessing result: [ total, rows, headers ] + var i, j, hsh, $f, $sh, + $t = $(table), + tc = table.config, + $b = $(table.tBodies).filter(':not(.' + tc.cssInfoBlock + ')'), + hl = $t.find('thead th').length, tds = '', + err = '' + + (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '', + result = c.ajaxProcessing(data) || [ 0, [] ], + d = result[1] || [], + l = d.length, + th = result[2]; + if ( l > 0 ) { + for ( i = 0; i < l; i++ ) { + tds += ''; + for ( j = 0; j < d[i].length; j++ ) { + // build tbody cells + tds += '' + d[i][j] + ''; + } + tds += ''; + } + } + // only add new header text if the length matches + if ( th && th.length === hl ) { + hsh = $t.hasClass('hasStickyHeaders'); + $sh = $t.find('.' + ((tc.widgetOptions && tc.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader')); + $f = $t.find('tfoot tr:first').children(); + $t.find('th.' + tc.cssHeader).each(function(j){ + var $t = $(this), tar, icn; + // add new test within the first span it finds, or just in the header + if ( $t.find('.' + tc.cssIcon).length ) { + icn = $t.find('.' + tc.cssIcon).clone(true); + $t.find('.tablesorter-header-inner').html( th[j] ).append(icn); + if ( hsh && $sh.length ) { + icn = $sh.find('th').eq(j).find('.' + tc.cssIcon).clone(true); + $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icn); + } + } else { + $t.find('.tablesorter-header-inner').html( th[j] ); + $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ); + } + $f.eq(j).html( th[j] ); + // update sticky headers + if ( hsh && $sh.length ){ + tar = $sh.find('th').eq(j); + tar = ( tar.find('span').length ) ? tar.find('span:first') : tar; + tar.html( th[j] ); + } + }); + } + if ( exception ) { + // add error row to thead instead of tbody, or clicking on the header will result in a parser error + $t.find('thead').append(err); + } else { + $b.html( tds ); // add tbody + } + c.temp.remove(); // remove loading icon + if (c.initialized) { $t.trigger('update'); } + c.totalRows = result[0] || 0; + c.totalPages = Math.ceil( c.totalRows / c.size ); + updatePageDisplay(table, c); + fixHeight(table, c); + if (c.initialized) { $t.trigger('pagerChange', c); } + } + if (!c.initialized) { + c.initialized = true; + $(table).trigger('pagerInitialized', c); + } + }, + + getAjax = function(table, c){ + var $t = $(table), + url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size); + if ( url !== '' ) { + // loading icon + c.temp = $('
', { + 'class' : 'tablesorter-processing', + width : $t.outerWidth(true), + height: $t.outerHeight(true) + }); + $t.before( c.temp ); + $(document).ajaxError(function(e, xhr, settings, exception) { + renderAjax(null, table, c, exception); + }); + $.getJSON(url, function(data) { + renderAjax(data, table, c); + }); + } + }, + + renderTable = function(table, rows, c) { + var i, j, o, + f = document.createDocumentFragment(), + l = rows.length, + s = ( c.page * c.size ), + e = ( s + c.size ); + if ( l < 1 ) { return; } // empty table, abort! + if (c.initialized) { $(table).trigger('pagerChange', c); } + if ( !c.removeRows ) { + hideRows(table, c); + } else { + if ( e > rows.length ) { + e = rows.length; + } + $(table.tBodies[0]).addClass('tablesorter-hidden'); + $.tablesorter.clearTableBody(table); + for ( i = s; i < e; i++ ) { + o = rows[i]; + l = o.length; + for ( j = 0; j < l; j++ ) { + f.appendChild(o[j]); + } + } + table.tBodies[0].appendChild(f); + $(table.tBodies[0]).removeClass('tablesorter-hidden'); + } + if ( c.page >= c.totalPages ) { + moveToLastPage(table, c); + } + updatePageDisplay(table, c); + if ( !c.isDisabled ) { fixHeight(table, c); } + $(table).trigger('applyWidgets'); + }, + + showAllRows = function(table, c){ + if ( c.ajax ) { + pagerArrows(c, true); + } else { + c.isDisabled = true; + $.data(table, 'pagerLastPage', c.page); + $.data(table, 'pagerLastSize', c.size); + c.page = 0; + c.size = c.totalRows; + c.totalPages = 1; + $('tr.pagerSavedHeightSpacer', table.tBodies[0]).remove(); + renderTable(table, table.config.rowsCopy, c); + } + // disable size selector + $(c.cssPageSize, c.container).addClass(c.cssDisabled)[0].disabled = true; + }, + + moveToPage = function(table, c) { + if ( c.isDisabled ) { return; } + var p = Math.min( c.totalPages, c.filteredPages ); + if ( c.page < 0 || c.page > ( p - 1 ) ) { + c.page = 0; + } + $.data(table, 'pagerLastPage', c.page); + if ( c.ajax ) { + getAjax(table, c); + } else { + renderTable(table, table.config.rowsCopy, c); + } + if (c.initialized) { $(table).trigger('pageMoved', c); } + }, + + setPageSize = function(table, size, c) { + c.size = size; + $.data(table, 'pagerLastPage', c.page); + $.data(table, 'pagerLastSize', c.size); + c.totalPages = Math.ceil( c.totalRows / c.size ); + moveToPage(table, c); + }, + + moveToFirstPage = function(table, c) { + c.page = 0; + moveToPage(table, c); + }, + + moveToLastPage = function(table, c) { + c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); + moveToPage(table, c); + }, + + moveToNextPage = function(table, c) { + c.page++; + if ( c.page >= ( Math.min( c.totalPages, c.filteredPages ) - 1 ) ) { + c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); + } + moveToPage(table, c); + }, + + moveToPrevPage = function(table, c) { + c.page--; + if ( c.page <= 0 ) { + c.page = 0; + } + moveToPage(table, c); + }, + + destroyPager = function(table, c){ + showAllRows(table, c); + $(c.container).hide(); // hide pager + table.config.appender = null; // remove pager appender function + $(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager'); + }, + + enablePager = function(table, c, triggered){ + var p = $(c.cssPageSize, c.container).removeClass(c.cssDisabled).removeAttr('disabled'); + c.isDisabled = false; + c.page = $.data(table, 'pagerLastPage') || c.page || 0; + c.size = $.data(table, 'pagerLastSize') || parseInt(p.val(), 10) || c.size; + c.totalPages = Math.ceil( Math.min( c.totalPages, c.filteredPages ) / c.size); + if ( triggered ) { + $(table).trigger('update'); + setPageSize(table, c.size, c); + hideRowsSetup(table, c); + fixHeight(table, c); + } + }; + + $this.appender = function(table, rows) { + var c = table.config.pager; + if ( !c.ajax ) { + table.config.rowsCopy = rows; + c.totalRows = rows.length; + c.size = $.data(table, 'pagerLastSize') || c.size; + c.totalPages = Math.ceil(c.totalRows / c.size); + renderTable(table, rows, c); + } + }; + + $this.construct = function(settings) { + return this.each(function() { + var config = this.config, + c = config.pager = $.extend( {}, $.tablesorterPager.defaults, settings ), + table = this, + $t = $(table), + pager = $(c.container).addClass('tablesorter-pager').show(); // added in case the pager is reinitialized after being destroyed. + config.appender = $this.appender; + // clear initialized flag + c.initialized = false; + enablePager(table, c, false); + if ( typeof(c.ajaxUrl) === 'string' ) { + // ajax pager; interact with database + c.ajax = true; + getAjax(table, c); + } else { + c.ajax = false; + // Regular pager; all rows stored in memory + $(this).trigger("appendCache", true); + hideRowsSetup(table, c); + } + + // update pager after filter widget completes + if ( $(table).hasClass('hasFilters') ) { + $(table).unbind('filterEnd.pager').bind('filterEnd.pager', function() { + c.page = 0; + updatePageDisplay(table, c); + moveToPage(table, c); + changeHeight(table, c); + }); + } + if ( $(c.cssGoto, pager).length ) { + $(c.cssGoto, pager).bind('change', function(){ + c.page = $(this).val() - 1; + moveToPage(table, c); + }); + updatePageDisplay(table, c); + } + $(c.cssFirst,pager).unbind('click.pager').bind('click.pager', function() { + if ( !$(this).hasClass(c.cssDisabled) ) { moveToFirstPage(table, c); } + return false; + }); + $(c.cssNext,pager).unbind('click.pager').bind('click.pager', function() { + if ( !$(this).hasClass(c.cssDisabled) ) { moveToNextPage(table, c); } + return false; + }); + $(c.cssPrev,pager).unbind('click.pager').bind('click.pager', function() { + if ( !$(this).hasClass(c.cssDisabled) ) { moveToPrevPage(table, c); } + return false; + }); + $(c.cssLast,pager).unbind('click.pager').bind('click.pager', function() { + if ( !$(this).hasClass(c.cssDisabled) ) { moveToLastPage(table, c); } + return false; + }); + $(c.cssPageSize,pager).unbind('change.pager').bind('change.pager', function() { + $(c.cssPageSize,pager).val( $(this).val() ); // in case there are more than one pagers + if ( !$(this).hasClass(c.cssDisabled) ) { + setPageSize(table, parseInt( $(this).val(), 10 ), c); + changeHeight(table, c); + } + return false; + }); + + $t + .unbind('disable.pager enable.pager destroy.pager update.pager') + .bind('disable.pager', function(){ + showAllRows(table, c); + }) + .bind('enable.pager', function(){ + enablePager(table, c, true); + }) + .bind('destroy.pager', function(){ + destroyPager(table, c); + }) + .bind('update.pager', function(){ + hideRows(table, c); + }); + + // pager initialized + if (!c.ajax) { + c.initialized = true; + $(table).trigger('pagerInitialized', c); + } + }); + }; + + }() +}); +// extend plugin scope +$.fn.extend({ + tablesorterPager: $.tablesorterPager.construct +}); + })(jQuery); \ No newline at end of file diff --git a/addons/pager/jquery.tablesorter.pager.min.js b/addons/pager/jquery.tablesorter.pager.min.js index eea1bdc4..28e0c17a 100644 --- a/addons/pager/jquery.tablesorter.pager.min.js +++ b/addons/pager/jquery.tablesorter.pager.min.js @@ -1,2 +1,2 @@ -/*! tablesorter pager plugin minified - updated 10/13/2012 */ -(function(a){"use strict";a.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(a){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:true,page:0,size:10,fixedHeight:false,removeRows:false,cssFirst:".first",cssPrev:".prev",cssNext:".next",cssLast:".last",cssGoto:".gotoPage",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0,filteredRows:0,filteredPages:0};var b=this,c=function(b,c){var d="addClass",e="removeClass",f=b.cssDisabled,g=!!c,h=Math.min(b.totalPages,b.filteredPages);if(b.updateArrows){a(b.cssFirst+","+b.cssPrev,b.container)[g||b.page===0?d:e](f);a(b.cssNext+","+b.cssLast,b.container)[g||b.page===h-1?d:e](f)}},d=function(b,d){var e,f,g,h,i,j=a(b).hasClass("hasFilters");d.filteredRows=j?a(b).find("tbody tr:not(.filtered)").length:d.totalRows;d.filteredPages=j?Math.ceil(d.filteredRows/d.size):d.totalPages;if(Math.min(d.totalPages,d.filteredPages)>0){h=d.size*d.page>d.filteredRows;d.startRow=h?1:d.size*d.page+1;d.page=h?0:d.page;d.endRow=Math.min(d.filteredRows,d.totalRows,d.size*(d.page+1));i=a(d.cssPageDisplay,d.container);g=d.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi,function(a){return{"{page}":d.page+1,"{filteredRows}":d.filteredRows,"{filteredPages}":d.filteredPages,"{totalPages}":d.totalPages,"{startRow}":d.startRow,"{endRow}":d.endRow,"{totalRows}":d.totalRows}[a]});if(i[0]){i[i[0].tagName==="INPUT"?"val":"html"](g);if(a(d.cssGoto,d.container).length){h="";f=Math.min(d.totalPages,d.filteredPages);for(e=1;e<=f;e++){h+=""}a(d.cssGoto,d.container).html(h).val(d.page+1)}}}c(d);a(b).trigger("pagerComplete",d)},e=function(b,c){var d,e,f=a(b.tBodies[0]);if(c.fixedHeight){f.find("tr.pagerSavedHeightSpacer").remove();e=a.data(b,"pagerSavedHeight");if(e){d=e-f.height();if(d>5&&a.data(b,"pagerLastSize")===c.size&&f.find("tr:visible").length')}}}},f=function(b,c){var d=a(b.tBodies[0]);d.find("tr.pagerSavedHeightSpacer").remove();a.data(b,"pagerSavedHeight",d.height());e(b,c);a.data(b,"pagerLastSize",c.size)},g=function(b,c){if(!c.ajaxUrl){var d,e=a("tr:not(."+b.config.cssChildRow+")",b.tBodies),f=e.length,g=c.page*c.size,h=g+c.size,i=0;for(d=0;d=g&&i'+(g?g.message+" ("+g.name+")":"No rows found")+"",s=f.ajaxProcessing(b)||[0,[]],t=s[1]||[],u=t.length,v=s[2];if(u>0){for(h=0;h";for(i=0;i"+t[h][i]+""}q+=""}}if(v&&v.length===p){j=m.hasClass("hasStickyHeaders");l=m.find("."+(n.widgetOptions&&n.widgetOptions.stickyHeaders||"tablesorter-stickyheader"));k=m.find("tfoot tr:first").children();m.find("th."+n.cssHeader).each(function(b){var c=a(this),d,e;if(c.find("."+n.cssIcon).length){e=c.find("."+n.cssIcon).clone(true);c.find(".tablesorter-header-inner").html(v[b]).append(e);if(j&&l.length){e=l.find("th").eq(b).find("."+n.cssIcon).clone(true);l.find("th").eq(b).find(".tablesorter-header-inner").html(v[b]).append(e)}}else{c.find(".tablesorter-header-inner").html(v[b]);l.find("th").eq(b).find(".tablesorter-header-inner").html(v[b])}k.eq(b).html(v[b]);if(j&&l.length){d=l.find("th").eq(b);d=d.find("span").length?d.find("span:first"):d;d.html(v[b])}})}if(g){m.find("thead").append(r)}else{o.html(q)}f.temp.remove();m.trigger("update");f.totalRows=s[0]||0;f.totalPages=Math.ceil(f.totalRows/f.size);d(c,f);e(c,f);m.trigger("pagerChange",f)}},j=function(b,c){var d=a(b),e=c.ajaxUrl.replace(/\{page\}/g,c.page).replace(/\{size\}/g,c.size);if(e!==""){c.temp=a("
",{"class":"tablesorter-processing",width:d.outerWidth(true),height:d.outerHeight(true)});d.before(c.temp);a(document).ajaxError(function(a,d,e,f){i(null,b,c,f)});a.getJSON(e,function(a){i(a,b,c)})}},k=function(b,c,f){var h,i,j,k=document.createDocumentFragment(),l=c.length,m=f.page*f.size,n=m+f.size;if(l<1){return}a(b).trigger("pagerChange",f);if(!f.removeRows){g(b,f)}else{if(n>c.length){n=c.length}a(b.tBodies[0]).addClass("tablesorter-hidden");a.tablesorter.clearTableBody(b);for(h=m;h=f.totalPages){p(b,f)}d(b,f);if(!f.isDisabled){e(b,f)}a(b).trigger("applyWidgets")},l=function(b,d){if(d.ajax){c(d,true)}else{d.isDisabled=true;a.data(b,"pagerLastPage",d.page);a.data(b,"pagerLastSize",d.size);d.page=0;d.size=d.totalRows;d.totalPages=1;a("tr.pagerSavedHeightSpacer",b.tBodies[0]).remove();k(b,b.config.rowsCopy,d)}a(d.cssPageSize,d.container).addClass(d.cssDisabled)[0].disabled=true},m=function(b,c){if(c.isDisabled){return}var d=Math.min(c.totalPages,c.filteredPages);if(c.page<0||c.page>d-1){c.page=0}a.data(b,"pagerLastPage",c.page);if(c.ajax){j(b,c)}else{k(b,b.config.rowsCopy,c)}a(b).trigger("pageMoved",c)},n=function(b,c,d){d.size=c;a.data(b,"pagerLastPage",d.page);a.data(b,"pagerLastSize",d.size);d.totalPages=Math.ceil(d.totalRows/d.size);m(b,d)},o=function(a,b){b.page=0;m(a,b)},p=function(a,b){b.page=Math.min(b.totalPages,b.filteredPages)-1;m(a,b)},q=function(a,b){b.page++;if(b.page>=Math.min(b.totalPages,b.filteredPages)-1){b.page=Math.min(b.totalPages,b.filteredPages)-1}m(a,b)},r=function(a,b){b.page--;if(b.page<=0){b.page=0}m(a,b)},s=function(b,c){l(b,c);a(c.container).hide();b.config.appender=null;a(b).unbind("destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager")},t=function(b,c,d){var f=a(c.cssPageSize,c.container).removeClass(c.cssDisabled).removeAttr("disabled");c.isDisabled=false;c.page=a.data(b,"pagerLastPage")||c.page||0;c.size=a.data(b,"pagerLastSize")||parseInt(f.val(),10)||c.size;c.totalPages=Math.ceil(Math.min(c.totalPages,c.filteredPages)/c.size);if(d){a(b).trigger("update");n(b,c.size,c);h(b,c);e(b,c)}};b.appender=function(b,c){var d=b.config.pager;if(!d.ajax){b.config.rowsCopy=c;d.totalRows=c.length;d.size=a.data(b,"pagerLastSize")||d.size;d.totalPages=Math.ceil(d.totalRows/d.size);k(b,c,d)}};b.construct=function(c){return this.each(function(){var e=this.config,i=e.pager=a.extend({},a.tablesorterPager.defaults,c),k=this,u=a(k),v=a(i.container).addClass("tablesorter-pager").show();e.appender=b.appender;t(k,i,false);if(typeof i.ajaxUrl==="string"){i.ajax=true;j(k,i)}else{i.ajax=false;a(this).trigger("appendCache",true);h(k,i)}if(a(k).hasClass("hasFilters")){a(k).unbind("filterEnd.pager").bind("filterEnd.pager",function(){i.page=0;d(k,i);m(k,i);f(k,i)})}if(a(i.cssGoto,v).length){a(i.cssGoto,v).bind("change",function(){i.page=a(this).val()-1;m(k,i)});d(k,i)}a(i.cssFirst,v).unbind("click.pager").bind("click.pager",function(){if(!a(this).hasClass(i.cssDisabled)){o(k,i)}return false});a(i.cssNext,v).unbind("click.pager").bind("click.pager",function(){if(!a(this).hasClass(i.cssDisabled)){q(k,i)}return false});a(i.cssPrev,v).unbind("click.pager").bind("click.pager",function(){if(!a(this).hasClass(i.cssDisabled)){r(k,i)}return false});a(i.cssLast,v).unbind("click.pager").bind("click.pager",function(){if(!a(this).hasClass(i.cssDisabled)){p(k,i)}return false});a(i.cssPageSize,v).unbind("change.pager").bind("change.pager",function(){a(i.cssPageSize,v).val(a(this).val());if(!a(this).hasClass(i.cssDisabled)){n(k,parseInt(a(this).val(),10),i);f(k,i)}return false});u.unbind("disable.pager enable.pager destroy.pager update.pager").bind("disable.pager",function(){l(k,i)}).bind("enable.pager",function(){t(k,i,true)}).bind("destroy.pager",function(){s(k,i)}).bind("update.pager",function(){g(k,i)})})}}});a.fn.extend({tablesorterPager:a.tablesorterPager.construct})})(jQuery) \ No newline at end of file +/*! tablesorter pager plugin minified - updated 10/15/2012 */ +;(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!1,cssFirst:".first",cssPrev:".prev",cssNext:".next",cssLast:".last",cssGoto:".gotoPage",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0,filteredRows:0,filteredPages:0};var p=this,r=function(c,b){var a= c.cssDisabled,e=!!b,f=Math.min(c.totalPages,c.filteredPages);c.updateArrows&&(d(c.cssFirst+","+c.cssPrev,c.container)[e||0===c.page?"addClass":"removeClass"](a),d(c.cssNext+","+c.cssLast,c.container)[e||c.page===f-1?"addClass":"removeClass"](a))},t=function(c,b){var a,e,f;a=d(c).hasClass("hasFilters");b.filteredRows=a?d(c).find("tbody tr:not(.filtered)").length:b.totalRows;b.filteredPages=a?Math.ceil(b.filteredRows/b.size):b.totalPages;if(0 b.filteredRows,b.startRow=f?1:b.size*b.page+1,b.page=f?0:b.page,b.endRow=Math.min(b.filteredRows,b.totalRows,b.size*(b.page+1)),e=d(b.cssPageDisplay,b.container),a=b.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi,function(a){return{"{page}":b.page+1,"{filteredRows}":b.filteredRows,"{filteredPages}":b.filteredPages,"{totalPages}":b.totalPages,"{startRow}":b.startRow,"{endRow}":b.endRow,"{totalRows}":b.totalRows}[a]}),e[0]&&(e["INPUT"===e[0].tagName?"val": "html"](a),d(b.cssGoto,b.container).length))){f="";e=Math.min(b.totalPages,b.filteredPages);for(a=1;a<=e;a++)f+="";d(b.cssGoto,b.container).html(f).val(b.page+1)}r(b);b.initialized&&d(c).trigger("pagerComplete",b)},u=function(c,b){var a,e=d(c.tBodies[0]);if(b.fixedHeight&&(e.find("tr.pagerSavedHeightSpacer").remove(),a=d.data(c,"pagerSavedHeight")))a-=e.height(),5')},s=function(c,b){var a=d(c.tBodies[0]);a.find("tr.pagerSavedHeightSpacer").remove();d.data(c,"pagerSavedHeight",a.height());u(c,b);d.data(c,"pagerLastSize",b.size)},q=function(c,b){if(!b.ajaxUrl){var a,e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies),f=e.length,g=b.page*b.size,i=g+b.size,h=0;for(a=0;a=g&&h'+(e?e.message+" ("+e.name+")":"No rows found")+"",k=a.ajaxProcessing(c)||[0,[]],v=k[1]||[],s=v.length,m=k[2];if(0";for(f=0;f"+v[c][f]+"";n+=""}m&&m.length===p&&(g=j.hasClass("hasStickyHeaders"),h=j.find("."+(l.widgetOptions&&l.widgetOptions.stickyHeaders||"tablesorter-stickyheader")),i=j.find("tfoot tr:first").children(),j.find("th."+l.cssHeader).each(function(a){var b=d(this),c;b.find("."+l.cssIcon).length?(c=b.find("."+l.cssIcon).clone(!0),b.find(".tablesorter-header-inner").html(m[a]).append(c),g&&h.length&&(c=h.find("th").eq(a).find("."+l.cssIcon).clone(!0),h.find("th").eq(a).find(".tablesorter-header-inner").html(m[a]).append(c))): (b.find(".tablesorter-header-inner").html(m[a]),h.find("th").eq(a).find(".tablesorter-header-inner").html(m[a]));i.eq(a).html(m[a]);g&&h.length&&(b=h.find("th").eq(a),b=b.find("span").length?b.find("span:first"):b,b.html(m[a]))}));e?j.find("thead").append(r):q.html(n);a.temp.remove();a.initialized&&j.trigger("update");a.totalRows=k[0]||0;a.totalPages=Math.ceil(a.totalRows/a.size);t(b,a);u(b,a);a.initialized&&j.trigger("pagerChange",a)}a.initialized||(a.initialized=!0,d(b).trigger("pagerInitialized", a))},y=function(c,b){var a=d(c),e=b.ajaxUrl.replace(/\{page\}/g,b.page).replace(/\{size\}/g,b.size);""!==e&&(b.temp=d("
",{"class":"tablesorter-processing",width:a.outerWidth(!0),height:a.outerHeight(!0)}),a.before(b.temp),d(document).ajaxError(function(a,d,e,h){x(null,c,b,h)}),d.getJSON(e,function(a){x(a,c,b)}))},k=function(c,b,a){var e,f,g,k=document.createDocumentFragment(),h=b.length;e=a.page*a.size;var j=e+a.size;if(!(1>h)){a.initialized&&d(c).trigger("pagerChange",a);if(a.removeRows){j> b.length&&(j=b.length);d(c.tBodies[0]).addClass("tablesorter-hidden");for(d.tablesorter.clearTableBody(c);e=a.totalPages&&(a.page=Math.min(a.totalPages,a.filteredPages)-1,i(c,a));t(c,a);a.isDisabled||u(c,a);d(c).trigger("applyWidgets")}},z=function(c,b){b.ajax?r(b,!0):(b.isDisabled=!0,d.data(c,"pagerLastPage",b.page),d.data(c,"pagerLastSize", b.size),b.page=0,b.size=b.totalRows,b.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),k(c,c.config.rowsCopy,b));d(b.cssPageSize,b.container).addClass(b.cssDisabled)[0].disabled=!0},i=function(c,b){if(!b.isDisabled){var a=Math.min(b.totalPages,b.filteredPages);if(0>b.page||b.page>a-1)b.page=0;d.data(c,"pagerLastPage",b.page);b.ajax?y(c,b):k(c,c.config.rowsCopy,b);b.initialized&&d(c).trigger("pageMoved",b)}},A=function(c,b,a){a.size=b;d.data(c,"pagerLastPage",a.page);d.data(c,"pagerLastSize", a.size);a.totalPages=Math.ceil(a.totalRows/a.size);i(c,a)},B=function(c,b,a){var e=d(b.cssPageSize,b.container).removeClass(b.cssDisabled).removeAttr("disabled");b.isDisabled=!1;b.page=d.data(c,"pagerLastPage")||b.page||0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10)||b.size;b.totalPages=Math.ceil(Math.min(b.totalPages,b.filteredPages)/b.size);a&&(d(c).trigger("update"),A(c,b.size,b),w(c,b),u(c,b))};p.appender=function(c,b){var a=c.config.pager;a.ajax||(c.config.rowsCopy=b,a.totalRows=b.length, a.size=d.data(c,"pagerLastSize")||a.size,a.totalPages=Math.ceil(a.totalRows/a.size),k(c,b,a))};p.construct=function(c){return this.each(function(){var b=this.config,a=b.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,f=d(e),g=d(a.container).addClass("tablesorter-pager").show();b.appender=p.appender;a.initialized=!1;B(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,y(e,a)):(a.ajax=!1,d(this).trigger("appendCache",!0),w(e,a));d(e).hasClass("hasFilters")&&d(e).unbind("filterEnd.pager").bind("filterEnd.pager", function(){a.page=0;t(e,a);i(e,a);s(e,a)});d(a.cssGoto,g).length&&(d(a.cssGoto,g).bind("change",function(){a.page=d(this).val()-1;i(e,a)}),t(e,a));d(a.cssFirst,g).unbind("click.pager").bind("click.pager",function(){d(this).hasClass(a.cssDisabled)||(a.page=0,i(e,a));return!1});d(a.cssNext,g).unbind("click.pager").bind("click.pager",function(){d(this).hasClass(a.cssDisabled)||(a.page++,a.page>=Math.min(a.totalPages,a.filteredPages)-1&&(a.page=Math.min(a.totalPages,a.filteredPages)-1),i(e,a));return!1}); d(a.cssPrev,g).unbind("click.pager").bind("click.pager",function(){d(this).hasClass(a.cssDisabled)||(a.page--,0>=a.page&&(a.page=0),i(e,a));return!1});d(a.cssLast,g).unbind("click.pager").bind("click.pager",function(){d(this).hasClass(a.cssDisabled)||(a.page=Math.min(a.totalPages,a.filteredPages)-1,i(e,a));return!1});d(a.cssPageSize,g).unbind("change.pager").bind("change.pager",function(){d(a.cssPageSize,g).val(d(this).val());d(this).hasClass(a.cssDisabled)||(A(e,parseInt(d(this).val(),10),a),s(e, a));return!1});f.unbind("disable.pager enable.pager destroy.pager update.pager").bind("disable.pager",function(){z(e,a)}).bind("enable.pager",function(){B(e,a,!0)}).bind("destroy.pager",function(){z(e,a);d(a.container).hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager")}).bind("update.pager",function(){q(e,a)});a.ajax||(a.initialized=!0,d(e).trigger("pagerInitialized",a))})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery); \ No newline at end of file diff --git a/docs/example-pager.html b/docs/example-pager.html index e64e5f6d..b862416d 100644 --- a/docs/example-pager.html +++ b/docs/example-pager.html @@ -1,706 +1,707 @@ - - - - - jQuery plugin: Tablesorter 2.0 - Pager plugin - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -

- NOTE! The following are not part of the original plugin: -

    -
  • This pager plugin can be applied to the original tablesorter, but there is one exception - setting the removeRows option to false will break the sort.
  • -
  • There have been lots of changes made in version 2.1, please check out the change log below.
  • -
-

- -

Triggered Events

-
    -
  • Pager events will appear here.
  • -
  •  
  • -
  •  
  • -
- -

Demo

-
- -

-
- First - Prev - - Next - Last - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
Student01Languagesmale80707580
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080
Student21Languagesmale5045100100
Student22Mathematicsmale1009910090
Student23Mathematicsmale8277079
Student24Languagesfemale100911382
Student25Mathematicsmale22968253
Student26Languagesfemale37295659
Student27Mathematicsmale86826923
Student28Languagesfemale4425431
Student29Mathematicsmale77472238
Student30Languagesfemale19352310
Student31Mathematicsmale90271750
Student32Languagesfemale60753338
Student33Mathematicsmale4313715
Student34Languagesfemale77978144
Student35Mathematicsmale5815195
Student36Languagesfemale70617094
Student37Mathematicsmale6036184
Student38Languagesfemale6339011
Student39Mathematicsmale50463238
Student40Languagesfemale5175253
Student41Mathematicsmale43342878
Student42Languagesfemale11896095
Student43Mathematicsmale48921888
Student44Languagesfemale8225973
Student45Mathematicsmale91733739
Student46Languagesfemale481210
Student47Mathematicsmale8910611
Student48Languagesfemale90322118
Student49Mathematicsmale42494972
Student50Languagesfemale56376754
- -
- First - Prev - - Next - Last - - -
- -

Javascript

-
-

-	
- -

CSS

-
-
/* pager wrapper, div */
-.tablesorter-pager {
-  padding: 5px;
-}
-/* pager wrapper, in thead/tfoot */
-td.tablesorter-pager {
-  background-color: #e6eeee;
-  margin: 0; /* needed for bootstrap .pager gets a 18px bottom margin */
-}
-/* pager navigation arrows */
-.tablesorter-pager img {
-  vertical-align: middle;
-  margin-right: 2px;
-  cursor: pointer;
-}
-
-/* pager output text */
-.tablesorter-pager .pagedisplay {
-  padding: 0 5px 0 5px;
-  width: 50px;
-  text-align: center;
-}
-
-/* pager element reset (needed for bootstrap) */
-.tablesorter-pager select {
-  margin: 0;
-  padding: 0;
-}
-
-/*** css used when "updateArrows" option is true ***/
-/* the pager itself gets a disabled class when the number of rows is less than the size */
-.tablesorter-pager.disabled {
-  display: none;
-}
-/* hide or fade out pager arrows when the first or last row is visible */
-.tablesorter-pager .disabled {
-  /* visibility: hidden */
-  opacity: 0.5;
-  filter: alpha(opacity=50);
-  cursor: default;
-}
-
- -

HTML

-
-
<table class="tablesorter">
-<!-- view page source to see the entire table -->
-</table>
-
-<!-- pager -->
-<div id="pager" class="pager">
-  <form>
-    <img src="first.png" class="first"/>
-    <img src="prev.png" class="prev"/>
-    <span class="pagedisplay"></span> <!-- this can be any element, including an input -->
-    <img src="next.png" class="next"/>
-    <img src="last.png" class="last"/>
-    <select class="pagesize">
-      <option selected="selected" value="10">10</option>
-      <option value="20">20</option>
-      <option value="30">30</option>
-      <option value="40">40</option>
-    </select>
-  </form>
-</div>
- -
- - -

Pager Change Log

- -
-

Changes

-
-
- -

Version 2.4 (8/19/2012)

-
-
    -
  • xxx.
  • -
-
- -

Version 2.2.1 (5/4/2012)

-
-
    -
  • Widgets should now apply properly while the pager is active. Fix for issue #60.
  • -
-
- -

Version 2.1.20 (4/28/2012)

-
-
    -
  • Optimized pager table rebuilding to also use document fragments, and by removing two extra calls that reapplied the current widgets.
  • -
-
- -

Version 2.1.6 (3/22/2012)

-
-
    -
  • Updated pager css. It wasn't targeting the pager block correctly.
  • -
  • Moved pager into the thead and/or tfoot in the pager ajax demo.
  • -
  • The pager plugin ajax method should now only target the header column text (not the pager) and first footer row when updating the header text.
  • -
-
- -

Version 2.1.3.1 (3/17/2012)

-
-
    -
  • Rozwell contributed some bug fixes that occur when cssPageSize is not set. Thanks for sharing!
  • -
-
- -

Version 2.1

-
-
    -
  • Ajax: -
      -
    • The pager plugin will now interact with a database via JSON. See demo here.
    • -
    • Added ajaxUrl option which contains the variables {page} and {size} which will be replaced by the plugin to obtain that data. -
      ajaxUrl : "http:/mydatabase.com?page={page}&size={size}"
      -
    • -
    • Another option named ajaxProcessing was included to process the data before returning it to the pager plugin. Basically the JSON needs to contain the data to match the example below. An additional required variable is the total number of records or rows needs to be returned. - -
      // process ajax so that the data object is returned along with the total number of rows
      -									// example: { "data" : [{ "ID": 1, "Name": "Foo", "Last": "Bar" }], "total_rows" : 100 }
      -									ajaxProcessing: function(ajax){
      -									if (ajax && ajax.hasOwnProperty('data')) {
      -									// return [ "data", "total_rows" ];
      -									return [ ajax.data, ajax.total_rows ];
      -									}
      -								}
      -
    • -
    • I tried to make the plugin interact with a database as flexible as possible, but I'm sure I haven't covered every situation. So any and all feedback is welcome!
    • -
    • Also, much thanks to kachar for the enhancement request and willingness to help test it!
    • -
    -
  • -
  • Removed positionFixed and offset options.
  • -
  • Added fixedHeight option which replaces the positionFixed and offset options. - -
      -
    • If true, it should maintain the height of the table, even when viewing fewer than the set number of records (go to the last page to see this in action).
    • -
    • It works by adding an empty row to make up the differences in height.
    • -
    • There were some issues of the height being incorrect when this option is true. The problems occurred if you add/remove rows + change pager size, or just destroy/enable the pager. I think I fixed it, but if you should find a problem, please report the issue and steps on how to duplicate it.
    • -
    -
  • - -
  • The pager container option will now accept class names. So you can add multiple container blocks to control the pager, just as this page now has two, one above and one below.
  • -
  • The pager now adds all of its options to the table configuration options within an object named "pager". Basically what this means is that instead of add all of the pager options to be mixed in with the tablesorter options, the pager options have been isolated and can be found by typing this into the browser console: $('table')[0].config.pager.
  • -
-
- -

Version 2.0.21.2

-
-
    -
  • Added "disable.pager" and "enable.pager" methods added to make it easier to add or delete rows from the table.
  • -
-
- -

Version 2.0.16

-
-
    -
  • Reduced the number of rows in the demo from 1022 to 50, so you don't have to scroll forever (when the pager is destroyed) to see the code below the table.
  • -
  • Added "destroy.pager" method will reveal the entire table, remove the pager functionality, and hide the actual pager.
  • -
  • Added a new addRows method to allow adding new rows while the pager is applied to a table. Using "update" would remove all non-visible rows.
  • -
-
- -

Version 2.0.9

-
-
    -
  • Added cssDisabled and pagerArrows options which controls the look of the pager and arrows when the pager is on the first or last page.
  • -
  • Updated pager functions, removed "separator" option, and added output string formatting (e.g. "1 to 10 (50)").
  • -
-
- -

Version 2.0.7

-
-
    -
  • Added "pagerChange" and "pagerComplete" events in version 2.0.7.
  • -
-
- -
-
-
- - - -
- - - - + + + + + jQuery plugin: Tablesorter 2.0 - Pager plugin + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ NOTE! The following are not part of the original plugin: +

    +
  • This pager plugin can be applied to the original tablesorter, but there is one exception - setting the removeRows option to false will break the sort.
  • +
  • There have been lots of changes made in version 2.1, please check out the change log below.
  • +
+

+ +

Triggered Events

+
    +
  • Pager events will appear here.
  • +
  •  
  • +
  •  
  • +
+ +

Demo

+
+ +

+
+ First + Prev + + Next + Last + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
Student01Languagesmale80707580
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080
Student21Languagesmale5045100100
Student22Mathematicsmale1009910090
Student23Mathematicsmale8277079
Student24Languagesfemale100911382
Student25Mathematicsmale22968253
Student26Languagesfemale37295659
Student27Mathematicsmale86826923
Student28Languagesfemale4425431
Student29Mathematicsmale77472238
Student30Languagesfemale19352310
Student31Mathematicsmale90271750
Student32Languagesfemale60753338
Student33Mathematicsmale4313715
Student34Languagesfemale77978144
Student35Mathematicsmale5815195
Student36Languagesfemale70617094
Student37Mathematicsmale6036184
Student38Languagesfemale6339011
Student39Mathematicsmale50463238
Student40Languagesfemale5175253
Student41Mathematicsmale43342878
Student42Languagesfemale11896095
Student43Mathematicsmale48921888
Student44Languagesfemale8225973
Student45Mathematicsmale91733739
Student46Languagesfemale481210
Student47Mathematicsmale8910611
Student48Languagesfemale90322118
Student49Mathematicsmale42494972
Student50Languagesfemale56376754
+ +
+ First + Prev + + Next + Last + + +
+ +

Javascript

+
+

+	
+ +

CSS

+
+
/* pager wrapper, div */
+.tablesorter-pager {
+  padding: 5px;
+}
+/* pager wrapper, in thead/tfoot */
+td.tablesorter-pager {
+  background-color: #e6eeee;
+  margin: 0; /* needed for bootstrap .pager gets a 18px bottom margin */
+}
+/* pager navigation arrows */
+.tablesorter-pager img {
+  vertical-align: middle;
+  margin-right: 2px;
+  cursor: pointer;
+}
+
+/* pager output text */
+.tablesorter-pager .pagedisplay {
+  padding: 0 5px 0 5px;
+  width: 50px;
+  text-align: center;
+}
+
+/* pager element reset (needed for bootstrap) */
+.tablesorter-pager select {
+  margin: 0;
+  padding: 0;
+}
+
+/*** css used when "updateArrows" option is true ***/
+/* the pager itself gets a disabled class when the number of rows is less than the size */
+.tablesorter-pager.disabled {
+  display: none;
+}
+/* hide or fade out pager arrows when the first or last row is visible */
+.tablesorter-pager .disabled {
+  /* visibility: hidden */
+  opacity: 0.5;
+  filter: alpha(opacity=50);
+  cursor: default;
+}
+
+ +

HTML

+
+
<table class="tablesorter">
+<!-- view page source to see the entire table -->
+</table>
+
+<!-- pager -->
+<div id="pager" class="pager">
+  <form>
+    <img src="first.png" class="first"/>
+    <img src="prev.png" class="prev"/>
+    <span class="pagedisplay"></span> <!-- this can be any element, including an input -->
+    <img src="next.png" class="next"/>
+    <img src="last.png" class="last"/>
+    <select class="pagesize">
+      <option selected="selected" value="10">10</option>
+      <option value="20">20</option>
+      <option value="30">30</option>
+      <option value="40">40</option>
+    </select>
+  </form>
+</div>
+ +
+ + +

Pager Change Log

+ +
+

Changes

+
+
+ +

Version 2.4 (8/19/2012)

+
+
    +
  • xxx.
  • +
+
+ +

Version 2.2.1 (5/4/2012)

+
+
    +
  • Widgets should now apply properly while the pager is active. Fix for issue #60.
  • +
+
+ +

Version 2.1.20 (4/28/2012)

+
+
    +
  • Optimized pager table rebuilding to also use document fragments, and by removing two extra calls that reapplied the current widgets.
  • +
+
+ +

Version 2.1.6 (3/22/2012)

+
+
    +
  • Updated pager css. It wasn't targeting the pager block correctly.
  • +
  • Moved pager into the thead and/or tfoot in the pager ajax demo.
  • +
  • The pager plugin ajax method should now only target the header column text (not the pager) and first footer row when updating the header text.
  • +
+
+ +

Version 2.1.3.1 (3/17/2012)

+
+
    +
  • Rozwell contributed some bug fixes that occur when cssPageSize is not set. Thanks for sharing!
  • +
+
+ +

Version 2.1

+
+
    +
  • Ajax: +
      +
    • The pager plugin will now interact with a database via JSON. See demo here.
    • +
    • Added ajaxUrl option which contains the variables {page} and {size} which will be replaced by the plugin to obtain that data. +
      ajaxUrl : "http:/mydatabase.com?page={page}&size={size}"
      +
    • +
    • Another option named ajaxProcessing was included to process the data before returning it to the pager plugin. Basically the JSON needs to contain the data to match the example below. An additional required variable is the total number of records or rows needs to be returned. + +
      // process ajax so that the data object is returned along with the total number of rows
      +									// example: { "data" : [{ "ID": 1, "Name": "Foo", "Last": "Bar" }], "total_rows" : 100 }
      +									ajaxProcessing: function(ajax){
      +									if (ajax && ajax.hasOwnProperty('data')) {
      +									// return [ "data", "total_rows" ];
      +									return [ ajax.data, ajax.total_rows ];
      +									}
      +								}
      +
    • +
    • I tried to make the plugin interact with a database as flexible as possible, but I'm sure I haven't covered every situation. So any and all feedback is welcome!
    • +
    • Also, much thanks to kachar for the enhancement request and willingness to help test it!
    • +
    +
  • +
  • Removed positionFixed and offset options.
  • +
  • Added fixedHeight option which replaces the positionFixed and offset options. + +
      +
    • If true, it should maintain the height of the table, even when viewing fewer than the set number of records (go to the last page to see this in action).
    • +
    • It works by adding an empty row to make up the differences in height.
    • +
    • There were some issues of the height being incorrect when this option is true. The problems occurred if you add/remove rows + change pager size, or just destroy/enable the pager. I think I fixed it, but if you should find a problem, please report the issue and steps on how to duplicate it.
    • +
    +
  • + +
  • The pager container option will now accept class names. So you can add multiple container blocks to control the pager, just as this page now has two, one above and one below.
  • +
  • The pager now adds all of its options to the table configuration options within an object named "pager". Basically what this means is that instead of add all of the pager options to be mixed in with the tablesorter options, the pager options have been isolated and can be found by typing this into the browser console: $('table')[0].config.pager.
  • +
+
+ +

Version 2.0.21.2

+
+
    +
  • Added "disable.pager" and "enable.pager" methods added to make it easier to add or delete rows from the table.
  • +
+
+ +

Version 2.0.16

+
+
    +
  • Reduced the number of rows in the demo from 1022 to 50, so you don't have to scroll forever (when the pager is destroyed) to see the code below the table.
  • +
  • Added "destroy.pager" method will reveal the entire table, remove the pager functionality, and hide the actual pager.
  • +
  • Added a new addRows method to allow adding new rows while the pager is applied to a table. Using "update" would remove all non-visible rows.
  • +
+
+ +

Version 2.0.9

+
+
    +
  • Added cssDisabled and pagerArrows options which controls the look of the pager and arrows when the pager is on the first or last page.
  • +
  • Updated pager functions, removed "separator" option, and added output string formatting (e.g. "1 to 10 (50)").
  • +
+
+ +

Version 2.0.7

+
+
    +
  • Added "pagerChange" and "pagerComplete" events in version 2.0.7.
  • +
+
+ +
+
+
+ + + +
+ + + + diff --git a/docs/index.html b/docs/index.html index 38fc4a7b..564aeeaf 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,2449 +1,2515 @@ - - - - -jQuery plugin: Tablesorter 2.0 - - - - - - - - - - - - - - - - - - -
-
-
-

- Author: Christian Bach
- Version: 2.1+ (forked from version 2.0.5, changelog)
- Licence: - Dual licensed under MIT - or GPL licenses. -

- - -

Contents

-
    -
  1. Introduction
  2. -
  3. Demo
  4. -
  5. Getting started
  6. -
  7. Examples
  8. -
  9. Configuration
  10. -
  11. Widget Options (v2.1)
  12. -
  13. Methods
  14. -
  15. Events
  16. -
  17. Download
  18. -
  19. Compatibility
  20. -
  21. Support
  22. -
  23. Credits
  24. -
- - -

Introduction

-

- tablesorter is a jQuery plugin for turning a - standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. - tablesorter can successfully parse and sort many types of data including linked data in a cell. - It has many useful features including: -

- -
    -
  • Multi-column sorting
  • -
  • Multi-tbody sorting - see the options table below
  • -
  • Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
  • -
  • Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)
  • -
  • Extensibility via widget system
  • -
  • Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+
  • -
  • Small code size
  • - -
- - -

Demo

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account #First NameLast NameAgeTotalDiscountDifferenceDate
A42bPeterParker28$9.9920.9%+12.1Jul 6, 2006 8:14 AM
A255JohnHood33$19.9925%+12Dec 10, 2002 5:14 AM
A33ClarkKent18$15.8944%-26Jan 12, 2003 11:14 AM
A1BruceAlmighty45$153.1944.7%+77Jan 18, 2001 9:12 AM
A102BruceEvans22$13.1911%-100.9Jan 18, 2007 9:12 AM
A42aBruceEvans22$13.1911%0Jan 18, 2007 9:12 AM
- -

- TIP! Sort multiple columns simultaneously by holding down the shift key and clicking a second, third or even fourth column header! -

- - - -

Getting started

-

- To use the tablesorter plugin, include the jQuery - library and the tablesorter plugin inside the <head> tag - of your HTML document: -

- -
<!-- choose a theme file -->
-<link rel="stylesheet" href="/path/to/theme.default.css">
-<!-- load jQuery and tablesorter scripts -->
-<script type="text/javascript" src="/path/to/jquery-latest.js"></script>
-<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script>
-
-<!-- tablesorter widgets (optional) -->
-<script type="text/javascript" src="/path/to/jquery.tablesorter.widgets.js"></script>
-
- -

tablesorter works on standard HTML tables. You must include THEAD and TBODY tags:

- -
<table id="myTable" class="tablesorter">
-  <thead>
-    <tr>
-      <th>Last Name</th>
-      <th>First Name</th>
-      <th>Email</th>
-      <th>Due</th>
-      <th>Web Site</th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td>Smith</td>
-      <td>John</td>
-      <td>jsmith@gmail.com</td>
-      <td>$50.00</td>
-      <td>http://www.jsmith.com</td>
-    </tr>
-    <tr>
-      <td>Bach</td>
-      <td>Frank</td>
-      <td>fbach@yahoo.com</td>
-      <td>$50.00</td>
-      <td>http://www.frank.com</td>
-    </tr>
-    <tr>
-      <td>Doe</td>
-      <td>Jason</td>
-      <td>jdoe@hotmail.com</td>
-      <td>$100.00</td>
-      <td>http://www.jdoe.com</td>
-    </tr>
-    <tr>
-      <td>Conway</td>
-      <td>Tim</td>
-      <td>tconway@earthlink.net</td>
-      <td>$50.00</td>
-      <td>http://www.timconway.com</td>
-    </tr>
-  </tbody>
-</table>
- -

Start by telling tablesorter to sort your table when the document is loaded:

- -
$(function(){
-  $("#myTable").tablesorter();
-});
- -

- Click on the headers and you'll see that your table is now sortable! You can - also pass in configuration options when you initialize the table. This tells - tablesorter to sort on the first and second column in ascending order. -

- -
$(function(){
-  $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] });
-});
- -

- NOTE! tablesorter will auto-detect most data types including numbers, dates, ip-adresses for more information see Examples -

- - -

Examples

-

- These examples will show what's possible with tablesorter. You need Javascript enabled to - run these samples, just like you and your users will need Javascript enabled to use tablesorter. -

- -
-

Basic

-

Sorting

- - -

Parsers / Extracting Content

- - -

Widgets / Plugins

- -
- -
-

Advanced

-

Adding / Removing Content

- - -

Change Header Style

- - -
- -

Other

-

Options & Events

- - -

Playgrounds & Other demos

- - -

Metadata - setting inline options

- -
-
- - -

Configuration

- -
-

- tablesorter has many options you can pass in at initialization to achieve different effects
- TIP! Click on the link in the property column to reveal full details (or toggle|show|hide all) or double click to update the browser location. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertyTypeDefaultDescriptionLink
PropertyTypeDefaultDescriptionLink
cancelSelectionBooleantrueIndicates if tablesorter should disable selection of text in the table header (TH). Makes header behave more like a button.
cssAscString"tablesorter-headerSortUp"The CSS style used to style the header when sorting ascending. Example from the blue skin: -
-
th.tablesorter-headerSortUp {
-  background-color: #8dbdd8;
-  background-image: url(black-asc.gif);
-}
-
cssChildRowString"tablesorter-childRow"Add this css class to a child row that should always be attached to its parent. Click on the "cssChildRow" link to toggle the view on the attached child row. Previous default was "expand-child", Changed! in v2.4.Ex:1 2
This is an entirely new row, but attached to the row above while sorting
- cssChildRow Example HTML: -
-<table width="100%" border="1">
-  <thead>
-    <tr>
-      <th>Item #</th>
-      <th>Name</th>
-      <th>Available</th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td>12345</td>
-      <td>Toy Car</td>
-      <td>5</td>
-    </tr>
-    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above row, and not sort separately -->
-      <td colspan="3">
-        It's a toy car!
-      </td>
-    </tr>
-    <tr>
-      <td>23456</td>
-      <td>Toy Plane</td>
-      <td>2</td>
-    </tr>
-    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above row, and not sort separately -->
-      <td colspan="3">
-        It's a toy plane!
-      </td>
-    </tr>
-    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above two rows, and not sort separately -->
-      <td colspan="3">
-        and it flies!
-      </td>
-    </tr>
-  </tbody>
-</table>
-					
-
cssDescString"tablesorter-headerSortDown"The CSS style used to style the header when sorting descending. Example from the blue skin: -
-
th.tablesorter-headerSortDown {
-  background-color: #8dbdd8;
-  background-image: url(black-desc.gif);
-}
-
cssHeaderString"tablesorter-header"The CSS style used to style the header in its unsorted state. Example from the blue skin: -
-
th.tablesorter-header {
-  background-color: #e6eeee;
-  background-image: url(black-bg.gif);
-  background-repeat: no-repeat;
-  background-position: center right;
-  border-collapse: collapse;
-  cursor: pointer;
-  font-size: 12px;
-  padding: 4px 20px 4px 4px;
-}
-
cssHeaderRowString"tablesorter-headerRow"The CSS style used to style the header row. New! v2.4. -
- Previously the row would get the same class as the header cells, this class was added to make it easier to determine what element was being targetted in the plugin. -
-
cssIconString"tablesorter-icon"The CSS style used to style the header cell icon. New! v2.4. -
- As of v2.4, an <i> element, with this class name, is automatically appended to the header cells. To prevent the plugin from adding an <i> element to the headers, set the cssicon option to an empty string. -
-
cssProcessingString"tablesorter-processing"This class name is added to the header cell that is currently being sorted or filted. To prevent this class name from being added, set the showProcessing option to false. New! v2.4.
cssInfoBlockString"tablesorter-infoOnly"All tbodies with this class name will not have its contents sorted. (v2.2). -
-
- With the addition of multiple tbody sorting in v2.2, you can now insert a non-sorting tbody within the table by adding this class to the tbody. -
<tbody class="tablesorter-infoOnly">
-  <tr>
-    <th>The contents of this tbody</th>
-  </tr>
-  <tr>
-    <td>will not be sorted</td>
-  </tr>
-</tbody>
- As an example, I've split up this options table into three (3) tbodies. The first contains the active options, the second is the info block with a row that only contains the text "Deprecated Options", and the last tbody contains the deprecated options. Sort the table to see how each tbody sorts separately. -
-

- NOTE! The pager plugin will only be applied to the first tbody, as always. I may work on modifying this behavior in the future, if I can figure out the best implementation. -

-
-
dateFormatString"mmddyyyy"Set the date format. Here are the available options. (Modified v2.0.23). -
-
    -
  • "mmddyyyy" (default)
  • -
  • "ddmmyyyy"
  • -
  • "yyyymmdd"
  • -
- In previous versions, this option was set as "us", "uk" or "dd/mm/yy". This option was modified to better fit needed date formats. It will only work with four digit years!
-
- The sorter should be set to "shortDate" and the date format can be set in the "dateFormat" option or set for a specific columns within the "headers" option. - See the demo page to see it working. -
$(function(){
-  $("table").tablesorter({
-
-    dateFormat : "mmddyyyy", // default date format
-
-    // or to change the format for specific columns,
-    // add the dateFormat to the headers option:
-    headers: {
-      0: { sorter: "shortDate" }, // "shortDate" with the default dateFormat above
-      1: { sorter: "shortDate", dateFormat: "ddmmyyyy" }, // day first format
-      2: { sorter: "shortDate", dateFormat: "yyyymmdd" }  // year first format
-    }
-
-  });
-});
- Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1): -
    -
  • jQuery data data-dateFormat="mmddyyyy".
  • -
  • metadata class="{ dateFormat: 'mmddyyyy'}". This requires the metadata plugin.
  • -
  • headers option headers : { 0 : { dateFormat : 'mmddyyyy' } }.
  • -
  • header class name class="dateFormat-mmddyyyy".
  • -
  • Overall dateFormat option.
  • -
-
-
Example
debugBooleanfalse - Boolean flag indicating if tablesorter should display debuging information useful for development. - Example
delayInitBooleanfalse - Setting this option to true will delay parsing of all table cell data until the user initializes a sort. This speeds up the initialization process of very large tables, but the data still needs to be parsed, so the delay is still present upon initial sort. - Example
emptyToString"bottom" - Boolean flag indicating how tablesorter should deal with empty table cells. (Modified v2.1.16). -
-
    -
  • bottom - sort empty table cells to the bottom.
  • -
  • top - sort empty table cells to the top.
  • -
  • none or zero - sort empty table cells as if the cell has the value equal to zero.
  • -
- Individual columns can be modified by adding the following (they all do the same thing), set in order of priority: -
    -
  • jQuery data data-empty="top".
  • -
  • metadata class="{ empty: 'top'}". This requires the metadata plugin.
  • -
  • headers option headers : { 0 : { empty : 'top' } }.
  • -
  • header class name class="empty-top".
  • -
  • Overall emptyTo option.
  • -
- emptyToBottom option was added in v2.1.11, then replaced by the emptyTo option in v2.1.16. -
-
Example
headerListArray[ ] (empty array)Internal list of each header element as selected using jQuery selectors in the selectorHeaders option. Not really useful for normal usage.
headersObjectnull - An object of instructions for per-column controls in the format: headers: { 0: { option: setting }, ... } -
-
- For example, to disable sorting on the first two columns of a table: headers: { 0: { sorter: false}, 1: {sorter: false} }.
-
- The plugin attempts to detect the type of data that is contained in a column, but if it can't figure it out then it defaults to alphanumeric. You can easily override this by setting the header argument (or column parser). - See the full list of default parsers here or write your own. -
$(function(){
-  $("table").tablesorter({
-    headers: {
-
-      // See example - Disable first column
-      0: { sorter: false },
-
-      // See example 2: Sort column numerically & treat any text as if its value is:
-      1: { sorter: "digit", empty:  "top" }, // zero; sort empty cells to the top
-      2: { sorter: "digit", string: "max" }, // maximum positive value
-      3: { sorter: "digit", string: "min" }, // maximum negative value
-
-      // Sort the fifth column by date & set the format
-      4: { sorter: "shortDate", dateFormat: "yyyymmdd" }, // year first format
-
-      // See example 3: lock the sort order
-      // this option will not work if added as metadata
-      5: { lockedOrder: "asc" },
-
-      // See Example 4: Initial sort order direction of seventh column
-      6: { sortInitialOrder: "desc" },
-
-      // Set filter widget options for this column
-      // See the "Applying the filter widget" demo
-      7: { filter: false },    // disable filter widget for this column
-      8: { filter: "parsed" }, // use parsed data for this column in the filter search
-      9: { filter: "noquicksearch" } // exclude this column from the advanced filter quick search
-
-    }
-  });
-});
-
- Ex:1 - 2 - 3 - 4 -
ignoreCaseBooleantrueWhen true, text sorting will ignore the character case. If false, upper case characters will sort before lower case. (v2.2).
initWidgetsBooleantrueApply widgets after table initializes (v2.3.5). -
- When true, all widgets set by the widgets option will apply after tablesorter has initialized, this is the normal behavior.
-
- If false, the each widget set by the widgets option will be initialized, meaning the "init" function is run, but the format function will not be run. This is useful when running the pager plugin after the table is set up. The pager plugin will initialize, then apply all set widgets.
-
- Why you ask? Well, lets say you have a table with 1000 rows that will have the pager plugin applied to it. Before this option, the table would finish its setup, all widgets would be applied to the 1000 rows, pager plugin initializes and reapplies the widgets on the say 20 rows showing; making the widget application to 100 rows unnecessary and a waste of time. So, when this option is false, widgets will only be applied to the table after the pager is set up. -
-
onRenderHeaderFunctionnull - This function is called when classes are added to the TH tags. You can use this to modify the HTML in each header tag for additional styling. -
-
- In versions 2.0.6+, all TH text is wrapped in a span by default. In the example below, the header cell (TH) span is given a class name (source). -
$(function(){
-  $("table").tablesorter({
-    onRenderHeader: function (){
-      $(this).find('div').addClass('roundedCorners');
-    }
-  });
-});
and you'll end up with this HTML (only the thead is shown)
<thead>
-  <tr>
-    <th class="header"><span class="roundedCorners">Column 1</span></th>
-    <th class="header"><span class="roundedCorners">Column 2</span></th>
-  </tr>
-</thead>
-
Example
parsersObject{ }Internal list of all of the parsers. Here is a complete list of default parsers: -
-
- - - - - - - - - - - - - -
sorter: falsedisable sort for this column.
sorter: "text"Sort alpha-numerically.
sorter: "digit"Sort numerically.
sorter: "currency"Sort by currency value (supports "£$€¤¥¢").
sorter: "ipAddress"Sort by IP Address.
sorter: "url"Sort by url.
sorter: "isoDate"Sort by ISO date (YYYY-MM-DD or YYYY/MM/DD).
sorter: "percent"Sort by percent.
sorter: "usLongDate"Sort by date (U.S. Standard, e.g. Jan 18, 2001 9:12 AM).
sorter: "shortDate"Sort by a shorten date (see dateFormat).
sorter: "time"Sort by time (23:59 or 12:59 pm).
sorter: "metadata"Sort by the sorter value in the metadata - requires the metadata plugin.

- Check out the headers option to see how to use these parsers in your table (example #1).
Or add a header class name using "sorter-" plus the parser name (example #2), this includes custom parsers (example #3). -
-
- Ex:1 - 2 - 3 -
selectorHeadersString"> thead th, > thead td"jQuery selectors used to find cells in the header. -
- You can change this, but the table will still need the required thead and tbody before this plugin will work properly. -
Added > to the selector in v2.3 to prevent targetting nested table headers. It was modified again in v2.4 to include td cells within the thead. Modified! v2.4. -
-
selectorRemoveString"tr.remove-me"This CSS class name can be applied to all rows that are to be removed prior to triggering a table update. (v2.1). -
-
- It was necessary to add this option because some widgets add table rows for styling (see the writing custom widgets demo) and if a table update is triggered ($('table').trigger('update');) those added rows will automatically become incorporated into the table. -
-
selectorSortString"th, td"jQuery selector of content within selectorHeaders that is clickable to trigger a sort. New! v2.4.Example
showProcessingBooleanfalseShow an indeterminate timer icon in the header when the table is sorted or filtered. Please note that due to javascript processing, the icon may not show as being animated. I'm looking into this further and would appreciate any feedback or suggestions with the coding. New! v2.4.Example
sortForceArraynullUse to add an additional forced sort that is prepended to sortList. -
-
- For example, sortForce: [[0,0]] will sort the first column in ascending order. After the forced sort, the user selected column(s), or during initialzation, the sorting order defined in the sortList will follow. And lastly, the sort defined in the sortAppend option will be applied. More explicitly:
-
- There are three options to determine the sort order and this is the order of priority: -
    -
  1. sortForce forces the user to have this/these column(s) sorted first (null by default).
  2. -
  3. SortList is the initial sort order of the columns.
  4. -
  5. SortAppend is the default sort that is added to the end of the users sort selection (null by default).
  6. -
- The value of these sort options is an array of arrays and can include one or more columns. The format is an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. -
$(function(){
-  $("table").tablesorter({
-    sortForce  : [[0,0]],        // Always sort first column first
-    sortList   : [[1,0], [2,0]], // initial sort columns (2nd and 3rd)
-    sortAppend : [[3,0]]         // Always add this sort on the end (4th column)
-  });
-});
-
Example
sortListArraynullUse to add an initial sort to the table. -
-
- The value contains an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. Please see sortForce for more details on other sort order options.
-
- This option can also be set using jQuery data (v2.3.1) or metadata on the table: - - - -
jQuery data<table data-sortlist="[[0,0],[4,0]]">
Meta data<table class="tablesorter {sortlist: [[0,0],[4,0]]}">
-
-
Example
sortAppendArraynullUse to add an additional forced sort that will be appended to the dynamic selections by the user. -
-
- For example, can be used to sort people alphabetically after some other user-selected sort that results in rows with the same value like dates or money due. It can help prevent data from appearing as though it has a random secondary sort.
-
- The value contains an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. Please see sortForce for more details on other sort order options. -
-
Example
sortInitialOrderString"asc" - The direction a column sorts when clicking the header for the first time. Valid arguments are "asc" for Ascending or "desc" for Descending.
-
-
- This order can also be set by desired column using the headers option (Added in v2.0.8).
-
- Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1): -
    -
  • jQuery data data-sortInitialOrder="asc".
  • -
  • metadata class="{ sortInitialOrder: 'asc'}". This requires the metadata plugin.
  • -
  • headers option headers : { 0 : { sortInitialOrder : 'asc' } }.
  • -
  • header class name class="sortInitialOrder-asc".
  • -
  • Overall sortInitialOrder option.
  • -
-
-
Ex:1 2
sortLocaleCompareBooleanfalse - Boolean flag indicating if certain accented characters within the table will be replaced with their equivalent characters. (Modified v2.2). -
-
    -
  • This option no longer switches the sort to use the String.localeCompare method.
  • -
  • When this option is true, the text parsed from table cells will convert accented characters to their equivalent to allow the alphanumeric sort to properly sort.
  • -
  • If false (default), any accented characters are treated as their value in the standard unicode order.
  • -
  • The following characters are replaced for both upper and lower case (information obtained from sugar.js sorting equivalents table): -
      -
    • áàâãä replaced with a
    • -
    • ç replaced with c
    • -
    • éèêë replaced with e
    • -
    • íìİîï replaced with i
    • -
    • óòôõö replaced with o
    • -
    • úùûü replaced with u
    • -
    • ß replaced with S
    • -
    -
  • -
  • Please see the example page for instrcutions on how to modify the above equivalency table.
  • -
  • If you would like to continuing using the String.localeCompare method, then set the sortLocaleCompare option to false and use the new textSorter option as follows: -
    $('table').tablesorter({
    -  textSorter: function(a,b) {
    -    return a.localeCompare(b);
    -  }
    -});
  • -
-

- NOTE: See the Language wiki page for language specific examples and how to extend the character equivalent tables seen in the sortLocaleCompare demo. -

- Boolean flag indicating whenever to use javascript String.localeCompare method or not.
- This is only used when comparing text with international character strings. A sort using localeCompare will sort accented characters the same as their unaccented counterparts.
-
-
Example
sortResetBooleanfalse - Setting this option to true will allow you to click on the table header a third time to reset the sort direction. (v2.0.27). - Example
sortRestartBooleanfalse - Setting this option to true will start the sort with the sortInitialOrder when clicking on a previously unsorted column. (v2.0.31). - Example
sortMultiSortKeyString"shiftKey"The key used to select more than one column for multi-column sorting. Defaults to the shift key. The other options are "ctrlKey" or "altKey". Reference: https://developer.mozilla.org/en/DOM/MouseEventExample
stringToString"max" - Boolean flag indicating how tablesorter should deal with text inside of numerically sorted columns. (v2.1.16). -

- String options was initially set in the header options only. Overall option added and values changed in version 2.1.16; setting the value to: -
    -
  • "max" will treat any text in that column as a value greater than the max (more positive) value. Renamed from "max+".
  • -
  • "min" will treat any text in that column as a value greater than the min (more negative) value. Renamed from "max-".
  • -
  • "top" will always sort the text to the top of the column.
  • -
  • "bottom" will always sort the text to the bottom of the column.
  • -
  • "none" or "zero" will treat the text as if it has a value of zero.
  • -
- Individual columns can be modified by adding the following (they all do the same thing), set in order of priority: -
    -
  • jQuery data data-string="top".
  • -
  • metadata class="{ string: 'top'}". This requires the metadata plugin.
  • -
  • headers option headers : { 0 : { string : 'top' } }.
  • -
  • header class name class="string-top".
  • -
  • Overall stringTo option.
  • -
-
-
Example
tableClassString"tablesorter"This class was required in the default markup in version 2.0.5. But in version 2.0.6, it was added as an option. -
-
Change this option if you are not using the default css, or if you are using a completely custom stylesheet. -
-
themeString"default"This option will add a theme css class name to the table "tablesorter-{theme}" for styling. New v2.4. -
-
When changing this theme option, make sure that the appropriate css theme file has also been loaded. Included theme files include: - see all themes
- - -
-
Example
textExtractionString Or Function"simple"Defines which method is used to extract data from a table cell for sorting. - The built-in option is "simple" which is the equivalent of doing this inside of the textExtraction function: $(node).text();. -
-
- You can customize the text extraction by writing your own text extraction function "myTextExtraction" which you define like: -
var myTextExtraction = function(node, table, cellIndex){
-  // extract data from markup and return it
-  // originally: return node.childNodes[0].childNodes[0].innerHTML;
-  return $(node).find('selector').text();
-}
-$(function(){
-  $("#myTable").tableSorter( { textExtraction: myTextExtraction } );
-});
- tablesorter will pass the current table cell object for you to parse and return. Thanks to Josh Nathanson for the examples. Updated to a jQuery example by Rob G (Mottie). -

Now if the text you are finding in the script above is say a number, then just include the headers sorter option to specify how to sort it. Also in this example, we will specify that the special textExtraction code is only needed for the second column ("1" because we are using a zero-based index). All other columns will ignore this textExtraction function.

-

Added table and cellIndex variables to the textExtraction function in version 2.1.2.

-
$(function(){
-  $("table").tablesorter({
-    textExtraction: {
-      1: function(node, table, cellIndex) {
-           return $(node).find("span:last").text();
-      }
-    },
-    headers: {
-      1: { sorter : "digit" }
-    }
-  });
-});
-
Example
textSorterFunctionnull - Replace the default sorting algorithm with a custom one using this option. -
-
- Include a script like naturalSort.js as follows: -
$(function(){
-  $("table").tablesorter({
-    textSorter : naturalSort
-  });
-});
- or use the localeCompare sort -
$(function(){
-  $("table").tablesorter({
-    textSorter: function(a,b) {
-      return a.localeCompare(b);
-    }
-  });
-});
There's no need to worry about reverse sorting, it's taken care of by the plugin. -
-
Example
usNumberFormatBooleantrue - Indicates how tablesorter should deal with a numerical format: (v2.1.3). -
- - - - - - - - - - - -
trueU.S.1,234,567.89
falseGerman:
French:
1.234.567,89
1 234 567,89
-
-
Example
widgetsArray[ ] (empty array) - Initialize widgets using this option ( e.g. widgets : ['zebra'], or custom widgets widgets: ['zebra', 'myCustomWidget'];, see this demo on how to write your own custom widget ). - Example
widthFixedBooleanfalse - Indicates if tablesorter should apply fixed percentage-based widths to the table columns. Modified! v2.4. -
- Prior to v2.4, this option set pixel widths to added colgroups to fix the column widths. This is useful for the Pager companion. -
- Requires the jQuery dimension plugin to work. This is now part of the jQuery core. -
-
Example
widgetOptionsObject{ } - In version 2.1, all widget options have been moved into this option. This is a move to store all widget specific options in one place so as not to polute the main table options. All current widgets have been modified to use this new option. (v2.1). -
-
- Previously documented widget options widgetZebra, widgetColumns and widgetUitheme will be retained for backwards compatibility.
-
- Use the widgetOptions option as follows, please note that each option is followed by a comma (except the last one): -
$(function(){
-  $("table").tablesorter({
-
-    // initialize a bunch of widgets
-    widgets: ["zebra", "uitheme", "columns", "filter", "resizable", "stickyHeaders"],
-
-    widgetOptions: {
-
-      // *** columns widget ***
-      // change the default column class names
-      columns : [ "primary", "secondary", "tertiary" ],
-      // include thead when adding class names
-      columns_thead : true,
-      // include tfoot when adding class names
-      columns_tfoot : true,
-
-      // *** filter widget ***
-      // Include child rows content in the search
-      filter_childRows     : false,
-      // show column filters
-      filter_columnFilters : true,
-      // css class applied to the filter row inputs/select
-      filter_cssFilter     : "tablesorter-filter",
-      // add custom filter functions using this option.
-      filter_functions     : null,
-      // if true, the filter row is hidden initially until hovered/focused.
-      filter_hideFilters   : false,
-      // if true, make all searches case-insensitive.
-      filter_ignoreCase    : true,
-      // jQuery selector string of an element used to reset the filters.
-      filter_reset         : null,
-      // typing delay in milliseconds before starting a search.
-      filter_searchDelay   : 300,
-      // if true, filter start from the beginning of the cell contents.
-      filter_startsWith    : false,
-      // filter all data using parsed content.
-      filter_useParsedData : false,
-
-      // *** stickyHeaders widget ***
-      // css class name applied to the sticky header
-      stickyHeaders : "tablesorter-stickyHeader",
-
-      // *** resizable widget ***
-      // if false, resized columns are not saved for next page reload
-      resizable : true,
-
-      // *** savesort widget ***
-      // if false, the sort will not be saved for next page reload
-      saveSort : true,
-
-      // *** uitheme widget ***
-      // include the name of the theme to use current options are
-      // "jui" (default) and "bootstrap"
-      uitheme : "jui",
-
-      // *** zebra widget ***
-      // class names to add, default is [ "even", "odd" ]
-      zebra : ["ui-widget-content even", "ui-state-default odd"]
-
-    }
-
-  });
-});
-
Example
Deprecated Options
widgetColumnsObject with Array{ css:[ "primary", "secondary", "tertiary" ] } - This option is being deprecated! - It has been replaced by widgetOptions.columns; but is still available for backwards compatibility. -
-
- When the column styling widget is initialized, it automatically applied the default class names of "primary" for the primary sort, "secondary" for the next sort, "tertiary" for the next sort, and so on (add more as needed)... (v2.0.17). - Use the widgetColumns option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["columns"], // initialize column styling of the table
-    widgetColumns: { css: ["primary", "secondary", "tertiary" ] }
-  });
-});
-
widgetUithemeObject with Array{ css: [ "ui-icon-arrowthick-2-n-s", "ui-icon-arrowthick-1-s", "ui-icon-arrowthick-1-n" ] } - This option is being deprecated! - It has been replaced by widgetOptions.uitheme; but is still available for backwards compatibility. -
-
- Used when the ui theme styling widget is initialized. It automatically applies the default class names of "ui-icon-arrowthick-2-n-s" for the unsorted column, "ui-icon-arrowthick-1-s" for the descending sort and "ui-icon-arrowthick-1-n" for the ascending sort. (v2.0.9). - Find more jQuery UI class names by hovering over the Framework icons on this page: http://jqueryui.com/themeroller/
-
- Use the widgetUitheme option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["uitheme"], // initialize ui theme styling widget of the table
-    widgetUitheme: {
-      css: [
-        "ui-icon-carat-2-n-s", // Unsorted icon
-        "ui-icon-carat-1-s",   // Sort up (down arrow)
-        "ui-icon-carat-1-n"    // Sort down (up arrow)
-      ]
-    }
-  });
-});
-
widgetZebraObject with Array{ css: [ "even", "odd" ] } - This option is being deprecated! - It has been replaced by widgetOptions.zebra; but is still available for backwards compatibility. -
-
- When the zebra striping widget is initialized, it automatically applied the default class names of "even" and "odd". - Use the widgetZebra option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["zebra"], // initialize zebra striping of the table
-    widgetZebra: { css: [ "normal-row", "alt-row" ] }
-  });
-});
-
- - -

Widget Options

- - - - - - - - - - - - - - - -
Applied OrderNameRequires jQueryLimiting function
6columnsv1.2.6
5filterv1.4.31.4.3 (nextUntil)
8pagerv1.2.6
4resizablev1.4.1*1.4 (isEmptyObject); 1.4.1 (parseJSON)*
3saveSortv1.4.11.4.1 (parseJSON)*
2stickyHeadersv1.2.6
1uithemev1.2.6
7zebrav1.2.6
- -
-

- tablesorter widgets have many options, and to better organize them, they now are grouped together inside of the widgetOptions. Thanks to thezoggy for putting together this jQuery-widget compatibility table, but please note: -
    -
  • The applied order will not change depending on the widgets applied, but the numbers will change.
  • -
  • The widgets are actually applied in reverse alphabetical order. This includes any custom widget names, so a custom widget named "zoom" will be the first applied widget. The only exception is the zebra widget which will always be the last widget applied.
  • -
  • The pager, being a plugin, is actually initialized after tablesorter has initialized and all selected widgets applied.
  • -
  • * The saveSort and resizable widgets use the $.tablesorter.storage function by default and thus need the ParseJSON function which is available in jQuery 1.4.1+.
  • -
- -
- TIP! Click on the link in the property column to reveal full details (or toggle|show|hide all) or double click to update the browser location. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertyTypeDefaultDescriptionLink
PropertyTypeDefaultDescriptionLink
columnsArray[ "primary", "secondary", "tertiary" ] - Columns widget: When the column styling widget is initialized, it automatically applied the default class names of "primary" for the primary sort, "secondary" for the next sort, "tertiary" for the next sort, and so on (add more as needed)... (Modified v2.1). -
-
- Use the "columns" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["columns"], // initialize column styling of the table
-    widgetOptions : {
-      columns: [ "primary", "secondary", "tertiary" ]
-    }
-  });
-});
-
Example
columns_theadArraytrue - Columns widget: If true, the class names from the columns option will also be added to the table thead. New! v2.4. -
-
- Use the "columns_thead" option to add the column class names to the thead as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["columns"], // initialize column styling of the table
-    widgetOptions : {
-      columns_thead: true
-    }
-  });
-});
-
Example
columns_tfootArraytrue - Columns widget: If true, the class names from the columns option will also be added to the table tfoot. New! v2.4. -
-
- Use the "columns_tfoot" option to add the column class names to the tfoot as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["columns"], // initialize column styling of the table
-    widgetOptions : {
-      columns_tfoot: true
-    }
-  });
-});
-
Example
filter_childRowsBooleanfalse - Filter widget: If there are child rows in the table (rows with class name from "cssChildRow" option) and this option is true and a match is found anywhere in the child row, then it will make that row visible. - (Modified v2.1). -
-
- Use the filter_childRows option include child row text as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_childRows : true
-    }
-  });
-});
-
filter_columnFiltersBooleantrue - Filter widget: If true, a filter will be added to the top of each table column. New! v2.4. -
-
- Use the filter_columnFilters option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_columnFilters : true
-    }
-  });
-});
-
filter_cssFilterString'tablesorter-filter' - Filter widget: This is the class name applied to each input within the filter row. If you change it from the default class name of "tablesorter-filter" make sure you also update the css! (v2.1). -
-
- Use the "tablesorter-filter" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      // css class applied to the table row containing the filters & the inputs within that row
-      filter_cssFilter : "tablesorter-filter"
-    }
-  });
-});
-
Example
filter_functionsObjectnull - Filter widget: Customize the filter widget by adding a select dropdown with content, custom options or custom filter functions (v2.3.6). -
- Use the "filter_functions" option in three different ways: -
-
    -
  • - Make a sorted select dropdown list of all column contents. Repeated content will be combined. -
    $(function(){
    -  $("table").tablesorter({
    -    widgets: ["filter"],
    -    widgetOptions: {
    -      filter_functions: {
    -        // Add select menu to this column
    -        // set the column value to true, and/or add "filter-select" class name to header
    -        0 : true
    -      }
    -    }
    -  });
    -});
    - Alternately, instead of setting the column filter funtion to true, give the column header a class name of "filter-select". See the demo.

    -
  • -
  • - Make a select dropdown list with custom option settings. Each option must have a corresponding function which returns a boolean value; return true if there is a match, or false with no match. - -

    Regex example

    -
    $(function(){
    -  $("table").tablesorter({
    -    widgets: ["filter"],
    -    widgetOptions: {
    -      // function variables:
    -      // e = exact text from cell
    -      // n = normalized value returned by the column parser
    -      // f = search filter input value
    -      // i = column index
    -      filter_functions: {
    -        // Add these options to the select dropdown (regex example)
    -        2 : {
    -          "A - D" : function(e, n, f, i) { return /^[A-D]/.test(e); },
    -          "E - H" : function(e, n, f, i) { return /^[E-H]/.test(e); },
    -          "I - L" : function(e, n, f, i) { return /^[I-L]/.test(e); },
    -          "M - P" : function(e, n, f, i) { return /^[M-P]/.test(e); },
    -          "Q - T" : function(e, n, f, i) { return /^[Q-T]/.test(e); },
    -          "U - X" : function(e, n, f, i) { return /^[U-X]/.test(e); },
    -          "Y - Z" : function(e, n, f, i) { return /^[Y-Z]/.test(e); }
    -        }
    -      }
    -    }
    -  });
    -});
    -

    Comparison example

    -
    $(function(){
    -  $("table").tablesorter({
    -    widgets: ["filter"],
    -    widgetOptions: {
    -      // function variables:
    -      // e = exact text from cell
    -      // n = normalized value returned by the column parser
    -      // f = search filter input value
    -      // i = column index
    -      filter_functions: {
    -        // Add these options to the select dropdown (numerical comparison example)
    -        // Note that only the normalized (n) value will contain numerical data
    -        // If you use the exact text, you'll need to parse it (parseFloat or parseInt)
    -        4 : {
    -          "< $10"      : function(e, n, f, i) { return n < 10; },
    -          "$10 - $100" : function(e, n, f, i) { return n >= 10 && n <=100; },
    -          "> $100"     : function(e, n, f, i) { return n > 100; }
    -        }
    -      }
    -    }
    -  });
    -});
    - Note: if the filter_ignoreCase option is true, it DOES alter the normalized value (n) by making it all lower case.

    -
  • -
  • - Make a custom filter for the column. -
    $(function(){
    -  $("table").tablesorter({
    -    widgets: ["filter"],
    -    widgetOptions: {
    -      // function variables:
    -      // e = exact text from cell
    -      // n = normalized value returned by the column parser
    -      // f = search filter input value
    -      // i = column index
    -      filter_functions: {
    -        // Exact match only
    -        1 : function(e, n, f, i) {
    -          return e === f;
    -        }
    -      }
    -    }
    -  });
    -});
    - Note: if the filter_ignoreCase option is true, it DOES alter the normalized value (n) by making it all lower case.

    -
  • -
-
-
Example
filter_hideFiltersBooleanfalse - Filter widget: Set this option to true to hide the filter row initially. The rows is revealed by hovering over the filter row or giving any filter input/select focus. New! v2.4. -
-
- Use the filter_hideFilters option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_hideFilters : true
-    }
-  });
-});
You can change the style (thickness) of the hidden filter row in the tablesorter theme css. Look for .tablesorter-filter-row (revealed row) and .tablesorter-filter-row.hideme (for the hidden row) css definitions.
-
Example
filter_ignoreCaseBooleantrue - Filter widget: Set this option to false to make the column content search case-insensitive, so typing in "a" will not find "Albert". (v2.3.4) -
-
- Use the filter_ignorecase option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_ignoreCase : false
-    }
-  });
-});
-
Example
filter_resetStringnull - Filter widget: jQuery selector string of an element used to reset the filters. New! v2.4. -
-

- To use this option, point to a reset button or link using a jQuery selector. For example, add this button (<button class="reset">Reset</button>) to the table header, or anywhere else on the page. That element will be used as a reset for all column and quick search filters (clears all fields): -

- Use the filter_reset option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_reset : '.reset'
-    }
-  });
-});
-
Example
filter_searchDelayNumeric300 - Filter widget: Set this option to the number of milliseconds to delay the search. (v2.3.4). -
-
- Use the filter_searchDelay option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_searchDelay : 500
-    }
-  });
-});
- - If you want to want to initialize the filter without user input, target any one of the filters and trigger a "search". - -
// target the first filter input
-// this method will begin the search after the searchDelay time
-$('input.tablesorter-filter:eq(0)').trigger('search');
-
-// this method will begin the search immediately
-$('input.tablesorter-filter:eq(0)').trigger('search', false);
- - In tablesorter v2.4+, the trigger can be applied directly to the table: -
// refresh the widget filter; no delay
-$('table').trigger('search', false);
-
filter_startsWithBooleanfalse - Filter widget: Set this option to true to use the filter to find text from the start of the column, so typing in "a" will find "albert" but not "frank", both have a's. (v2.1). -
-
- Use the filter_startsWith option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_startsWith : true
-    }
-  });
-});
-
Example
filter_useParsedDataBooleanfalse - Filter widget: If true, ALL filter searches will only use parsed data. New! v2.4. -
-
- Use the filter_useParsedData option as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["filter"],
-    widgetOptions : {
-      filter_useParsedData : false
-    }
-  });
-});
-
    -
  • To only use parsed data in specific columns, set this option to false and use any of the following (they all do the same thing), set in order of priority: -
      -
    • jQuery data data-filter="parsed".
    • -
    • metadata class="{ filter: 'parsed'}". This requires the metadata plugin.
    • -
    • headers option headers : { 0 : { filter : 'parsed' } }.
    • -
    • header class name class="filter-parsed".
    • -
    -
  • -
  • Remember that parsed data most likely doesn't match the actual table cell text, 20% becomes 20 and Jan 1, 2013 12:01 AM becomes 1357020060000.
  • -
-
-
stickyHeadersString"tablesorter-stickyHeader" - Sticky Headers widget: This is the class name applied to the sticky header row (tr). If you change it from the default class name of "tablesorter-stickyHeader" make sure you also update the css! (v2.1). -
-
- Use the "stickyHeaders" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["stickyHeaders"],
-    widgetOptions : {
-      // css class name applied to the sticky header
-      stickyHeaders : "tablesorter-stickyHeader"
-    }
-  });
-});
-
Example
resizableBooleantrue - Resizable widget: If this option is set to false, resized column widths will not be saved. Previous saved values will be restored on page reload. New! v2.4. -
-
- Use the "resizable" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["resizable"],
-    widgetOptions : {
-      // css class name applied to the sticky header
-      resizable : false
-    }
-  });
-});
-
Example
saveSortBooleantrue - saveSort widget: If this option is set to false, new sorts will not be saved. Any previous saved sort will be restored on page reload. New! v2.4. -
-
- Use the "saveSort" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["saveSort"],
-    widgetOptions : {
-      // if false, the sort will not be saved for next page reload
-      saveSort : false
-    }
-  });
-});
-
Example
uithemeString"jui" - ** Updated! in tablesorter v2.4 **
- - Instead of the array of icon class names, this option now contains the name of the theme. Currently jQuery UI ("jui") and Bootstrap ("bootstrap") themes are supported. To modify the class names used, extend from the theme -
-

-
// Extend the themes to change any of the default class names ** NEW **
-$.extend($.tablesorter.themes.jui, {
-  // change default jQuery uitheme icons - find the full list of icons
-  // here: http://jqueryui.com/themeroller/ (hover over them for their name)
-  table    : 'ui-widget ui-widget-content ui-corner-all', // table classes
-  header   : 'ui-widget-header ui-corner-all ui-state-default', // header classes
-  icons    : 'ui-icon', // icon class added to the <i> in the header
-  sortNone : 'ui-icon-carat-2-n-s',
-  sortAsc  : 'ui-icon-carat-1-n',
-  sortDesc : 'ui-icon-carat-1-s',
-  active   : 'ui-state-active', // applied when column is sorted
-  hover    : 'ui-state-hover',  // hover class
-  filterRow: '',
-  even     : 'ui-widget-content', // even row zebra striping
-  odd      : 'ui-state-default'   // odd row zebra striping
-});
- - This widget option replaces the previous widgetUitheme. All theme css names are now contained within the $.tablesorter.themes variable. Extend the default theme as seen above.
-
- - The class names from the $.tablesorter.themes.{name} variable are applied to the table as indicated.
-
- - As before the jQuery UI theme applies the default class names of "ui-icon-arrowthick-2-n-s" for the unsorted column, "ui-icon-arrowthick-1-s" for the descending sort and "ui-icon-arrowthick-1-n" for the ascending sort. (Modified v2.1; Updated in v2.4). Find more jQuery UI class names by hovering over the Framework icons on this page: http://jqueryui.com/themeroller/
-
- Use the "uitheme" option to change the css class name as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["uitheme"], // initialize ui theme styling widget of the table
-    widgetOptions: {
-      uitheme : "jui"
-    }
-  });
-});
- - To add a new theme, define it as follows; replace "custom" with the name of your theme: -
$.tablesorter.themes.custom = {
-  table    : 'table',       // table classes
-  header   : 'header',      // header classes
-  icons    : 'icon',        // icon class added to the <i> in the header
-  sortNone : 'sort-none',   // unsorted header
-  sortAsc  : 'sort-asc',    // ascending sorted header
-  sortDesc : 'sort-desc',   // descending sorted header
-  active   : 'sort-active', // applied when column is sorted
-  hover    : 'hover',       // hover class
-  filterRow: 'filters',     // class added to the filter row
-  even     : 'even',        // even row zebra striping
-  odd      : 'odd'          // odd row zebra striping
-}
-
Example
zebraArray[ "even", "odd" ] - zebra widget: When the zebra striping widget is initialized, it automatically applied the default class names of "even" and "odd". (Modified v2.1). -
-
- Use the "zebra" option to change the theme as follows: -
$(function(){
-  $("table").tablesorter({
-    widgets: ["zebra"], // initialize zebra striping of the table
-    widgetOptions: {
-      zebra: [ "normal-row", "alt-row" ]
-    }
-  });
-});
-
Example
- - -

Methods

- -
-

- tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized. -
- TIP! Click on the link in the method column to reveal full details (or toggle|show|hide all) or double click to update the browser location. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MethodDescriptionLink
addRowsUse this method to add table rows. (v2.0.16). -
- It does not work the same as "update" in that it only adds rows, it does not remove them.
- Also, use this method to add table rows while using the pager plugin. If the "update" method is used, only the visible table rows continue to exist. -
// Add multiple rows to the table
-  var row = '<tr><td>Inigo</td><td>Montoya</td><td>34</td>' +
-    '<td>$19.99</td><td>15%</td><td>Sep 25, 1987 12:00PM</td></tr>',
-    $row = $(row),
-    // resort table using the current sort; set to false to prevent resort, otherwise
-    // any other value in resort will automatically trigger the table resort.
-    // A callback method was added in 2.3.9.
-    resort = true,
-    callback = function(table){
-      alert('rows have been added!');
-    };
-  $('table')
-    .find('tbody').append($row)
-    .trigger('addRows', [$row, resort, callback]);
-
Example
sortonUse this method to sort an initialized table in the desired order. -
-
// Choose a new sort order
-var sort = [[0,0],[2,0]],
-    callback = function(table){
-        alert('new sort applied to ' + table.id);
-    };
-// Note that the sort value below is inside of another array (inside another set of square brackets)
-// A callback method was added in 2.3.9.
-$("table").trigger("sorton", [sort, callback]);
-
Example
updateUpdate the stored tablesorter data and the table. -
-
// Add new content
-$("table tbody").append(html);
-
-// let the plugin know that we made a update
-// the resort flag set to anything BUT false (no quotes) will trigger an automatic
-// table resort using the current sort
-// A callback method was added in 2.3.9.
-var resort = true,
-    callback = function(table){
-        alert('new sort applied');
-    };
-$("table").trigger("update", [resort, callback]);
-
-// As of version 2.0.14, the table will automatically resort (using the current sort selection)
-// after the update, so include the following if you want to specify a different sort
-
-// set sorting column and direction, this will sort on the first and third column
-var sorting = [[2,1],[0,0]];
-$("table").trigger("sorton", [sorting]);
-
Example
appendCacheUpdate a table that has had its data dynamically changed; used in conjunction with "update".
-
- Use this method when more than just one cell like in the "updateCell" method, but you may possibly have to trigger two events: both "update" and "appendCache".
-
- Note: This is the only method the pager widget uses - the entire table is stored in the cache, but only the visible portion is actually exists in the table. -
// Table data was just dynamically changed (more than one cell)
-$("table")
-  .trigger("update")
-  .trigger("appendCache");
-
updateCellUpdate a table cell in the tablesorter data. -
-
$(function() {
-  $("table").tablesorter();
-
-  $("td.discount").click(function(){
-
-    // randomize a number
-    var resort = false,
-        discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' +
-          ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
-    // add new table cell text
-    $(this).text(discount);
-
-    // update the table, so the tablesorter plugin can update its value
-    // set resort flag to false to prevent automatic resort (since we're using a different sort below)
-    // leave the resort flag as undefined, or with any other value, to automatically resort the table
-    // $("table").trigger("updateCell", [this]); < - resort is undefined so the table WILL resort
-    $("table").trigger("updateCell", [this, resort]);
-
-    // As of version 2.0.14, the table will automatically resort (using the current sort selection)
-    // after the update, so include the following if you want to specify a different sort
-
-    // set sorting column and direction, this will sort on the first and third column
-    var sorting = [[3,1]];
-    $("table").trigger("sorton", [sorting]);
-
-    return false;
-  });
-});
-
Example
applyWidgetIdApply the selected widget to the table, but the widget will not continue to be applied after each sort. See the example, it's easier than describing it. -
-
$(function(){
-  // initialize tablesorter without the widget
-  $("table").tablesorter();
-
-  // click a button to apply the zebra striping
-  $("button").click(function(){
-    $('table').trigger('applyWidgetId', ['zebra']);
-  });
-
-});
-
Example
applyWidgetsApply the set widgets to the table. This method can be used after a table has been initialized, but it won't work unless you update the configuration settings. See the example, it's easier than describing it. -
-
// Update the list of widgets to apply to the table (add or remove)
-// $("table").data("tablesorter").widgets = ["zebra"]; // works the same as
-$("table")[0].config.widgets = ["zebra"];
-
-// This method applies the widget - no need to keep updating
-$('table').trigger('applyWidgets');
-
-
Example
destroyUse this method to remove tablesorter from the table. -
-
// Remove tablesorter and all classes
-$("table").trigger("destroy");
-
-// Remove tablesorter and all classes but the "tablesorter" class on the table
-$("table").trigger("destroy", [false];
-
refreshWidgetsRefresh the currently applied widgets. Depending on the options, it will completely remove all widgets, then re-initialize the current widgets or just remove all non-current widgets. New v2.4. -

- Trigger this method using either of the following methods (they are equivalent): -
// trigger a refresh widget event
-$('table').trigger('refreshWidgets', [doAll, dontapply]);
-
-// Use the API directly
-$.tablesorter.refreshWidgets(table, doAll, dontapply)
-
    -
  • If doAll is true it removes all widgets from the table. If false only non-current widgets (from the widgets option) are removed.
  • -
  • When done removing widgets, the widget re-initializes the currently selected widgets, unless the dontapply parameter is true leaving the table widget-less.
  • -
  • Note that if the widgets option has any named widgets, they will be re-applied to the table when it gets resorted. So if you want to completely remove all widgets from the table, also clear out the widgets option $('table')[0].config.widgets = [];
  • -
-
-
Example
Widget Methods
- - -

Events

- -
-

- tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized. -
- TIP! Click on the link in the event column to reveal full details (or toggle|show|hide all) or double click to update the browser location. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventDescriptionLink
initializedThis event fires when tablesorter has completed initialization. (v2.2). -
-
$(function(){
-
-  // bind to initialized event BEFORE initializing tablesorter
-  $("table")
-    .bind("tablesorter-initialized",function(e, table) {
-      // do something after tablesorter has initialized
-    });
-
-  // initialize the tablesorter plugin
-  $("table").tablesorter({
-    // this is equivalent to the above bind method
-    initialized : function(table){
-      // do something after tablesorter has initialized
-    }
-  });
-
-});
-
sortBeginThis event fires immediately before tablesorter begins resorting the table. -
-
$(function(){
-
-  // initialize the tablesorter plugin
-  $("table").tablesorter();
-
-  // bind to sort events
-  $("table").bind("sortBegin",function(e, table) {
-    // do something crazy!
-  });
-});
-
sortStartThis event fires immediately after the tablesorter header has been clicked, initializing a resort. -
-
$(function(){
-
-  // initialize the tablesorter plugin
-  $("table").tablesorter();
-
-  // bind to sort events
-  $("table")
-    .bind("sortStart",function(e, table) {
-      $("#overlay").show();
-    })
-    .bind("sortEnd",function(e, table) {
-      $("#overlay").hide();
-    });
-});
-
Example
sortEndThis event fires when tablesorter has completed resorting the table. -
-
$(function(){
-
-  // initialize the tablesorter plugin
-  $("table").tablesorter();
-
-  // bind to sort events
-  $("table")
-    .bind("sortStart",function(e, table) {
-      $("#overlay").show();
-    })
-    .bind("sortEnd",function(e, table) {
-      $("#overlay").hide();
-    });
-});
-
Example
pagerChangeThis event fires when the pager plugin begins to render the table on the currently selected page. (v2.0.7). -
-
$(function(){
-
-  // initialize the sorter
-  $("table")
-    .tablesorter()
-
-    // initialize the pager plugin
-    .tablesorterPager({
-      container: $("#pager")
-    })
-
-    // bind to pager events
-    .bind('pagerChange pagerComplete', function(e,c){
-      // c.totalPages contains the total number of pages
-      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
-    });
-
-});
-
Example
pagerCompleteThis event fires when the pager plugin has completed its render of the table on the currently selected page. (v2.0.7). -
-
$(function(){
-
-  // initialize the sorter
-  $("table")
-    .tablesorter()
-
-    // initialize the pager plugin
-    .tablesorterPager({
-      container: $("#pager")
-    })
-
-    // bind to pager events
-    .bind('pagerChange pagerComplete', function(e,c){
-      // c.totalPages contains the total number of pages
-      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
-    });
-
-});
-
Example
Widget Events
filterInitEvent triggered when the filter widget has finished initializing. New v2.4. -
- You can use this event to modify the filter elements (row, inputs and/or selects) as desired. Use it as follows:
$(function(){
-  $('table').bind('filterInit', function(){
-    $(this).find('tr.tablesorter-filter-row').addClass('fred');
-  });
-});
-
Example
filterStartEvent triggered when the filter widget has started processing the search. New v2.4. -
- You can use this event to do something like add a class to the filter row. Use it as follows:
$(function(){
-  $('table').bind('filterStart', function(){
-    $(this).find('tr.tablesorter-filter-row').addClass('filtering');
-  });
-});
-
Example
filterEndEvent triggered when the filter widget has finished processing the search. New v2.4. -
- You can use this event to do something like remove the class added to the filter row when the filtering started. Use it as follows:
$(function(){
-  $('table').bind('filterEnd', function(){
-    $(this).find('tr.tablesorter-filter-row').removeClass('filtering');
-  });
-});
-
Example
- - -

Download

- -

Full release - Plugin, Documentation, Add-ons, Themes. Download: zip or tar.gz

- -

Pick n choose - Place at least the required files in a directory on your webserver that is accessible to a web browser. Record this location.

- - Required: - - - Optional / Add-Ons: - - - Themes: -

Theme zip files have been removed. There are now numerous themes available which can be seen here

- - -

Browser Compatibility

- -

tablesorter has been tested successfully in the following browsers with Javascript enabled:

-
    -
  • Firefox 2+
  • -
  • Internet Explorer 6+
  • -
  • Safari 2+
  • -
  • Opera 9+
  • -
  • Konqueror
  • -
- -

jQuery Browser Compatibility

- - -

Support

- -

If you are having a problem with the plugin or you want to submit a feature request, please submit an issue.

- -

If you would like to contribute, fork a copy on github.

- -

Support is also available through the jQuery Mailing List or StackOverflow.

- -

Access to the jQuery Mailing List is also available through Nabble Forums.

- - -

Credits

-

Written by Christian Bach.

-

- Documentation written by Brian Ghidinelli, - based on Mike Alsup's great documention.
- Additional & Missing documentation, alphanumeric sort, numerous widgets and other changes added by Mottie. -

-

- John Resig for the fantastic jQuery -

-
- - - + + + + +jQuery plugin: Tablesorter 2.0 + + + + + + + + + + + + + + + + + + +
+
+
+

+ Author: Christian Bach
+ Version: 2.1+ (forked from version 2.0.5, changelog)
+ Licence: + Dual licensed under MIT + or GPL licenses. +

+ + +

Contents

+
    +
  1. Introduction
  2. +
  3. Demo
  4. +
  5. Getting started
  6. +
  7. Examples
  8. +
  9. Configuration
  10. +
  11. Widget Options (v2.1)
  12. +
  13. Methods
  14. +
  15. Events
  16. +
  17. Download
  18. +
  19. Compatibility
  20. +
  21. Support
  22. +
  23. Credits
  24. +
+ + +

Introduction

+

+ tablesorter is a jQuery plugin for turning a + standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. + tablesorter can successfully parse and sort many types of data including linked data in a cell. + It has many useful features including: +

+ +
    +
  • Multi-column sorting
  • +
  • Multi-tbody sorting - see the options table below
  • +
  • Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
  • +
  • Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)
  • +
  • Extensibility via widget system
  • +
  • Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+
  • +
  • Small code size
  • +
+ + +

Demo

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Account #First NameLast NameAgeTotalDiscountDifferenceDate
A42bPeterParker28$9.9920.9%+12.1Jul 6, 2006 8:14 AM
A255JohnHood33$19.9925%+12Dec 10, 2002 5:14 AM
A33ClarkKent18$15.8944%-26Jan 12, 2003 11:14 AM
A1BruceAlmighty45$153.1944.7%+77Jan 18, 2001 9:12 AM
A102BruceEvans22$13.1911%-100.9Jan 18, 2007 9:12 AM
A42aBruceEvans22$13.1911%0Jan 18, 2007 9:12 AM
+ +

+ TIP! Sort multiple columns simultaneously by holding down the shift key and clicking a second, third or even fourth column header! +

+ + + +

Getting started

+

+ To use the tablesorter plugin, include the jQuery + library and the tablesorter plugin inside the <head> tag + of your HTML document: +

+ +
<!-- choose a theme file -->
+<link rel="stylesheet" href="/path/to/theme.default.css">
+<!-- load jQuery and tablesorter scripts -->
+<script type="text/javascript" src="/path/to/jquery-latest.js"></script>
+<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script>
+
+<!-- tablesorter widgets (optional) -->
+<script type="text/javascript" src="/path/to/jquery.tablesorter.widgets.js"></script>
+
+ +

tablesorter works on standard HTML tables. You must include THEAD and TBODY tags:

+ +
<table id="myTable" class="tablesorter">
+  <thead>
+    <tr>
+      <th>Last Name</th>
+      <th>First Name</th>
+      <th>Email</th>
+      <th>Due</th>
+      <th>Web Site</th>
+    </tr>
+  </thead>
+  <tbody>
+    <tr>
+      <td>Smith</td>
+      <td>John</td>
+      <td>jsmith@gmail.com</td>
+      <td>$50.00</td>
+      <td>http://www.jsmith.com</td>
+    </tr>
+    <tr>
+      <td>Bach</td>
+      <td>Frank</td>
+      <td>fbach@yahoo.com</td>
+      <td>$50.00</td>
+      <td>http://www.frank.com</td>
+    </tr>
+    <tr>
+      <td>Doe</td>
+      <td>Jason</td>
+      <td>jdoe@hotmail.com</td>
+      <td>$100.00</td>
+      <td>http://www.jdoe.com</td>
+    </tr>
+    <tr>
+      <td>Conway</td>
+      <td>Tim</td>
+      <td>tconway@earthlink.net</td>
+      <td>$50.00</td>
+      <td>http://www.timconway.com</td>
+    </tr>
+  </tbody>
+</table>
+ +

Start by telling tablesorter to sort your table when the document is loaded:

+ +
$(function(){
+  $("#myTable").tablesorter();
+});
+ +

+ Click on the headers and you'll see that your table is now sortable! You can + also pass in configuration options when you initialize the table. This tells + tablesorter to sort on the first and second column in ascending order. +

+ +
$(function(){
+  $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] });
+});
+ +

+ NOTE! tablesorter will auto-detect most data types including numbers, dates, ip-adresses for more information see Examples +

+ + +

Examples

+

+ These examples will show what's possible with tablesorter. You need Javascript enabled to + run these samples, just like you and your users will need Javascript enabled to use tablesorter. +

+ +
+

Basic

+

Sorting

+ + +

Parsers / Extracting Content

+ + +

Widgets / Plugins

+ +
+ +
+

Advanced

+

Adding / Removing Content

+ + +

Change Header Style

+ + +
+ +

Other

+

Options & Events

+ + +

Playgrounds & Other demos

+ + +

Metadata - setting inline options

+ +
+
+ + +

Configuration

+ +
+

+ tablesorter has many options you can pass in at initialization to achieve different effects
+ TIP! Click on the link in the property column to reveal full details (or toggle|show|hide all) or double click to update the browser location. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyTypeDefaultDescriptionLink
PropertyTypeDefaultDescriptionLink
cancelSelectionBooleantrueIndicates if tablesorter should disable selection of text in the table header (TH). Makes header behave more like a button.
cssAscString"tablesorter-headerSortUp"The CSS style used to style the header when sorting ascending. Example from the blue skin: +
+
th.tablesorter-headerSortUp {
+  background-color: #8dbdd8;
+  background-image: url(black-asc.gif);
+}
+
cssChildRowString"tablesorter-childRow"Add this css class to a child row that should always be attached to its parent. Click on the "cssChildRow" link to toggle the view on the attached child row. Previous default was "expand-child", Changed! in v2.4.Ex:1 2
This is an entirely new row, but attached to the row above while sorting
+ cssChildRow Example HTML: +
+<table width="100%" border="1">
+  <thead>
+    <tr>
+      <th>Item #</th>
+      <th>Name</th>
+      <th>Available</th>
+    </tr>
+  </thead>
+  <tbody>
+    <tr>
+      <td>12345</td>
+      <td>Toy Car</td>
+      <td>5</td>
+    </tr>
+    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above row, and not sort separately -->
+      <td colspan="3">
+        It's a toy car!
+      </td>
+    </tr>
+    <tr>
+      <td>23456</td>
+      <td>Toy Plane</td>
+      <td>2</td>
+    </tr>
+    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above row, and not sort separately -->
+      <td colspan="3">
+        It's a toy plane!
+      </td>
+    </tr>
+    <tr class="tablesorter-childRow"> <!-- this row will remain attached to the above two rows, and not sort separately -->
+      <td colspan="3">
+        and it flies!
+      </td>
+    </tr>
+  </tbody>
+</table>
+					
+
cssDescString"tablesorter-headerSortDown"The CSS style used to style the header when sorting descending. Example from the blue skin: +
+
th.tablesorter-headerSortDown {
+  background-color: #8dbdd8;
+  background-image: url(black-desc.gif);
+}
+
cssHeaderString"tablesorter-header"The CSS style used to style the header in its unsorted state. Example from the blue skin: +
+
th.tablesorter-header {
+  background-color: #e6eeee;
+  background-image: url(black-bg.gif);
+  background-repeat: no-repeat;
+  background-position: center right;
+  border-collapse: collapse;
+  cursor: pointer;
+  font-size: 12px;
+  padding: 4px 20px 4px 4px;
+}
+
cssHeaderRowString"tablesorter-headerRow"The CSS style used to style the header row. New! v2.4. +
+ Previously the row would get the same class as the header cells, this class was added to make it easier to determine what element was being targetted in the plugin. +
+
cssIconString"tablesorter-icon"The CSS style used to style the header cell icon. New! v2.4. +
+ As of v2.4, an <i> element, with this class name, is automatically appended to the header cells. To prevent the plugin from adding an <i> element to the headers, set the cssicon option to an empty string. +
+
cssProcessingString"tablesorter-processing"This class name is added to the header cell that is currently being sorted or filted. To prevent this class name from being added, set the showProcessing option to false. New! v2.4.
cssInfoBlockString"tablesorter-infoOnly"All tbodies with this class name will not have its contents sorted. (v2.2). +
+
+ With the addition of multiple tbody sorting in v2.2, you can now insert a non-sorting tbody within the table by adding this class to the tbody. +
<tbody class="tablesorter-infoOnly">
+  <tr>
+    <th>The contents of this tbody</th>
+  </tr>
+  <tr>
+    <td>will not be sorted</td>
+  </tr>
+</tbody>
+ As an example, I've split up this options table into three (3) tbodies. The first contains the active options, the second is the info block with a row that only contains the text "Deprecated Options", and the last tbody contains the deprecated options. Sort the table to see how each tbody sorts separately. +
+

+ NOTE! The pager plugin will only be applied to the first tbody, as always. I may work on modifying this behavior in the future, if I can figure out the best implementation. +

+
+
dateFormatString"mmddyyyy"Set the date format. Here are the available options. (Modified v2.0.23). +
+
    +
  • "mmddyyyy" (default)
  • +
  • "ddmmyyyy"
  • +
  • "yyyymmdd"
  • +
+ In previous versions, this option was set as "us", "uk" or "dd/mm/yy". This option was modified to better fit needed date formats. It will only work with four digit years!
+
+ The sorter should be set to "shortDate" and the date format can be set in the "dateFormat" option or set for a specific columns within the "headers" option. + See the demo page to see it working. +
$(function(){
+  $("table").tablesorter({
+
+    dateFormat : "mmddyyyy", // default date format
+
+    // or to change the format for specific columns,
+    // add the dateFormat to the headers option:
+    headers: {
+      0: { sorter: "shortDate" }, // "shortDate" with the default dateFormat above
+      1: { sorter: "shortDate", dateFormat: "ddmmyyyy" }, // day first format
+      2: { sorter: "shortDate", dateFormat: "yyyymmdd" }  // year first format
+    }
+
+  });
+});
+ Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1): +
    +
  • jQuery data data-dateFormat="mmddyyyy".
  • +
  • metadata class="{ dateFormat: 'mmddyyyy'}". This requires the metadata plugin.
  • +
  • headers option headers : { 0 : { dateFormat : 'mmddyyyy' } }.
  • +
  • header class name class="dateFormat-mmddyyyy".
  • +
  • Overall dateFormat option.
  • +
+
+
Example
debugBooleanfalse + Boolean flag indicating if tablesorter should display debuging information useful for development. + Example
delayInitBooleanfalse + Setting this option to true will delay parsing of all table cell data until the user initializes a sort. This speeds up the initialization process of very large tables, but the data still needs to be parsed, so the delay is still present upon initial sort. + Example
emptyToString"bottom" + Boolean flag indicating how tablesorter should deal with empty table cells. (Modified v2.1.16). +
+
    +
  • bottom - sort empty table cells to the bottom.
  • +
  • top - sort empty table cells to the top.
  • +
  • none or zero - sort empty table cells as if the cell has the value equal to zero.
  • +
+ Individual columns can be modified by adding the following (they all do the same thing), set in order of priority: +
    +
  • jQuery data data-empty="top".
  • +
  • metadata class="{ empty: 'top'}". This requires the metadata plugin.
  • +
  • headers option headers : { 0 : { empty : 'top' } }.
  • +
  • header class name class="empty-top".
  • +
  • Overall emptyTo option.
  • +
+ emptyToBottom option was added in v2.1.11, then replaced by the emptyTo option in v2.1.16. +
+
Example
headerListArray[ ] (empty array)Internal list of each header element as selected using jQuery selectors in the selectorHeaders option. Not really useful for normal usage.
headersObjectnull + An object of instructions for per-column controls in the format: headers: { 0: { option: setting }, ... } +
+
+ For example, to disable sorting on the first two columns of a table: headers: { 0: { sorter: false}, 1: {sorter: false} }.
+
+ The plugin attempts to detect the type of data that is contained in a column, but if it can't figure it out then it defaults to alphanumeric. You can easily override this by setting the header argument (or column parser). + See the full list of default parsers here or write your own. +
$(function(){
+  $("table").tablesorter({
+    headers: {
+
+      // See example - Disable first column
+      0: { sorter: false },
+
+      // See example 2: Sort column numerically & treat any text as if its value is:
+      1: { sorter: "digit", empty:  "top" }, // zero; sort empty cells to the top
+      2: { sorter: "digit", string: "max" }, // maximum positive value
+      3: { sorter: "digit", string: "min" }, // maximum negative value
+
+      // Sort the fifth column by date & set the format
+      4: { sorter: "shortDate", dateFormat: "yyyymmdd" }, // year first format
+
+      // See example 3: lock the sort order
+      // this option will not work if added as metadata
+      5: { lockedOrder: "asc" },
+
+      // See Example 4: Initial sort order direction of seventh column
+      6: { sortInitialOrder: "desc" },
+
+      // Set filter widget options for this column
+      // See the "Applying the filter widget" demo
+      7: { filter: false },    // disable filter widget for this column
+      8: { filter: "parsed" }, // use parsed data for this column in the filter search
+      9: { filter: "noquicksearch" } // exclude this column from the advanced filter quick search
+
+    }
+  });
+});
+
+ Ex:1 + 2 + 3 + 4 +
ignoreCaseBooleantrueWhen true, text sorting will ignore the character case. If false, upper case characters will sort before lower case. (v2.2).
initWidgetsBooleantrueApply widgets after table initializes (v2.3.5). +
+ When true, all widgets set by the widgets option will apply after tablesorter has initialized, this is the normal behavior.
+
+ If false, the each widget set by the widgets option will be initialized, meaning the "init" function is run, but the format function will not be run. This is useful when running the pager plugin after the table is set up. The pager plugin will initialize, then apply all set widgets.
+
+ Why you ask? Well, lets say you have a table with 1000 rows that will have the pager plugin applied to it. Before this option, the table would finish its setup, all widgets would be applied to the 1000 rows, pager plugin initializes and reapplies the widgets on the say 20 rows showing; making the widget application to 100 rows unnecessary and a waste of time. So, when this option is false, widgets will only be applied to the table after the pager is set up. +
+
onRenderHeaderFunctionnull + This function is called when classes are added to the TH tags. You can use this to modify the HTML in each header tag for additional styling. +
+
+ In versions 2.0.6+, all TH text is wrapped in a span by default. In the example below, the header cell (TH) span is given a class name (source). +
$(function(){
+  $("table").tablesorter({
+    onRenderHeader: function (){
+      $(this).find('div').addClass('roundedCorners');
+    }
+  });
+});
and you'll end up with this HTML (only the thead is shown)
<thead>
+  <tr>
+    <th class="header"><span class="roundedCorners">Column 1</span></th>
+    <th class="header"><span class="roundedCorners">Column 2</span></th>
+  </tr>
+</thead>
+
Example
parsersObject{ }Internal list of all of the parsers. Here is a complete list of default parsers: +
+
+ + + + + + + + + + + + + +
sorter: falsedisable sort for this column.
sorter: "text"Sort alpha-numerically.
sorter: "digit"Sort numerically.
sorter: "currency"Sort by currency value (supports "£$€¤¥¢").
sorter: "ipAddress"Sort by IP Address.
sorter: "url"Sort by url.
sorter: "isoDate"Sort by ISO date (YYYY-MM-DD or YYYY/MM/DD).
sorter: "percent"Sort by percent.
sorter: "usLongDate"Sort by date (U.S. Standard, e.g. Jan 18, 2001 9:12 AM).
sorter: "shortDate"Sort by a shorten date (see dateFormat).
sorter: "time"Sort by time (23:59 or 12:59 pm).
sorter: "metadata"Sort by the sorter value in the metadata - requires the metadata plugin.

+ Check out the headers option to see how to use these parsers in your table (example #1).
Or add a header class name using "sorter-" plus the parser name (example #2), this includes custom parsers (example #3). +
+
+ Ex:1 + 2 + 3 +
selectorHeadersString"> thead th, > thead td"jQuery selectors used to find cells in the header. +
+ You can change this, but the table will still need the required thead and tbody before this plugin will work properly. +
Added > to the selector in v2.3 to prevent targetting nested table headers. It was modified again in v2.4 to include td cells within the thead. Modified! v2.4. +
+
selectorRemoveString"tr.remove-me"This CSS class name can be applied to all rows that are to be removed prior to triggering a table update. (v2.1). +
+
+ It was necessary to add this option because some widgets add table rows for styling (see the writing custom widgets demo) and if a table update is triggered ($('table').trigger('update');) those added rows will automatically become incorporated into the table. +
+
selectorSortString"th, td"jQuery selector of content within selectorHeaders that is clickable to trigger a sort. New! v2.4.Example
showProcessingBooleanfalseShow an indeterminate timer icon in the header when the table is sorted or filtered. Please note that due to javascript processing, the icon may not show as being animated. I'm looking into this further and would appreciate any feedback or suggestions with the coding. New! v2.4.Example
sortForceArraynullUse to add an additional forced sort that is prepended to sortList. +
+
+ For example, sortForce: [[0,0]] will sort the first column in ascending order. After the forced sort, the user selected column(s), or during initialzation, the sorting order defined in the sortList will follow. And lastly, the sort defined in the sortAppend option will be applied. More explicitly:
+
+ There are three options to determine the sort order and this is the order of priority: +
    +
  1. sortForce forces the user to have this/these column(s) sorted first (null by default).
  2. +
  3. SortList is the initial sort order of the columns.
  4. +
  5. SortAppend is the default sort that is added to the end of the users sort selection (null by default).
  6. +
+ The value of these sort options is an array of arrays and can include one or more columns. The format is an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. +
$(function(){
+  $("table").tablesorter({
+    sortForce  : [[0,0]],        // Always sort first column first
+    sortList   : [[1,0], [2,0]], // initial sort columns (2nd and 3rd)
+    sortAppend : [[3,0]]         // Always add this sort on the end (4th column)
+  });
+});
+
Example
sortListArraynullUse to add an initial sort to the table. +
+
+ The value contains an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. Please see sortForce for more details on other sort order options.
+
+ This option can also be set using jQuery data (v2.3.1) or metadata on the table: + + + +
jQuery data<table data-sortlist="[[0,0],[4,0]]">
Meta data<table class="tablesorter {sortlist: [[0,0],[4,0]]}">
+
+
Example
sortAppendArraynullUse to add an additional forced sort that will be appended to the dynamic selections by the user. +
+
+ For example, can be used to sort people alphabetically after some other user-selected sort that results in rows with the same value like dates or money due. It can help prevent data from appearing as though it has a random secondary sort.
+
+ The value contains an array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]. Please see sortForce for more details on other sort order options. +
+
Example
sortInitialOrderString"asc" + The direction a column sorts when clicking the header for the first time. Valid arguments are "asc" for Ascending or "desc" for Descending.
+
+
+ This order can also be set by desired column using the headers option (Added in v2.0.8).
+
+ Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1): +
    +
  • jQuery data data-sortInitialOrder="asc".
  • +
  • metadata class="{ sortInitialOrder: 'asc'}". This requires the metadata plugin.
  • +
  • headers option headers : { 0 : { sortInitialOrder : 'asc' } }.
  • +
  • header class name class="sortInitialOrder-asc".
  • +
  • Overall sortInitialOrder option.
  • +
+
+
Ex:1 2
sortLocaleCompareBooleanfalse + Boolean flag indicating if certain accented characters within the table will be replaced with their equivalent characters. (Modified v2.2). +
+
    +
  • This option no longer switches the sort to use the String.localeCompare method.
  • +
  • When this option is true, the text parsed from table cells will convert accented characters to their equivalent to allow the alphanumeric sort to properly sort.
  • +
  • If false (default), any accented characters are treated as their value in the standard unicode order.
  • +
  • The following characters are replaced for both upper and lower case (information obtained from sugar.js sorting equivalents table): +
      +
    • áàâãä replaced with a
    • +
    • ç replaced with c
    • +
    • éèêë replaced with e
    • +
    • íìİîï replaced with i
    • +
    • óòôõö replaced with o
    • +
    • úùûü replaced with u
    • +
    • ß replaced with S
    • +
    +
  • +
  • Please see the example page for instrcutions on how to modify the above equivalency table.
  • +
  • If you would like to continuing using the String.localeCompare method, then set the sortLocaleCompare option to false and use the new textSorter option as follows: +
    $('table').tablesorter({
    +  textSorter: function(a,b) {
    +    return a.localeCompare(b);
    +  }
    +});
  • +
+

+ NOTE: See the Language wiki page for language specific examples and how to extend the character equivalent tables seen in the sortLocaleCompare demo. +

+ Boolean flag indicating whenever to use javascript String.localeCompare method or not.
+ This is only used when comparing text with international character strings. A sort using localeCompare will sort accented characters the same as their unaccented counterparts.
+
+
Example
sortResetBooleanfalse + Setting this option to true will allow you to click on the table header a third time to reset the sort direction. (v2.0.27). + Example
sortRestartBooleanfalse + Setting this option to true will start the sort with the sortInitialOrder when clicking on a previously unsorted column. (v2.0.31). + Example
sortMultiSortKeyString"shiftKey"The key used to select more than one column for multi-column sorting. Defaults to the shift key. The other options are "ctrlKey" or "altKey". Reference: https://developer.mozilla.org/en/DOM/MouseEventExample
stringToString"max" + Boolean flag indicating how tablesorter should deal with text inside of numerically sorted columns. (v2.1.16). +

+ String options was initially set in the header options only. Overall option added and values changed in version 2.1.16; setting the value to: +
    +
  • "max" will treat any text in that column as a value greater than the max (more positive) value. Renamed from "max+".
  • +
  • "min" will treat any text in that column as a value greater than the min (more negative) value. Renamed from "max-".
  • +
  • "top" will always sort the text to the top of the column.
  • +
  • "bottom" will always sort the text to the bottom of the column.
  • +
  • "none" or "zero" will treat the text as if it has a value of zero.
  • +
+ Individual columns can be modified by adding the following (they all do the same thing), set in order of priority: +
    +
  • jQuery data data-string="top".
  • +
  • metadata class="{ string: 'top'}". This requires the metadata plugin.
  • +
  • headers option headers : { 0 : { string : 'top' } }.
  • +
  • header class name class="string-top".
  • +
  • Overall stringTo option.
  • +
+
+
Example
tableClassString"tablesorter"This class was required in the default markup in version 2.0.5. But in version 2.0.6, it was added as an option. +
+
Change this option if you are not using the default css, or if you are using a completely custom stylesheet. +
+
themeString"default"This option will add a theme css class name to the table "tablesorter-{theme}" for styling. New v2.4. +
+
When changing this theme option, make sure that the appropriate css theme file has also been loaded. Included theme files include: + see all themes
+ + +
+
Example
textExtractionString Or Function"simple"Defines which method is used to extract data from a table cell for sorting. + The built-in option is "simple" which is the equivalent of doing this inside of the textExtraction function: $(node).text();. +
+
+ You can customize the text extraction by writing your own text extraction function "myTextExtraction" which you define like: +
var myTextExtraction = function(node, table, cellIndex){
+  // extract data from markup and return it
+  // originally: return node.childNodes[0].childNodes[0].innerHTML;
+  return $(node).find('selector').text();
+}
+$(function(){
+  $("#myTable").tableSorter( { textExtraction: myTextExtraction } );
+});
+ tablesorter will pass the current table cell object for you to parse and return. Thanks to Josh Nathanson for the examples. Updated to a jQuery example by Rob G (Mottie). +

Now if the text you are finding in the script above is say a number, then just include the headers sorter option to specify how to sort it. Also in this example, we will specify that the special textExtraction code is only needed for the second column ("1" because we are using a zero-based index). All other columns will ignore this textExtraction function.

+

Added table and cellIndex variables to the textExtraction function in version 2.1.2.

+
$(function(){
+  $("table").tablesorter({
+    textExtraction: {
+      1: function(node, table, cellIndex) {
+           return $(node).find("span:last").text();
+      }
+    },
+    headers: {
+      1: { sorter : "digit" }
+    }
+  });
+});
+
Example
textSorterFunctionnull + Replace the default sorting algorithm with a custom one using this option. +
+
+ Include a script like naturalSort.js as follows: +
$(function(){
+  $("table").tablesorter({
+    textSorter : naturalSort
+  });
+});
+ or use the localeCompare sort +
$(function(){
+  $("table").tablesorter({
+    textSorter: function(a,b) {
+      return a.localeCompare(b);
+    }
+  });
+});
There's no need to worry about reverse sorting, it's taken care of by the plugin. +
+
Example
usNumberFormatBooleantrue + Indicates how tablesorter should deal with a numerical format: (v2.1.3). +
+ + + + + + + + + + + +
trueU.S.1,234,567.89
falseGerman:
French:
1.234.567,89
1 234 567,89
+
+
Example
widgetsArray[ ] (empty array) + Initialize widgets using this option ( e.g. widgets : ['zebra'], or custom widgets widgets: ['zebra', 'myCustomWidget'];, see this demo on how to write your own custom widget ). + Example
widthFixedBooleanfalse + Indicates if tablesorter should apply fixed percentage-based widths to the table columns. Modified! v2.4. +
+ Prior to v2.4, this option set pixel widths to added colgroups to fix the column widths. This is useful for the Pager companion. +
+ Requires the jQuery dimension plugin to work. This is now part of the jQuery core. +
+
Example
widgetOptionsObject{ } + In version 2.1, all widget options have been moved into this option. This is a move to store all widget specific options in one place so as not to polute the main table options. All current widgets have been modified to use this new option. (v2.1). +
+
+ Previously documented widget options widgetZebra, widgetColumns and widgetUitheme will be retained for backwards compatibility.
+
+ Use the widgetOptions option as follows, please note that each option is followed by a comma (except the last one): +
$(function(){
+  $("table").tablesorter({
+
+    // initialize a bunch of widgets
+    widgets: ["zebra", "uitheme", "columns", "filter", "resizable", "stickyHeaders"],
+
+    widgetOptions: {
+
+      // *** columns widget ***
+      // change the default column class names
+      columns : [ "primary", "secondary", "tertiary" ],
+      // include thead when adding class names
+      columns_thead : true,
+      // include tfoot when adding class names
+      columns_tfoot : true,
+
+      // *** filter widget ***
+      // Include child rows content in the search
+      filter_childRows     : false,
+      // show column filters
+      filter_columnFilters : true,
+      // css class applied to the filter row inputs/select
+      filter_cssFilter     : "tablesorter-filter",
+      // add custom filter functions using this option.
+      filter_functions     : null,
+      // if true, the filter row is hidden initially until hovered/focused.
+      filter_hideFilters   : false,
+      // if true, make all searches case-insensitive.
+      filter_ignoreCase    : true,
+      // jQuery selector string of an element used to reset the filters.
+      filter_reset         : null,
+      // typing delay in milliseconds before starting a search.
+      filter_searchDelay   : 300,
+      // if true, filter start from the beginning of the cell contents.
+      filter_startsWith    : false,
+      // filter all data using parsed content.
+      filter_useParsedData : false,
+
+      // *** stickyHeaders widget ***
+      // css class name applied to the sticky header
+      stickyHeaders : "tablesorter-stickyHeader",
+
+      // *** resizable widget ***
+      // if false, resized columns are not saved for next page reload
+      resizable : true,
+
+      // *** savesort widget ***
+      // if false, the sort will not be saved for next page reload
+      saveSort : true,
+
+      // *** uitheme widget ***
+      // include the name of the theme to use current options are
+      // "jui" (default) and "bootstrap"
+      uitheme : "jui",
+
+      // *** zebra widget ***
+      // class names to add, default is [ "even", "odd" ]
+      zebra : ["ui-widget-content even", "ui-state-default odd"]
+
+    }
+
+  });
+});
+
Example
Deprecated Options
widgetColumnsObject with Array{ css:[ "primary", "secondary", "tertiary" ] } + This option is being deprecated! + It has been replaced by widgetOptions.columns; but is still available for backwards compatibility. +
+
+ When the column styling widget is initialized, it automatically applied the default class names of "primary" for the primary sort, "secondary" for the next sort, "tertiary" for the next sort, and so on (add more as needed)... (v2.0.17). + Use the widgetColumns option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["columns"], // initialize column styling of the table
+    widgetColumns: { css: ["primary", "secondary", "tertiary" ] }
+  });
+});
+
widgetUithemeObject with Array{ css: [ "ui-icon-arrowthick-2-n-s", "ui-icon-arrowthick-1-s", "ui-icon-arrowthick-1-n" ] } + This option is being deprecated! + It has been replaced by widgetOptions.uitheme; but is still available for backwards compatibility. +
+
+ Used when the ui theme styling widget is initialized. It automatically applies the default class names of "ui-icon-arrowthick-2-n-s" for the unsorted column, "ui-icon-arrowthick-1-s" for the descending sort and "ui-icon-arrowthick-1-n" for the ascending sort. (v2.0.9). + Find more jQuery UI class names by hovering over the Framework icons on this page: http://jqueryui.com/themeroller/
+
+ Use the widgetUitheme option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["uitheme"], // initialize ui theme styling widget of the table
+    widgetUitheme: {
+      css: [
+        "ui-icon-carat-2-n-s", // Unsorted icon
+        "ui-icon-carat-1-s",   // Sort up (down arrow)
+        "ui-icon-carat-1-n"    // Sort down (up arrow)
+      ]
+    }
+  });
+});
+
widgetZebraObject with Array{ css: [ "even", "odd" ] } + This option is being deprecated! + It has been replaced by widgetOptions.zebra; but is still available for backwards compatibility. +
+
+ When the zebra striping widget is initialized, it automatically applied the default class names of "even" and "odd". + Use the widgetZebra option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["zebra"], // initialize zebra striping of the table
+    widgetZebra: { css: [ "normal-row", "alt-row" ] }
+  });
+});
+
+ + +

Widget Options

+ + + + + + + + + + + + + + + +
Applied OrderNameRequires jQueryLimiting function
6columnsv1.2.6
5filterv1.4.31.4.3 (nextUntil)
8pagerv1.2.6
4resizablev1.4.1*1.4 (isEmptyObject); 1.4.1 (parseJSON)*
3saveSortv1.4.11.4.1 (parseJSON)*
2stickyHeadersv1.2.6
1uithemev1.2.6
7zebrav1.2.6
+ +
+

+ tablesorter widgets have many options, and to better organize them, they now are grouped together inside of the widgetOptions. Thanks to thezoggy for putting together this jQuery-widget compatibility table, but please note: +
    +
  • The applied order will not change depending on the widgets applied, but the numbers will change.
  • +
  • The widgets are actually applied in reverse alphabetical order. This includes any custom widget names, so a custom widget named "zoom" will be the first applied widget. The only exception is the zebra widget which will always be the last widget applied.
  • +
  • The pager, being a plugin, is actually initialized after tablesorter has initialized and all selected widgets applied.
  • +
  • * The saveSort and resizable widgets use the $.tablesorter.storage function by default and thus need the ParseJSON function which is available in jQuery 1.4.1+.
  • +
+ +
+ TIP! Click on the link in the property column to reveal full details (or toggle|show|hide all) or double click to update the browser location. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyTypeDefaultDescriptionLink
PropertyTypeDefaultDescriptionLink
columnsArray[ "primary", "secondary", "tertiary" ] + Columns widget: When the column styling widget is initialized, it automatically applied the default class names of "primary" for the primary sort, "secondary" for the next sort, "tertiary" for the next sort, and so on (add more as needed)... (Modified v2.1). +
+
+ Use the "columns" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["columns"], // initialize column styling of the table
+    widgetOptions : {
+      columns: [ "primary", "secondary", "tertiary" ]
+    }
+  });
+});
+
Example
columns_theadArraytrue + Columns widget: If true, the class names from the columns option will also be added to the table thead. New! v2.4. +
+
+ Use the "columns_thead" option to add the column class names to the thead as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["columns"], // initialize column styling of the table
+    widgetOptions : {
+      columns_thead: true
+    }
+  });
+});
+
Example
columns_tfootArraytrue + Columns widget: If true, the class names from the columns option will also be added to the table tfoot. New! v2.4. +
+
+ Use the "columns_tfoot" option to add the column class names to the tfoot as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["columns"], // initialize column styling of the table
+    widgetOptions : {
+      columns_tfoot: true
+    }
+  });
+});
+
Example
filter_childRowsBooleanfalse + Filter widget: If there are child rows in the table (rows with class name from "cssChildRow" option) and this option is true and a match is found anywhere in the child row, then it will make that row visible. + (Modified v2.1). +
+
+ Use the filter_childRows option include child row text as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_childRows : true
+    }
+  });
+});
+
filter_columnFiltersBooleantrue + Filter widget: If true, a filter will be added to the top of each table column. New! v2.4. +
+
+ Use the filter_columnFilters option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_columnFilters : true
+    }
+  });
+});
+
filter_cssFilterString'tablesorter-filter' + Filter widget: This is the class name applied to each input within the filter row. If you change it from the default class name of "tablesorter-filter" make sure you also update the css! (v2.1). +
+
+ Use the "tablesorter-filter" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      // css class applied to the table row containing the filters & the inputs within that row
+      filter_cssFilter : "tablesorter-filter"
+    }
+  });
+});
+
Example
filter_functionsObjectnull + Filter widget: Customize the filter widget by adding a select dropdown with content, custom options or custom filter functions (v2.3.6). +
+ Use the "filter_functions" option in three different ways: +
+
    +
  • + Make a sorted select dropdown list of all column contents. Repeated content will be combined. +
    $(function(){
    +  $("table").tablesorter({
    +    widgets: ["filter"],
    +    widgetOptions: {
    +      filter_functions: {
    +        // Add select menu to this column
    +        // set the column value to true, and/or add "filter-select" class name to header
    +        0 : true
    +      }
    +    }
    +  });
    +});
    + Alternately, instead of setting the column filter funtion to true, give the column header a class name of "filter-select". See the demo.

    +
  • +
  • + Make a select dropdown list with custom option settings. Each option must have a corresponding function which returns a boolean value; return true if there is a match, or false with no match. + +

    Regex example

    +
    $(function(){
    +  $("table").tablesorter({
    +    widgets: ["filter"],
    +    widgetOptions: {
    +      // function variables:
    +      // e = exact text from cell
    +      // n = normalized value returned by the column parser
    +      // f = search filter input value
    +      // i = column index
    +      filter_functions: {
    +        // Add these options to the select dropdown (regex example)
    +        2 : {
    +          "A - D" : function(e, n, f, i) { return /^[A-D]/.test(e); },
    +          "E - H" : function(e, n, f, i) { return /^[E-H]/.test(e); },
    +          "I - L" : function(e, n, f, i) { return /^[I-L]/.test(e); },
    +          "M - P" : function(e, n, f, i) { return /^[M-P]/.test(e); },
    +          "Q - T" : function(e, n, f, i) { return /^[Q-T]/.test(e); },
    +          "U - X" : function(e, n, f, i) { return /^[U-X]/.test(e); },
    +          "Y - Z" : function(e, n, f, i) { return /^[Y-Z]/.test(e); }
    +        }
    +      }
    +    }
    +  });
    +});
    +

    Comparison example

    +
    $(function(){
    +  $("table").tablesorter({
    +    widgets: ["filter"],
    +    widgetOptions: {
    +      // function variables:
    +      // e = exact text from cell
    +      // n = normalized value returned by the column parser
    +      // f = search filter input value
    +      // i = column index
    +      filter_functions: {
    +        // Add these options to the select dropdown (numerical comparison example)
    +        // Note that only the normalized (n) value will contain numerical data
    +        // If you use the exact text, you'll need to parse it (parseFloat or parseInt)
    +        4 : {
    +          "< $10"      : function(e, n, f, i) { return n < 10; },
    +          "$10 - $100" : function(e, n, f, i) { return n >= 10 && n <=100; },
    +          "> $100"     : function(e, n, f, i) { return n > 100; }
    +        }
    +      }
    +    }
    +  });
    +});
    + Note: if the filter_ignoreCase option is true, it DOES alter the normalized value (n) by making it all lower case.

    +
  • +
  • + Make a custom filter for the column. +
    $(function(){
    +  $("table").tablesorter({
    +    widgets: ["filter"],
    +    widgetOptions: {
    +      // function variables:
    +      // e = exact text from cell
    +      // n = normalized value returned by the column parser
    +      // f = search filter input value
    +      // i = column index
    +      filter_functions: {
    +        // Exact match only
    +        1 : function(e, n, f, i) {
    +          return e === f;
    +        }
    +      }
    +    }
    +  });
    +});
    + Note: if the filter_ignoreCase option is true, it DOES alter the normalized value (n) by making it all lower case.

    +
  • +
+
+
Example
filter_hideFiltersBooleanfalse + Filter widget: Set this option to true to hide the filter row initially. The rows is revealed by hovering over the filter row or giving any filter input/select focus. New! v2.4. +
+
+ Use the filter_hideFilters option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_hideFilters : true
+    }
+  });
+});
You can change the style (thickness) of the hidden filter row in the tablesorter theme css. Look for .tablesorter-filter-row (revealed row) and .tablesorter-filter-row.hideme (for the hidden row) css definitions.
+
Example
filter_ignoreCaseBooleantrue + Filter widget: Set this option to false to make the column content search case-insensitive, so typing in "a" will not find "Albert". (v2.3.4) +
+
+ Use the filter_ignorecase option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_ignoreCase : false
+    }
+  });
+});
+
Example
filter_resetStringnull + Filter widget: jQuery selector string of an element used to reset the filters. New! v2.4. +
+

+ To use this option, point to a reset button or link using a jQuery selector. For example, add this button (<button class="reset">Reset</button>) to the table header, or anywhere else on the page. That element will be used as a reset for all column and quick search filters (clears all fields): +

+ Use the filter_reset option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_reset : '.reset'
+    }
+  });
+});
+
Example
filter_searchDelayNumeric300 + Filter widget: Set this option to the number of milliseconds to delay the search. (v2.3.4). +
+
+ Use the filter_searchDelay option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_searchDelay : 500
+    }
+  });
+});
+ + If you want to want to initialize the filter without user input, target any one of the filters and trigger a "search". + +
// target the first filter input
+// this method will begin the search after the searchDelay time
+$('input.tablesorter-filter:eq(0)').trigger('search');
+
+// this method will begin the search immediately
+$('input.tablesorter-filter:eq(0)').trigger('search', false);
+ + In tablesorter v2.4+, the trigger can be applied directly to the table: +
// refresh the widget filter; no delay
+$('table').trigger('search', false);
+
filter_startsWithBooleanfalse + Filter widget: Set this option to true to use the filter to find text from the start of the column, so typing in "a" will find "albert" but not "frank", both have a's. (v2.1). +
+
+ Use the filter_startsWith option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_startsWith : true
+    }
+  });
+});
+
Example
filter_useParsedDataBooleanfalse + Filter widget: If true, ALL filter searches will only use parsed data. New! v2.4. +
+
+ Use the filter_useParsedData option as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_useParsedData : false
+    }
+  });
+});
+
    +
  • To only use parsed data in specific columns, set this option to false and use any of the following (they all do the same thing), set in order of priority: +
      +
    • jQuery data data-filter="parsed".
    • +
    • metadata class="{ filter: 'parsed'}". This requires the metadata plugin.
    • +
    • headers option headers : { 0 : { filter : 'parsed' } }.
    • +
    • header class name class="filter-parsed".
    • +
    +
  • +
  • Remember that parsed data most likely doesn't match the actual table cell text, 20% becomes 20 and Jan 1, 2013 12:01 AM becomes 1357020060000.
  • +
+
+
stickyHeadersString"tablesorter-stickyHeader" + Sticky Headers widget: This is the class name applied to the sticky header row (tr). If you change it from the default class name of "tablesorter-stickyHeader" make sure you also update the css! (v2.1). +
+
+ Use the "stickyHeaders" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["stickyHeaders"],
+    widgetOptions : {
+      // css class name applied to the sticky header
+      stickyHeaders : "tablesorter-stickyHeader"
+    }
+  });
+});
+
Example
resizableBooleantrue + Resizable widget: If this option is set to false, resized column widths will not be saved. Previous saved values will be restored on page reload. New! v2.4. +
+
+ Use the "resizable" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["resizable"],
+    widgetOptions : {
+      // css class name applied to the sticky header
+      resizable : false
+    }
+  });
+});
+
Example
saveSortBooleantrue + saveSort widget: If this option is set to false, new sorts will not be saved. Any previous saved sort will be restored on page reload. New! v2.4. +
+
+ Use the "saveSort" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["saveSort"],
+    widgetOptions : {
+      // if false, the sort will not be saved for next page reload
+      saveSort : false
+    }
+  });
+});
+
Example
uithemeString"jui" + ** Updated! in tablesorter v2.4 **
+ + Instead of the array of icon class names, this option now contains the name of the theme. Currently jQuery UI ("jui") and Bootstrap ("bootstrap") themes are supported. To modify the class names used, extend from the theme +
+

+
// Extend the themes to change any of the default class names ** NEW **
+$.extend($.tablesorter.themes.jui, {
+  // change default jQuery uitheme icons - find the full list of icons
+  // here: http://jqueryui.com/themeroller/ (hover over them for their name)
+  table    : 'ui-widget ui-widget-content ui-corner-all', // table classes
+  header   : 'ui-widget-header ui-corner-all ui-state-default', // header classes
+  icons    : 'ui-icon', // icon class added to the <i> in the header
+  sortNone : 'ui-icon-carat-2-n-s',
+  sortAsc  : 'ui-icon-carat-1-n',
+  sortDesc : 'ui-icon-carat-1-s',
+  active   : 'ui-state-active', // applied when column is sorted
+  hover    : 'ui-state-hover',  // hover class
+  filterRow: '',
+  even     : 'ui-widget-content', // even row zebra striping
+  odd      : 'ui-state-default'   // odd row zebra striping
+});
+ + This widget option replaces the previous widgetUitheme. All theme css names are now contained within the $.tablesorter.themes variable. Extend the default theme as seen above.
+
+ + The class names from the $.tablesorter.themes.{name} variable are applied to the table as indicated.
+
+ + As before the jQuery UI theme applies the default class names of "ui-icon-arrowthick-2-n-s" for the unsorted column, "ui-icon-arrowthick-1-s" for the descending sort and "ui-icon-arrowthick-1-n" for the ascending sort. (Modified v2.1; Updated in v2.4). Find more jQuery UI class names by hovering over the Framework icons on this page: http://jqueryui.com/themeroller/
+
+ Use the "uitheme" option to change the css class name as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["uitheme"], // initialize ui theme styling widget of the table
+    widgetOptions: {
+      uitheme : "jui"
+    }
+  });
+});
+ + To add a new theme, define it as follows; replace "custom" with the name of your theme: +
$.tablesorter.themes.custom = {
+  table    : 'table',       // table classes
+  header   : 'header',      // header classes
+  icons    : 'icon',        // icon class added to the <i> in the header
+  sortNone : 'sort-none',   // unsorted header
+  sortAsc  : 'sort-asc',    // ascending sorted header
+  sortDesc : 'sort-desc',   // descending sorted header
+  active   : 'sort-active', // applied when column is sorted
+  hover    : 'hover',       // hover class
+  filterRow: 'filters',     // class added to the filter row
+  even     : 'even',        // even row zebra striping
+  odd      : 'odd'          // odd row zebra striping
+}
+
Example
zebraArray[ "even", "odd" ] + zebra widget: When the zebra striping widget is initialized, it automatically applied the default class names of "even" and "odd". (Modified v2.1). +
+
+ Use the "zebra" option to change the theme as follows: +
$(function(){
+  $("table").tablesorter({
+    widgets: ["zebra"], // initialize zebra striping of the table
+    widgetOptions: {
+      zebra: [ "normal-row", "alt-row" ]
+    }
+  });
+});
+
Example
+ + +

Methods

+ +
+

+ tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized. +
+ TIP! Click on the link in the method column to reveal full details (or toggle|show|hide all) or double click to update the browser location. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodDescriptionLink
addRowsUse this method to add table rows. (v2.0.16). +
+ It does not work the same as "update" in that it only adds rows, it does not remove them.
+ Also, use this method to add table rows while using the pager plugin. If the "update" method is used, only the visible table rows continue to exist. +
// Add multiple rows to the table
+  var row = '<tr><td>Inigo</td><td>Montoya</td><td>34</td>' +
+    '<td>$19.99</td><td>15%</td><td>Sep 25, 1987 12:00PM</td></tr>',
+    $row = $(row),
+    // resort table using the current sort; set to false to prevent resort, otherwise
+    // any other value in resort will automatically trigger the table resort.
+    // A callback method was added in 2.3.9.
+    resort = true,
+    callback = function(table){
+      alert('rows have been added!');
+    };
+  $('table')
+    .find('tbody').append($row)
+    .trigger('addRows', [$row, resort, callback]);
+
Example
sortonUse this method to sort an initialized table in the desired order. +
+
// Choose a new sort order
+var sort = [[0,0],[2,0]],
+    callback = function(table){
+        alert('new sort applied to ' + table.id);
+    };
+// Note that the sort value below is inside of another array (inside another set of square brackets)
+// A callback method was added in 2.3.9.
+$("table").trigger("sorton", [sort, callback]);
+
Example
updateUpdate the stored tablesorter data and the table. +
+
// Add new content
+$("table tbody").append(html);
+
+// let the plugin know that we made a update
+// the resort flag set to anything BUT false (no quotes) will trigger an automatic
+// table resort using the current sort
+// A callback method was added in 2.3.9.
+var resort = true,
+    callback = function(table){
+        alert('new sort applied');
+    };
+$("table").trigger("update", [resort, callback]);
+
+// As of version 2.0.14, the table will automatically resort (using the current sort selection)
+// after the update, so include the following if you want to specify a different sort
+
+// set sorting column and direction, this will sort on the first and third column
+var sorting = [[2,1],[0,0]];
+$("table").trigger("sorton", [sorting]);
+
Example
appendCacheUpdate a table that has had its data dynamically changed; used in conjunction with "update".
+
+ Use this method when more than just one cell like in the "updateCell" method, but you may possibly have to trigger two events: both "update" and "appendCache".
+
+ Note: This is the only method the pager widget uses - the entire table is stored in the cache, but only the visible portion is actually exists in the table. +
// Table data was just dynamically changed (more than one cell)
+$("table")
+  .trigger("update")
+  .trigger("appendCache");
+
updateCellUpdate a table cell in the tablesorter data. +
+
$(function() {
+  $("table").tablesorter();
+
+  $("td.discount").click(function(){
+
+    // randomize a number
+    var resort = false,
+        discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' +
+          ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
+    // add new table cell text
+    $(this).text(discount);
+
+    // update the table, so the tablesorter plugin can update its value
+    // set resort flag to false to prevent automatic resort (since we're using a different sort below)
+    // leave the resort flag as undefined, or with any other value, to automatically resort the table
+    // $("table").trigger("updateCell", [this]); < - resort is undefined so the table WILL resort
+    $("table").trigger("updateCell", [this, resort]);
+
+    // As of version 2.0.14, the table will automatically resort (using the current sort selection)
+    // after the update, so include the following if you want to specify a different sort
+
+    // set sorting column and direction, this will sort on the first and third column
+    var sorting = [[3,1]];
+    $("table").trigger("sorton", [sorting]);
+
+    return false;
+  });
+});
+
Example
applyWidgetIdApply the selected widget to the table, but the widget will not continue to be applied after each sort. See the example, it's easier than describing it. +
+
$(function(){
+  // initialize tablesorter without the widget
+  $("table").tablesorter();
+
+  // click a button to apply the zebra striping
+  $("button").click(function(){
+    $('table').trigger('applyWidgetId', ['zebra']);
+  });
+
+});
+
Example
applyWidgetsApply the set widgets to the table. This method can be used after a table has been initialized, but it won't work unless you update the configuration settings. See the example, it's easier than describing it. +
+
// Update the list of widgets to apply to the table (add or remove)
+// $("table").data("tablesorter").widgets = ["zebra"]; // works the same as
+$("table")[0].config.widgets = ["zebra"];
+
+// This method applies the widget - no need to keep updating
+$('table').trigger('applyWidgets');
+
+
Example
destroyUse this method to remove tablesorter from the table. +
+
// Remove tablesorter and all classes
+$("table").trigger("destroy");
+
+// Remove tablesorter and all classes but the "tablesorter" class on the table
+$("table").trigger("destroy", [false];
+
refreshWidgetsRefresh the currently applied widgets. Depending on the options, it will completely remove all widgets, then re-initialize the current widgets or just remove all non-current widgets. New v2.4. +

+ Trigger this method using either of the following methods (they are equivalent): +
// trigger a refresh widget event
+$('table').trigger('refreshWidgets', [doAll, dontapply]);
+
+// Use the API directly
+$.tablesorter.refreshWidgets(table, doAll, dontapply)
+
    +
  • If doAll is true it removes all widgets from the table. If false only non-current widgets (from the widgets option) are removed.
  • +
  • When done removing widgets, the widget re-initializes the currently selected widgets, unless the dontapply parameter is true leaving the table widget-less.
  • +
  • Note that if the widgets option has any named widgets, they will be re-applied to the table when it gets resorted. So if you want to completely remove all widgets from the table, also clear out the widgets option $('table')[0].config.widgets = [];
  • +
+
+
Example
Widget Methods
+ + +

Events

+ +
+

+ tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized. +
+ TIP! Click on the link in the event column to reveal full details (or toggle|show|hide all) or double click to update the browser location. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EventDescriptionLink
initializedThis event fires when tablesorter has completed initialization. (v2.2). +
+
$(function(){
+
+  // bind to initialized event BEFORE initializing tablesorter
+  $("table")
+    .bind("tablesorter-initialized",function(e, table) {
+      // do something after tablesorter has initialized
+    });
+
+  // initialize the tablesorter plugin
+  $("table").tablesorter({
+    // this is equivalent to the above bind method
+    initialized : function(table){
+      // do something after tablesorter has initialized
+    }
+  });
+
+});
+
sortBeginThis event fires immediately before tablesorter begins resorting the table. +
+
$(function(){
+
+  // initialize the tablesorter plugin
+  $("table").tablesorter();
+
+  // bind to sort events
+  $("table").bind("sortBegin",function(e, table) {
+    // do something crazy!
+  });
+});
+
sortStartThis event fires immediately after the tablesorter header has been clicked, initializing a resort. +
+
$(function(){
+
+  // initialize the tablesorter plugin
+  $("table").tablesorter();
+
+  // bind to sort events
+  $("table")
+    .bind("sortStart",function(e, table) {
+      $("#overlay").show();
+    })
+    .bind("sortEnd",function(e, table) {
+      $("#overlay").hide();
+    });
+});
+
Example
sortEndThis event fires when tablesorter has completed resorting the table. +
+
$(function(){
+
+  // initialize the tablesorter plugin
+  $("table").tablesorter();
+
+  // bind to sort events
+  $("table")
+    .bind("sortStart",function(e, table) {
+      $("#overlay").show();
+    })
+    .bind("sortEnd",function(e, table) {
+      $("#overlay").hide();
+    });
+});
+
Example
Pager Events
pagerChangeThis event fires when the pager plugin begins to render the table on the currently selected page. (v2.0.7). +
+
$(function(){
+
+  // initialize the sorter
+  $("table")
+    .tablesorter()
+
+    // initialize the pager plugin
+    .tablesorterPager({
+      container: $("#pager")
+    })
+
+    // bind to pager events
+    .bind('pagerChange pagerComplete', function(e,c){
+      // c.totalPages contains the total number of pages
+      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
+    });
+
+});
+
Example
pagerCompleteThis event fires when the pager plugin has completed its render of the table on the currently selected page. (v2.0.7). +
+
$(function(){
+
+  // initialize the sorter
+  $("table")
+    .tablesorter()
+
+    // initialize the pager plugin
+    .tablesorterPager({
+      container: $("#pager")
+    })
+
+    // bind to pager events
+    .bind('pagerChange pagerComplete', function(e,c){
+      // c.totalPages contains the total number of pages
+      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
+    });
+
+});
+
Example
pagerInitializedThis event fires when the pager plugin has completed initialization. New v2.4.4. +
+
$(function(){
+
+  $("table")
+
+    // initialize the sorter
+    .tablesorter()
+
+    // bind to pager initialized event BEFORE calling the addon
+    .bind('pagerInitialized', function(e, c){
+      // c.totalPages contains the total number of pages
+      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
+    })
+
+    // initialize the pager plugin
+    .tablesorterPager({
+      container: $("#pager")
+    });
+
+});
+
Example
pageMovedThis event fires when the pager plugin begins to change to the selected page. New v2.4.4. +
+ This event may fire before the pagerComplete event when ajax processing is involved, or after the pagerComplete on normal use. + See issue #153. +
$(function(){
+
+  // initialize the sorter
+  $("table")
+    .tablesorter()
+
+    // initialize the pager plugin
+    .tablesorterPager({
+      container: $("#pager")
+    })
+
+    // bind to pager events
+    .bind('pageMoved', function(e, c){
+      // c.totalPages contains the total number of pages
+      $('#display').html( e.type + " event triggered, now on page " + (c.page + 1) );
+    });
+
+});
+
Example
Widget Events
filterInitEvent triggered when the filter widget has finished initializing. New v2.4. +
+ You can use this event to modify the filter elements (row, inputs and/or selects) as desired. Use it as follows:
$(function(){
+  $('table').bind('filterInit', function(){
+    $(this).find('tr.tablesorter-filter-row').addClass('fred');
+  });
+});
+
Example
filterStartEvent triggered when the filter widget has started processing the search. New v2.4. +
+ You can use this event to do something like add a class to the filter row. Use it as follows:
$(function(){
+  $('table').bind('filterStart', function(){
+    $(this).find('tr.tablesorter-filter-row').addClass('filtering');
+  });
+});
+
Example
filterEndEvent triggered when the filter widget has finished processing the search. New v2.4. +
+ You can use this event to do something like remove the class added to the filter row when the filtering started. Use it as follows:
$(function(){
+  $('table').bind('filterEnd', function(){
+    $(this).find('tr.tablesorter-filter-row').removeClass('filtering');
+  });
+});
+
Example
+ + +

Download

+ +

Full release - Plugin, Documentation, Add-ons, Themes. Download: zip or tar.gz

+ +

Pick n choose - Place at least the required files in a directory on your webserver that is accessible to a web browser. Record this location.

+ + Required: + + + Optional / Add-Ons: + + + Themes: +

Theme zip files have been removed. There are now numerous themes available which can be seen here

+ + +

Browser Compatibility

+ +

tablesorter has been tested successfully in the following browsers with Javascript enabled:

+
    +
  • Firefox 2+
  • +
  • Internet Explorer 6+
  • +
  • Safari 2+
  • +
  • Opera 9+
  • +
  • Konqueror
  • +
+ +

jQuery Browser Compatibility

+ + +

Support

+ +

If you are having a problem with the plugin or you want to submit a feature request, please submit an issue.

+ +

If you would like to contribute, fork a copy on github.

+ +

Support is also available through the jQuery Mailing List or StackOverflow.

+ +

Access to the jQuery Mailing List is also available through Nabble Forums.

+ + +

Credits

+

Written by Christian Bach.

+

+ Documentation written by Brian Ghidinelli, + based on Mike Alsup's great documention.
+ Additional & Missing documentation, alphanumeric sort, numerous widgets and other changes added by Mottie. +

+

+ John Resig for the fantastic jQuery +

+
+ + + diff --git a/package.json b/package.json index 16c4de9a..23ed289c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tablesorter", - "version": "2.4.3", + "version": "2.4.4", "title": "tablesorter", "author": { "name": "Christian Bach",