Original Author: Christian Bach
Maintainer of this fork: Rob Garrison (Mottie)
Version: 2.31.1 (changelog)
Licence:
Dual licensed under MIT
or GPL licenses (pick one).
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:
Account # |
First Name |
Last Name |
Age |
Total |
Discount |
Difference |
Date |
---|---|---|---|---|---|---|---|
A42b | Peter | Parker | 28 | $9.99 | 20.9% | +12.1 | Jul 6, 2006 8:14 AM |
A255 | Bruce | Jones | 33 | $13.19 | 25% | +12 | Dec 10, 2002 5:14 AM |
A33 | Clark | Evans | 18 | $15.89 | 44% | -26 | Jan 12, 2003 11:14 AM |
A1 | Bruce | Almighty | 45 | $153.19 | 44.7% | +77 | Jan 18, 2001 9:12 AM |
A102 | Bruce | Evans | 22 | $13.19 | 11% | -100.9 | Jan 18, 2007 9:12 AM |
A42a | Bruce | Evans | 22 | $13.19 | 11% | 0 | Jan 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!
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-addresses for more information see 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.
sortList
).sortInitialOrder
option [demo], or other methods).sortReset
& sortRestart
).sortReset
method; v2.4.7).cssIgnoreRow
class; v2.18.4).sortForce
).sortAppend
; v2.24.0).emptyTo
; v2.1.11).selectorSort
; v2.4).sortMultiSortKey
).textSorter
; added v2.2; updated v2.12).sortLocaleCompare
; v2.24; languages).delayInit
).duplicateSpan
; v2.25.0).stringTo
; v2.0.10).addParser
; v2.18.0; v2.18.0).textExtraction
function).addWidget
).update
).addRows
; v2.0.16).thead
and tbody
) (updateAll
; v2.8).updateCell
).onRenderHeader
).headerTemplate
; v2.7).debug
).jquery.tablesorter.widgets.js
file (except for extra filter formatter functions).
Property | Type | Default | Description | Link |
---|---|---|---|---|
Property | Type | Default | Description | Link |
cancelSelection | Boolean | true | Indicates if tablesorter should disable selection of text in the table header (TH). Makes header behave more like a button. | |
duplicateSpan | Boolean | true | Any colspan cells in the tbody may have its content duplicated in the cache for each spanned column (v2.25.0; v2.25.8).
|
Example |
cssAsc | String | "" | Additional CSS class applied to style the header with a ascending sort (v2.11). | |
cssChildRow | String | "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" (Modified v2.4). |
1 2 |
cssDesc | String | "" | Additional CSS class applied to style the header with a descending sort (v2.11). | |
cssHeader | String | "" | Additional CSS class applied to style the headers (v2.11). | |
cssHeaderRow | String | "" | Additional CSS class applied to style the header row (v2.11). | |
cssIcon | String | "tablesorter-icon" | The CSS style used to style the header cell icon (modified v2.7; v2.21.1). | |
cssIconAsc | String | "" | The CSS style added to the header cell icon when the column has an ascending sort (v2.18.3). | |
cssIconDesc | String | "" | The CSS style used to style the header cell icon when the column has a descending sort (v2.18.3) | |
cssIconNone | String | "" | The CSS style used to style the header cell icon when the column does not have a sort applied (v2.18.3) | |
cssIconDisabled | String | "" | The CSS style used to style the header cell icon when the column sort is disabled (v2.28.13) | |
cssNone | String | "" | Additional CSS class applied to style the header when no sort is applied (v2.15). | |
cssProcessing | String | "" | Additional CSS class applied to style the header cell while it is being sorted or filtered (v2.4; v2.11). | |
cssInfoBlock | String | "tablesorter-infoOnly" | All tbodies with this class name will not have its contents sorted. (v2.2). | |
cssNoSort | String | "tablesorter-noSort" | Class name added to element inside header. Clicking on that element, or any elements within it won't cause a sort. (v2.20.0). | |
cssIgnoreRow | String | "tablesorter-ignoreRow" | Class name to add to a table header row if you want all cells within this row to be ignored (v2.18.4). | 1 2 |
dateFormat | String | "mmddyyyy" | Set the date format. Here are the available options. (Modified v2.0.23). | Example |
debug | Boolean or String | false | Set this option to provide useful for development debugging information in the console Updated v2.30.0. | Example |
delayInit | Boolean | false | 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 |
emptyTo | String | "bottom" | Option indicating how tablesorter should deal with empty table cells. (Modified v2.1.16, v2.16.2). | Example |
headers | Object | null |
An object of instructions for per-"header cell" controls in the format: headers: { 0: { option: setting }, ... }
(v2.17.1)
|
1 2 3 4 5 |
headerTemplate | String | "{content}" | This is a template string which allows adding additional content to the header while it is being built (v2.7; v2.17.8). | Example |
ignoreCase | Boolean | true | When true, text sorting will ignore the character case. If false, upper case characters will sort before lower case. (v2.2). | |
initialized | Function | null | This callback fires when tablesorter has completed initialization. (v2.2). | |
initWidgets | Boolean | true | Apply widgets after table initializes (v2.3.5). | |
widgetClass | String | "widget-{name}" | When the table has a class name that matches the template and a widget id that matches the {name} , the widget will automatically be added to the table (v2.18.0)
|
|
onRenderHeader | Function | null | This function is called after content is to the TH tags (after the template is procressed and added). You can use this to modify the HTML in each header tag for additional styling (v2.18.0). | Example |
onRenderTemplate | Function | null |
This function is called after the template string has been built, but before the template string is applied to the header and before the onRenderHeader function is called (v2.7).
|
Example |
selectorHeaders | String | "> thead th, > thead td" | jQuery selectors used to find cells in the header. | |
selectorRemove | String | "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). | |
selectorSort | String | "th, td" | jQuery selector of content within selectorHeaders that is clickable to trigger a sort (v2.4). |
Example |
resort | Boolean | true | When this option is true any applied sort on the table will be reapplied after an update method (v2.19.0).
|
|
serverSideSorting | Boolean | false | Set to true if the server is performing the sorting. The ui and events will still be used (v2.5.3). |
|
showProcessing | Boolean | false | Show 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 (v2.4). | Example |
sortForce | Array | null | Use to add an additional forced sort that is prepended to sortList .
|
Example |
sortList | Array | null | Use to add an initial sort to the table. | Example |
sortAppend | Array or Object | null | Use to add an additional forced sort that will be appended to the dynamic selections by the user (v2.24.0). | Example |
sortInitialOrder | String | "asc" |
This sets the direction a column will sort when clicking on the header for the first time. Valid arguments are "asc" for Ascending or "desc" for Descending. |
1 2 |
sortLocaleCompare | Boolean | false | Boolean flag indicating if certain accented characters within the table will be replaced with their equivalent characters. (Modified v2.2). | Example |
sortReset | Boolean | false |
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 |
sortResetKey | String | "ctrlKey" | The key used to reset sorting on the entire table. Defaults to the control key. The other options are "shiftKey" or "altKey" (reference). |
|
sortRestart | Boolean | false |
Setting this option to true will start the sort with the sortInitialOrder when clicking on a previously unsorted column. (v2.0.31).
|
Example |
sortStable | Boolean | false |
Setting this option to true and sorting two rows with exactly the same content, the original sort order is maintained (v2.14).
|
Example |
sortMultiSortKey | String | "shiftKey" | The key used to select more than one column for multi-column sorting. Defaults to the Shift key. | Example |
stringTo | String | "max" | A key word indicating how tablesorter should deal with text inside of numerically sorted columns. (v2.1.16). | Example |
tabIndex | Boolean | true | Add a tabindex to the headers for keyboard accessibility; this was previously always applied (v2.14). | |
tableClass | String | "" | Additional CSS class applied to style the table (v2.11). | |
theme | String | "default" | This option will add a theme css class name to the table "tablesorter-{theme}" for styling (v2.4; v2.18.0).
|
Example |
textAttribute | String | "data-text" | This data-attribute can be added to any tbody cell and can contains alternate cell text (v2.16.0). | |
textExtraction | Multiple* | "basic" | Defines which method is used to extract data from a table cell for sorting (v2.19.0) | Example |
namespace | String | undefined | This option should contain a unique namespace for each table; it is used when binding to event listeners (v2.15.7). | |
numberSorter | Function | null | Replace the default number sorting algorithm with a custom one using this option (v2.12). | |
pointerClick | String | "click" | Use this option to change the click event (v2.22.0) | |
pointerDown | String | "mousedown" | Use this option to change the pointer down event (v2.22.0) | |
pointerUp | String | "mouseup" | Use this option to change the pointer up event (v2.22.0) | |
textSorter | Function | null | Replace the default sorting algorithm with a custom one using this option (v2.27.6) - *NOTE* The parameters have changed!!. | 1 2 |
usNumberFormat | Boolean | true | Indicates how tablesorter should deal with a numerical format: (v2.1.3). | Example |
widgets | Array | [ ] (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 |
widthFixed | Boolean | false | Indicates if tablesorter should apply fixed percentage-based widths to the table columns (modified v2.4). | Example |
widgetOptions | Object | { } | 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). | Example |
Utility Options | ||||
checkboxClass | String | "checked" | Used by the "checkbox" parser in the parser-input-select.js file (v2.22.2; v2.25.0).
|
Example |
checkboxVisible | Boolean | true | Used by the "checkbox" parser in the parser-input-select.js file (v2.24.6).
|
Example |
data | Object, Array | undefined | Storage for processed table build widget (widget-build-table.js ) data (array, object, string) (v2.11). |
Example |
dateRange | Numeric | 50 |
Used by the two digit year parser (parser-date-two-digit-year.js ) to set the date range (v2.14). |
Example |
globalize | object | null | This option is used by multiple parsers to localize the language (v2.24.0; v2.24.1). | 2 2 |
ignoreChildRow | Boolean | false | Used by the input-select parser indicate if changes to child row content is to be ignored (v2.28.10) | |
imgAttr | String | "alt" |
Used by the image parser to grab the image attribute content (v2.17.5; moved to tablesorter core in v2.18.0; see config.parsers ).
|
|
Deprecated/Removed Options | ||||
fixedUrl | String | undefined |
This option is being deprecated in v2.21.3!
It has been replaced by widgetOptions.storage_fixedUrl ; but is still available for backwards compatibility.
|
|
cssAllowClicks | String | This option was removed! It has been replaced by cssNoSort which does the opposite of what this class name was supposed to do. | ||
widgetColumns |
This option was removed in v2.21.2!
It has been replaced by widgetOptions.columns .
|
|||
widgetUitheme |
This option was removed in v2.4!
It has been replaced by widgetOptions.uitheme .
|
|||
widgetZebra |
This option was removed in v2.4!
It has been replaced by widgetOptions.zebra .
|
Widget Priority | Name | Requires jQuery | Limiting function |
---|---|---|---|
30 | columns | v1.2.6 | |
50 | filter | v1.4.3 | 1.4.3 (nextUntil & delegate) |
Last | pager plugin | v1.2.6 | |
55 | pager widget | v1.7 | 1.7 (on) |
40 | resizable | v1.4.1* | 1.4.1 (parseJSON)* |
20 | saveSort | v1.4.1 | 1.4.1 (parseJSON)* |
60 | stickyHeaders | v1.4.3 | 1.4.3 (isWindow)** |
10 | uitheme | v1.2.6 | |
90 | zebra | v1.2.6 |
widgetOptions
. Thanks to thezoggy for putting together this jQuery-widget compatibility table, but please note:
10
.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+.stickyHeaders
widget was updated in v2.18.0 to use $.isWindow
for the xScroll
& yScroll
options; and therefore now requires jQuery 1.4.3+.Property | Type | Default | Description | Link |
---|---|---|---|---|
Property | Type | Default | Description | Link |
columns | Array | [ "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).
|
Example |
columns_thead | Boolean | true |
Columns widget: If true, the class names from the columns option will also be added to the table thead (v2.4).
|
Example |
columns_tfoot | Boolean | true |
Columns widget: If true, the class names from the columns option will also be added to the table tfoot (v2.4).
|
Example |
filter_childRows | Boolean | false |
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).
|
|
filter_childByColumn | Boolean | false |
Filter widget: If true , queries will search child row content by column (v2.22.0).
|
Example |
filter_childWithSibs | Boolean | true | Filter widget: include all sibling rows of the matching child row (v2.23.4). | Example |
filter_columnAnyMatch | Boolean | true |
Filter widget: If true , allows using "#:{query}" in anyMatch searches (v2.20.0).
|
|
filter_columnFilters | Boolean | true |
Filter widget: If true , a filter will be added to the top of each table column (v2.4).
|
|
filter_cellFilter | String or Array | "" | Filter widget: Additional CSS class applied to each filter cell (v2.18.0). | Example |
filter_cssFilter | String or Array | "" | Filter widget: Additional CSS class applied to each filter (v2.15). | Example |
filter_defaultFilter | Object | { } | Filter widget: Add a default filter type to a column (v2.17.8). | Example |
filter_excludeFilter | Object | { } | Filter widget: Additional CSS class applied to each filter (v2.17.8). Exclude a filter type(s) for a column. | |
filter_external | String | "" | Filter widget: jQuery selector string of inputs, outside of the table, to be used for searching table content (v2.15). | Example |
filter_filteredRow | String | "filtered" | Filter widget: This is the class name applied to all rows that do not match the filter (hidden rows); used by pager plugin (v2.10). | |
filter_filterLabel | String | 'Filter "{{label}}" column by...' | This option contains the ARIA-label value to be added to the filter input or select (v2.29.4). | Example |
filter_formatter | Object | null |
Filter widget: This option allows you to add custom controls within the filter widget row (v2.7.7; v2.17.0). |
1 2 |
filter_functions | Object | null | Filter widget: Customize the filter widget by adding a select dropdown with content, custom options or custom filter functions (v2.3.6; v2.17.0). | Example |
filter_hideEmpty | Boolean | true |
Filter widget: Set this option to false to always show the filter row; by default, the filter row is completely hidden when no rows exist within the tbody (v2.15).
|
|
filter_hideFilters | Boolean, or Function | false |
Filter widget: Set this option to true to hide the filter row initially. The row is revealed by hovering over the visible portion of the filter row or by giving any filter input/select focus (tab key) (v2.4; v2.26.6).
|
Example |
filter_ignoreCase | Boolean | true |
Filter widget: Set this option to false to make the column content search case-sensitive, so typing in "a" will not find "Albert". (v2.3.4)
|
Example |
filter_liveSearch | Boolean, Number or Object | true |
Filter widget: If true , a search of the column content will occur as the user types, with the delay set in the filter_searchDelay option (v2.9; v2.27.3).
|
|
filter_matchType | Object | { 'input': 'exact', 'select': 'exact' } | Filter widget: This option sets the global setting that applied to either input or select filters (v2.25.5) | Example |
filter_onlyAvail | String | "filter-onlyAvail" | Filter widget: If a header contains a select dropdown and this class name, only the available (visible) options in the column will show (v2.10.1; v2.17.6). | Example |
filter_placeholder | object | { search : '', select : '' } | Filter widget: Set global filter input placeholder text for search inputs and selects (v2.16). | Example |
filter_reset | String, jQuery object | null | Filter widget: jQuery selector string of an element used to reset the filters (v2.4; v2.16). | Example |
filter_resetOnEsc | Boolean | true |
Filter widget: when true , normalize pressing escape to clear filter input across browsers (v2.25.2).
|
|
filter_saveFilters | Boolean | false |
Filter widget: If the storage utility is available (included with jquery.tablesorter.widgets.js file, the last applied filter is saved to storage (v2.14).
|
Example |
filter_searchDelay | Numeric | 300 | Filter widget: Set this option to the number of milliseconds to delay the search. (v2.3.4). | |
filter_searchFiltered | Boolean | true | Filter widget: Set this option to allow searching through already filtered rows (in special conditions); this will speed up searching in large tables (v2.17.4). | Example |
filter_selectSource | Function | null | Filter widget: Include a function to return an array of values to be added to the column filter select (v2.16.0; v2.28.12). | 1 2 |
filter_selectSourceSeparator | String | '|' |
Filter widget: Set this option to be any separator (v2.17.6) that is to be used within the filter_selectSource returned array.
|
|
filter_serversideFiltering | Boolean | false |
Filter widget: Set this option to true if filtering is performed on the server-side (v2.5.3).
|
|
filter_startsWith | Boolean | false |
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).
|
Example |
filter_useParsedData | Boolean | false |
Filter widget: If true , ALL filter searches will only use parsed data (v2.4).
|
|
filter_defaultAttrib | String | "data-value" | Filter widget: This option contains the name of the data-attribute which contains the default (starting) filter value (v2.10.8). | Example |
stickyHeaders | String | "" | Sticky Headers widget: This additional CSS class applied to the sticky header row (v2.11). | Example |
stickyHeaders_cloneId | String | "-sticky" | Sticky Headers widget: If the table has an ID defined, the suffix from this option will be added to the ID in the cloned sticky table (v2.9). | |
stickyHeaders_includeCaption | Boolean | true |
Sticky Headers widget: If this option is false and a caption exists, it will not be included in the sticky header (v2.10.8).
|
Example |
stickyHeaders_appendTo | String, jQuery Object | null | Sticky Headers widget: jQuery selector or object to physically attach the sticky headers (v2.27.0). | |
stickyHeaders_attachTo | String, jQuery Object | null | Sticky Headers widget: points to the table wrapper to stick the headers to while scrolling. Use this option to point to their needs (v2.14.4). | Example |
stickyHeaders_xScroll | String, jQuery Object | null | Sticky Headers widget: points to the element in which to monitor for horizontal scrolling (v2.18.0). | Example |
stickyHeaders_yScroll | String, jQuery Object | null | Sticky Headers widget: points to the element in which to monitor for vertical scrolling (v2.18.0). | Example |
stickyHeaders_offset | Multiple | 0 | Sticky Headers widget: Set the sticky header offset from the top as a Number or jQuery selector string or object (v2.10). | |
stickyHeaders_filteredToTop | Boolean | true | Sticky Headers widget: Scroll table top into view after filtering (v2.16.2). | |
stickyHeaders_addResizeEvent | Boolean | true |
Sticky Headers widget: If true , sticky table headers will resize automatically when content is added to or removed from the table headers (v2.10).
|
|
stickyHeaders_zIndex | Numeric | 2 | Sticky Headers widget: The zIndex added to the stickyHeaders. This option allows the user to adjust the value to their needs (v2.11). | |
resizable | Boolean | true |
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 (v2.4).
|
Example |
resizable_addLastColumn | Boolean | false |
Resizable widget: If this option is set to true , a resizing anchor will be included in the last column of the table (v2.8.3).
|
Example |
resizable_includeFooter | Boolean | true | Resizable widget: If this option is set to true , the resizable handle will extend into the table footer (v2.28.8).
|
|
resizable_widths | Array | [] | Resizable widget: Set this option to the starting & reset header widths (v2.15.12). | Example |
resizable_throttle | Boolean | false | Resizable widget: Set this option to throttle the resizable events (v2.17.4). | |
resizable_targetLast | Boolean | false |
Resizable widget: When true , the last column will be targeted for resizing (v2.21.3).
|
|
saveSort | Boolean | true |
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 (v2.4).
|
Example |
storage_storageType | String | "" | Storage widget: Set this option to the first letter of the desired storage type (v2.28.8). | |
storage_useSessionStorage | Boolean | false | Storage widget: This option was deprecated in v2.28.8. | Example |
storage_tableId | String | "" | Storage widget: This option allows setting an alternate table id so multiple tables on a page have the settings grouped together | |
storage_group | String | "" | Storage widget: Set a table (data) attribute to use to obtain a table id, which allows grouping multiple tables on one page together - they share a common saved setting. | |
storage_fixedUrl | String | "" | Storage widget: This option allows setting an alternate table url so that tables on multiple pages will have their settings grouped together | |
storage_page | String | "" | Storage widget: Set a table (data) attribute to use to obtain a table url, which allows grouping tables across multiple pages together - they share a common saved setting. | |
zebra | Array | [ "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).
|
Example |
Pager | ||||
container | Object | null | Target your one or more pager markup blocks by setting this option with a jQuery selector. | Example |
ajaxUrl | String | null | Set this option to include a url template to use so that the pager plugin can interact with your database (v2.1; v2.9). | Example |
customAjaxUrl | Function | function(table, url) { return url; } | This callback function allows you to modify the processed URL as desired (v2.8.1). | Example |
ajaxObject | Object | { dataType: 'json' } | This option contains the ajax settings for the pager interaction with your database (v2.10). | Example |
ajaxError | Function | null |
This callback allows you to customize the error message displayed in the thead (v2.23.0; v2.23.1).
|
|
initialRows | Object | undefined |
When processAjaxOnInit is set to false , set this option to contain the total number of rows and filtered rows to prevent an initial ajax call (v2.25.4).
|
|
processAjaxOnInit | Boolean | true |
Set this option to false if your table data is preloaded into the table, but you are still using ajax (v2.14.5).
|
|
ajaxProcessing | Function | function (data) { return data; } | This function is required to return the ajax data obtained from your server into a useable format for tablesorter to apply to the table (v2.1, Updated v2.30.8). | Example |
output | String | "{startRow} to {endRow} of {totalRows} rows" | This option allows you to format the output display which can show the current page, total pages, filtered pages, current start and end rows, total rows and filtered rows (v2.0.9; v2.28.4). | 1 2 3 4 |
updateArrows | Boolean | true |
If true , the addon hides the left pager arrow on the first page and right pager arrow on the last page.
|
Example |
page | Numeric | 0 | Set the starting page of the pager (zero-based index). | Example |
pageReset | Numeric, Boolean | 0 |
Reset pager to this page after filtering; set to desired page number (zero-based index), or false to not change page at filter start (v2.16).
|
|
size | Numeric | 10 |
Set initial number of visible rows. This value is changed by the dropdown selector targeted by the cssPageSize option.
|
Example |
savePages | Boolean | true |
Saves the current pager page size and number. This option requires the $.tablesorter.storage script in the jquery.tablesorter.widgets.js file (v2.11).
|
Example |
storageKey | String | "tablesorter-pager" |
Saves tablesorter paging to custom key if defined. Key parameter name used by the $.tablesorter.storage function. Useful if you have multiple tables defined (v2.15)
|
Example |
fixedHeight | Boolean | false | Maintain the height of the table even when fewer than the set number of records is shown (v2.1; updated 2.7.1). | Example |
countChildRows | Boolean | false |
If true , child rows will be counted towards the pager set size (v2.13).
|
|
removeRows | Boolean | false |
If true , rows are removed from the table to speed up the sort of large tables (v2.0.21).
|
Example |
cssFirst | String | ".first" |
This option contains a jQuery selector string pointing to the go to first page arrow. See container for full HTML.
|
Example |
cssPrev | String | ".prev" |
This option contains a jQuery selector string pointing to the go to previous page arrow. See container for full HTML.
|
Example |
cssNext | String | ".next" |
This option contains a jQuery selector string pointing to the go to next page arrow. See container for full HTML.
|
Example |
cssLast | String | ".last" |
This option contains a jQuery selector string pointing to the go to last page arrow. See container for full HTML.
|
Example |
cssGoto | String | ".gotoPage" | This option contains a jQuery selector string pointing to the page select dropdown. See container for full HTML (v2.4; v2.17.3)
|
Example |
cssPageDisplay | String | ".pagedisplay" | This option contains a jQuery selector string pointing to the output element (v2.0.9) | Example |
cssPageSize | String | ".pagesize" |
This option contains a jQuery selector string pointing to the page size selector. See container for full HTML.
|
Example |
cssErrorRow | String | "tablesorter-errorRow" | This option contains the class name that is applied to the error information row that is added inside the pager with any ajax exceptions. | |
cssDisabled | String | "disabled" | This option contains the class name that is applied to disabled pager controls. | |
Removed Options | ||||
filter_anyMatch | Boolean | false | Filter: This option was removed in v2.15... sorry for the sudden notice. | |
uitheme | String | "jui" | UiTheme: This option was removed in v2.19.0! It has been replaced by theme. | Example |
offset | Numeric | 0 | Pager: This option was removed! | |
positionFixed | Boolean | true | Pager: This option was removed! | |
seperator | String | "/" | Pager: This option was removed! Use the output option to allow for more control over the formatting. |
Method | Description | Link |
---|---|---|
addRows | Use this method to add table rows (v2.0.16; v2.23.0). | Example |
resetToLoadState | Use this method reset the table to it's original settings. (v2.17.0). | |
sort | Use this method to initialize a sort while targeting a specific column header (v2.9). | |
sorton | Use this method to sort an initialized table in the desired order (v2.23.0) | Example |
sortReset | Use this method to set the table into an unsorted state (v2.4.7; v2.23.0). | Example |
update / updateRows | Update the tbody 's stored data (update & updateRows do exactly the same thing; v2.23.0)
|
Example |
updateAll | Update a column of cells (thead and tbody ) (v2.8; v2.23.0).
|
Example |
updateCache | Update the parsers, only if not defined, then update the internal cache (v2.15.4; v2.27.0). | Example |
appendCache | Adds all of the cached table rows back into the table (v2.23.0). |
|
updateHeaders | Refresh table headers only (v2.23.0). | |
updateCell | Update a table cell in the tablesorter data (v2.23.0). | Example |
applyWidgetId | Apply 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 (v2.25.4). | Example |
applyWidgets | Apply the set widgets to the table (v2.29.0). | Example |
removeWidget | Remove the named widget from the table (v2.25.0). | Example |
destroy | Use this method to remove tablesorter from the table (v2.3.2; v2.16). | |
refreshWidgets | Refresh 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 (v2.4; v2.19.0). | Example |
Widget Methods | ||
search | filter: Trigger the filter widget to update the search from current inputs and/or selections (v2.4; v2.15). | |
filterReset | filter: Trigger the filter widget to reset the search criteria (v2.7.7). | Example |
filterAndSortReset | filter: Trigger the filter widget to reset the sort & reset the search criteria (v2.28.7). | |
filterResetSaved | filter: Make the filter widget reset any saved searches (v2.25.6). | Example |
saveSortReset | Trigger the saveSort widget to clear any saved sorts for that specific table (v2.7.11). | |
Pager Methods | ||
pageSize | Trigger the pager to change the page size (v2.7.4; v2.24.0). | |
pageSet | Trigger the pager to change the current page (v2.7.7). | |
pageAndSize | Trigger the pager to change the current page & size (v2.19.0; ; v2.24.0). | |
pagerUpdate | Force the pager to update the table with the current settings (v2.19.0). | |
destroyPager | Calling this method will reveal the entire table, remove the pager functionality, and hide the actual pager (v2.0.16; v2.23.0). | Example |
disablePager | This method will put the pager into a disabled state (v2.0.21.2; v2.23.0). | Example |
enablePager | This method will re-enable the pager, but only from the disabled state (v2.0.21.2; v2.23.0). | Example |
Event | Description | Link |
---|---|---|
tablesorter-initialized | This event fires when tablesorter has completed initialization. (v2.2). | |
sortBegin | This event fires immediately before tablesorter begins resorting the table. | |
sortStart | This event fires immediately after the tablesorter header has been clicked, initializing a resort. | Example |
sortEnd | This event fires when tablesorter has completed resorting the table. | Example |
updateComplete | This event fires after tablesorter has completed updating (v2.3.9). | |
tablesorter-ready | This event fires after tablesorter has complete applying all widgets and is ready for its next action (v2.24.0). | |
refreshComplete | This event fires after tablesorter has completed executing the refreshWidget method (v2.19.0) | |
Widget Events | ||
filterInit | Event triggered when the filter widget has finished initializing (v2.4). | Example |
filterStart | Event triggered when the filter widget has started processing the search (v2.4). | Example |
filterEnd | Event triggered when the filter widget has finished processing the search (v2.4). | Example |
stickyHeadersInit | Event triggered when the stickyHeader widget has finished initializing (v2.10.4). | |
widgetRemoveEnd | Event triggered after any widget has finished being removed (v2.29.0). | Example |
Pager Events | ||
pagerChange | This event fires when the pager plugin begins to render the table on the currently selected page. (v2.0.7). | Example |
pagerComplete | This event fires when the pager plugin has completed initialization (v2.18.1), and its render of the table on the currently selected page. (v2.0.7). | Example |
pagerBeforeInitialized | This event fires after all pager controls have been bound and set up but before the pager formats the table or loads any ajax data (v2.4.4). | |
pagerInitialized | This event fires when the pager plugin has completed initialization (v2.4.4). | Example |
pageMoved | This event fires when the pager plugin begins to change to the selected page (v2.4.4). | Example |
Variable | Type | Description | Link |
---|---|---|---|
$.tablesorter.defaults | Object | This object contains all of the default settings shown in the configuration section. | |
$.tablesorter.parsers | Array | This is an array of all parser objects added using the addParser function.
|
|
$.tablesorter.themes | Object | This is an object containing a list of specific class names to be applied to table elements. Please see the widget uitheme option for more details. |
|
$.tablesorter.widgets | Array | This is an array of all widget objects added using the addWidget function.
|
|
$.tablesorter.language | Object | This object contains the phrases (in English by default) added to the aria-label on each header column (v2.24.4).
|
1 2 |
$.tablesorter.instanceMethods | Object | This variable contains all instance methods of the config object. Added using addInstanceMethods function before table initialization (v2.21.0).
|
|
core | Access the table configuration variables (config ) using any of these methods:
|
||
config.cache | Object | Internal list of table contents (v2.0.18; v2.20.0 ) | |
config.columns | Numeric | Internal count of the number of table columns in the header (v2.12) | |
config.headerContent | Array | Internal list of each header's starting HTML (as text) (v2.8) | |
config.headerList | Array | Internal list of each header element as selected using jQuery selectors in the selectorHeaders option.
|
|
config.parsers | Array | Internal list of all of the table's currently set parsers (objects copied from $.tablesorter.parsers ). Here is a complete list of default parsers: (modified v2.18.0)
|
1 2 3 4 |
config.$headerIndexed | Array | Internally stored Array of headers that represent each column (v2.21.0) | |
config.$headers | jQuery Object | Internal list of all table header cells (v2.8) | |
config.table | DOM element | Internally stored DOM table element (v2.17.5) | |
config.$table | jQuery Object | Internally stored jQuery object of the table (v2.7.1) | |
config.sortVars | Object | Internally stored object of column specific sort variables (v2.24.0; Updated v2.30.7) | |
config.$tbodies | jQuery Object | Internally stored jQuery object of table non-info block tbodies (v2.7.1) | |
hasInitialized | Boolean | Boolean value indicating that tablesorter has been initialized on a table | |
config.totalRows | Numeric | This variable contains the total number of rows within the table, not including rows within info-only tbodies (v2.17.4; v2.17.5) | |
widgets | Access the widgetOptions (wo ) using any of these methods:
|
||
wo.filter_$anyMatch | jQuery Object | Only available when the filter widget is active. This variable contains all external search inputs with data-column="all" , bound using the bindSearch function.
|
|
config.$filters | jQuery Object | Only available when the filter widget is active. This variable contains all table cells within the filter row. | |
wo.filter_$externalFilters | jQuery Object | Only available when the filter widget is active. This variable contains all external search inputs bound using the bindSearch function.
|
|
wo.filter_initialized | Boolean | Only available when the filter widget is active. This variable is true once the filter widget has initialized; it is undefined otherwise. |
|
config.filteredRows | Numeric | Only available when the filter widget is active. This variable contains the current number of filtered rows (v2.17.4; v2.17.5) | |
wo.$sticky | jQuery Object | Only available when the stickyHeaders widget (not the css3 version) is active. | |
pager | Access the pager options† (p ) using any of these methods:
|
||
p.$container | jQuery Object | Contains a jQuery object pointing to a pager block(s). | |
p.$goto | jQuery Object | Contains a jQuery object pointing to an empty select within the pager block(s). | |
p.$size | jQuery Object | Contains a jQuery object pointing to a select with the desired page size settings already in place. | |
p.cacheIndex | Array | Contains an array of zero-based row indexes of rows that currently displayed within the table. | |
p.startRow | Numeric | Contains a one-based index of the first row visible in the pager. | |
p.endRow | Numeric | Contains a one-based index of the last row visible in the pager. | |
p.filteredPages | Numeric | Contains the page count, determined by the page size setting, after the table is filtered. It equals the totalPages if no filters are applied.
|
|
p.filteredRows | Numeric | Contains the number of rows accessible by the pager after the table is filtered. It equals the totalRows if no filters are applied.
|
|
p.page | Numeric | Contains a zero-based index of the current page visible in the pager. | |
p.size | Numeric | Contains the currently selected page size. | |
p.totalPages | Numeric | Contains the total page count as determined by the page size setting. | |
p.totalRows | Numeric | Contains the total number of rows within the table | |
Removed Variables | |||
config.$extraHeaders | jQuery Object | Internal list of all extra table header cells (v2.16.2; removed v2.21.3) | |
config.$extraTables | jQuery Object | Internal list of all extra (cloned) table elements (v2.19.0; removed v2.21.3) |
Function | Description |
---|---|
Core Functions | |
fixColumnWidth | This function adds a colgroup element to the table when widthFixed is true .
|
processTbody | This function detaches the targeted tbody from the DOM to allow faster manipulation of the tbody contents (v2.4). |
isProcessing | This function adds the processing (indeterminant loading icon) to specific or all header cells while processing table elements (v2.4). |
clearTableBody | This function empties ALL of the table tbodies (v2.17.2). |
bindEvents | This function adds header event listeners to the targeted cells (v2.8; v2.16.2). |
restoreHeaders | This function restores the table headers cells with their original content (v2.8). |
destroy | This function completely removes tablesorter, including all widgets, associated data & event handlers from the table (v2.3.2). |
sortNatural | This function sorts the a & b parameter using a natural sort (v2.12; v2.28.13). |
sortText | This function sorts the a & b parameter using a basic sort (renamed v2.12). |
replaceAccents | This function replaces basic accented characters to better sorting & filtering of table contents (v2.2). |
isValueInArray | This function returns a zero-based index value of the position of the value within the array, otherwise it returns -1 (Modified v2.15.6). |
addParser | This function allows the adding of custom parser scripts to the tablesorter core. |
addInstanceMethods | This function allows to add custom methods for config object (v2.21.0). |
getParserById | This function returns the named parser object. |
hasWidget | This function allows the checking to see if a widget is installed (v2.17.4). |
addWidget | This function allows the adding of custom widget scripts to the tablesorter core (v2.19.0). |
getWidgetById | This function returns the named widget object. |
applyWidget | This function applys (refreshes) all currently selected widgets on a table (v2.16.0; v2.19.0). |
refreshWidgets | This function removes, then reapplies all currently selected widgets on a table (v2.4; v2.19.0). |
removeWidget | This function removes selected widgets (v2.19.0). |
getColumnData | This function returns the column data from an object based on a column index or classname/id (v2.21.1). |
getColumnText | This utility function returns the entire column text (raw and parsed) as well as other data (v2.21.4; v2.24.0). |
getData | This functions gets the sorter, string, empty, etc options for each column from jQuery data, metadata, header option or header class name ("sorter-false") (v2.1.16). |
formatFloat | This function converts a number string into a number type. |
isDigit | This function determines if a string contains a number after removing commas, periods, quotes and spaces. |
computeColumnIndex | Adds the correct data-column indexing to all rows passed to this function (v2.16; v2.25.0).
|
showError | This function allows adding/removing a row to the thead, to display any errors (v2.15; v2.23.1). |
Widget Functions | |
bindSearch | This filter widget function allows binding external search filters to the table (v2.13.3; v2.15). |
buildSelect | This filter widget function allows the updating or replacing of filter select options from an external source. (v2.17.5): |
getOptions | This filter widget function returns all the cached values of the set table column (v2.16.0): |
getOptionSource | This filter widget function returns all the cached values of the set table column (v2.16.0): |
processOptions | This filter widget function returns an array of sorted column data will duplicates removed (v2.23.4). |
getFilters | This filter widget function allows getting an array of the currently applied filters (v2.9; v2.15) |
setFilters | This filter widget function allows setting of the filters; include a true boolean to actually apply the search (v2.9; v2.24.3):
|
resizableReset | This resizable widget function allows resetting column width changes and clearing out the saved set widths (v2.4; v2.10.1) |
addHeaderResizeEvent | Added a resize event to the table headers - used by the stickyHeaders widget, but this is a public function available to any widget (v2.10).
|
storage | This function allows saving specific table data (especially widgets) to local storage (cookie fallback for no browser support) (v2.1) |
bower install jquery.tablesorter
npm install tablesorter
Theme zip files have been removed. There are now numerous themes available which can be seen here.
tablesorter has been tested successfully in the following browsers with Javascript enabled:
First, please review the FAQ page to see if it will help you resolve the problem.
If you are having a problem with the plugin or you want to submit a feature request, please submit an issue.
Support is also available from stackoverflow.
If you would like to contribute, fork a copy on github.
Some basic unit testing has been added (v2.6). If you would like to add more or report a problem, please use the appropriate link above.
For questions about jQuery, try irc, stackoverflow, or the jQuery forums.
Written by Christian Bach.
Documentation written by Brian Ghidinelli, based on Mike Alsup's great documention.
Additional & Missing documentation, alphanumeric sort, numerous widgets, unit testing and other changes added by Mottie.
Thanks to all that have contributed code, comments, feedback and everything else. A special thanks goes out to: