Original Author: Christian Bach
Maintainer of this fork: Rob Garrison (Mottie)
Version: 2.23.3 (changelog)
Licence:
Dual licensed under MIT
or GPL licenses.
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-adresses 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)selectorSort
; v2.4)sortMultiSortKey
)textSorter
; added v2.2; updated v2.12)sortLocaleCompare
; v2.24; languages)delayInit
)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. | |
checkboxClass | String | "checked" | Used by the "checkbox" parser in the parser-input-select.js file (New v2.22.2).
|
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) | |
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). | |
cssInfoBlock | String | "tablesorter-infoOnly" | All tbodies with this class name will not have its contents sorted. (v2.2). | |
cssNone | String | "" | Additional CSS class applied to style the header when no sort is applied (v2.15). | |
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). | |
cssProcessing | String | "" | Additional CSS class applied to style the header cell while it is being sorted or filtered (v2.4; v2.11). | |
dateFormat | String | "mmddyyyy" | Set the date format. Here are the available options. (Modified v2.0.23). | Example |
debug | Boolean | false | Boolean flag indicating if tablesorter should display debuging information useful for development. | 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). | |
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 ).
|
|
initialized | Function | null | This callback fires when tablesorter has completed initialization. (v2.2). | |
initWidgets | Boolean | true | Apply widgets after table initializes (v2.3.5). | |
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). | |
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 |
pointerClick | String | "click" | Use this option to change the click event (New v2.22.0) | |
pointerDown | String | "mousedown" | Use this option to change the pointer down event (New v2.22.0) | |
pointerUp | String | "mouseup" | Use this option to change the pointer up event (New v2.22.0) | |
resort | Boolean | true | When this option is true any applied sort on the table will be reapplied after an update method (v2.19.0).
|
|
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 |
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 |
sortAppend | Array | null | Use to add an additional forced sort that will be appended to the dynamic selections by the user. | Example |
sortForce | Array | null | Use to add an additional forced sort that is prepended to sortList .
|
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 |
sortList | Array | null | Use to add an initial sort to the table. | Example |
sortLocaleCompare | Boolean | false | Boolean flag indicating if certain accented characters within the table will be replaced with their equivalent characters. (Modified v2.2). | Example |
sortMultiSortKey | String | "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). |
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).
|
|
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). | |
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 |
textSorter | Function | null | Replace the default sorting algorithm with a custom one using this option (v2.12) - *NOTE* The parameters have changed!!. | 1 2 |
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 |
usNumberFormat | Boolean | true | Indicates how tablesorter should deal with a numerical format: (v2.1.3). | Example |
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)
|
|
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 |
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 |
Utility Options | ||||
data | Object, Array | undefined | Storage for processed table build widget data (array, object, string) (v2.11). | Example |
dateRange | Numeric | 50 | Used by the two digit year parser to set the date range (v2.14). | Example |
Deprecated/Removed Options | ||||
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. | ||
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.
|
|
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 |
---|---|---|---|
10 | uitheme | v1.2.6 | |
20 | saveSort | v1.4.1 | 1.4.1 (parseJSON)* |
30 | columns | v1.2.6 | |
40 | resizable | v1.4.1* | 1.4.1 (parseJSON)* |
50 | filter | v1.4.3 | 1.4.3 (nextUntil & delegate) |
55 | pager widget | v1.7 | 1.7 (on) |
60 | stickyHeaders | v1.4.3 | 1.4.3 (isWindow)** |
90 | zebra | v1.2.6 | |
Last | pager plugin | 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_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 |
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 |
filter_cellFilter | String or Array | "" | Filter widget: Additional CSS class applied to each filter cell (v2.18.0). | Example |
filter_childByColumn | Boolean | false |
Filter widget: If true , queries will search child row content by column (New v2.22.0).
|
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_columnFilters | Boolean | true |
Filter widget: If true , a filter will be added to the top of each table column (v2.4).
|
|
filter_cssFilter | String or Array | "" | Filter widget: Additional CSS class applied to each filter (v2.15). | Example |
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 |
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_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 | 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).
|
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, or Number | 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.10).
|
|
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_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.21.5). | Example |
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).
|
|
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_targetLast | Boolean | false |
Resizable widget: When true , the last column will be targeted for resizing (v2.21.3).
|
|
resizable_throttle | Boolean | false | Resizable widget: Set this option to throttle the resizable events (v2.17.4). | |
resizable_widths | Array | [] | Resizable widget: Set this option to the starting & reset header widths (v2.15.12). | Example |
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 |
stickyHeaders | String | "" | Sticky Headers widget: This additional CSS class applied to the sticky header row (v2.11). | Example |
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_attachTo | String | 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_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_filteredToTop | Boolean | true | Sticky Headers widget: Scroll table top into view after filtering (v2.16.2). | |
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_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_xScroll | String | null | Sticky Headers widget: points to the element in which to monitor for horizontal scrolling (v2.18.0). | Example |
stickyHeaders_yScroll | String | null | Sticky Headers widget: points to the element in which to monitor for vertical scrolling (v2.18.0). | Example |
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). | |
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_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_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. | |
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_useSessionStorage | Boolean | false |
Storage widget: If this option is set to false , all saved variables for the table will be within local storage (v2.21.3).
|
Example |
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 | ||||
ajaxError | Function | null |
This callback allows you to customize the error message displayed in the thead (New v2.23.0; Updated v2.23.1).
|
|
ajaxObject | Object | { dataType: 'json' } | This option contains the ajax settings for the pager interaction with your database (v2.10). | Example |
ajaxProcessing | Function | null | 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, v2.17.3). | 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 |
container | Object | null | Target your one or more pager markup blocks by setting this option with a jQuery selector. | Example |
countChildRows | Boolean | false |
If true , child rows will be counted towards the pager set size (v2.13).
|
|
cssDisabled | String | "disabled" | This option contains the class name that is applied to disabled pager controls. | |
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. | |
cssFirst | String | ".first" |
This option contains a jQuery selector string pointing to the go to first 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 |
cssLast | String | ".last" |
This option contains a jQuery selector string pointing to the go to last 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 |
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 |
cssPrev | String | ".prev" |
This option contains a jQuery selector string pointing to the go to previous page arrow. See container for full HTML.
|
Example |
customAjaxUrl | Function | function(table, url) { return url; } | This callback function allows you to modify the processed URL as desired (v2.8.1). | 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 |
output | String | "{page}/{totalPages}" | 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.17.6). | 1 2 3 4 |
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).
|
|
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).
|
|
removeRows | Boolean | false |
If true , rows are removed from the table to speed up the sort of large tables (v2.0.21).
|
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 |
size | Numeric | 10 |
Set initial number of visible rows. This value is changed by the dropdown selector targeted by the cssPageSize option.
|
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 |
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 |
Removed Options | ||||
filter_anyMatch | Boolean | false | Filter: This option was removed in v2.15... sorry for the sudden notice. | |
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. | |
uitheme | String | "jui" | UiTheme: This option was removed in v2.19.0! It has been replaced by theme. | Example |
Method |
Description |
Link |
---|---|---|
addRows | Use this method to add table rows (v2.0.16; Updated v2.23.0). | Example |
appendCache | Adds all of the cached table rows back into the table (Updated v2.23.0). |
|
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. | Example |
applyWidgets | Apply the set widgets to the table (v2.16.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 |
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 (Updated v2.23.0) | Example |
sortReset | Use this method to reset the table to it's initial unsorted state (v2.4.7; Updated v2.23.0). | Example |
update / updateRows | Update the tbody 's stored data (update & updateRows do exactly the same thing; Updated v2.23.0)
|
Example |
updateAll | Update a column of cells (thead and tbody ) (v2.8; Updated v2.23.0).
|
Example |
updateCache | Update the parsers, only if not defined, then update the internal cache (v2.15.4; Updated v2.23.0). | Example |
updateCell | Update a table cell in the tablesorter data (Updated v2.23.0). | Example |
updateHeaders | Refresh table headers only (New v2.23.0). | |
Widget Methods | ||
filterReset | filter: Trigger the filter widget to reset the search criteria (v2.7.7). | Example |
saveSortReset | Trigger the saveSort widget to clear any saved sorts for that specific table (v2.7.11). | |
search | filter: Trigger the filter widget to update the search from current inputs and/or selections (v2.4; v2.15). | |
Pager Methods | ||
destroyPager | Calling this method will reveal the entire table, remove the pager functionality, and hide the actual pager (v2.0.16; Updated v2.23.0). | Example |
disablePager | This method will put the pager into a disabled state (v2.0.21.2; Updated v2.23.0). | Example |
enablePager | This method will re-enable the pager, but only from the disabled state (v2.0.21.2; Updated v2.23.0). | Example |
pageAndSize | Trigger the pager to change the current page & size (v2.19.0). | |
pagerUpdate | Force the pager to update the table with the current settings (v2.19.0). | |
pageSet | Trigger the pager to change the current page (v2.7.7). | |
pageSize | Trigger the pager to change the page size (v2.7.4). |
Event |
Description |
Link |
---|---|---|
refreshComplete | This event fires after tablesorter has completed executing the refreshWidget method (v2.19.0) | |
sortBegin | This event fires immediately before tablesorter begins resorting the table. | |
sortEnd | This event fires when tablesorter has completed resorting the table. | Example |
sortStart | This event fires immediately after the tablesorter header has been clicked, initializing a resort. | Example |
tablesorter-initialized | This event fires when tablesorter has completed initialization. (v2.2). | |
updateComplete | This event fires after tablesorter has completed updating (v2.3.9). | |
Widget Events | ||
filterEnd | Event triggered when the filter widget has finished processing the search (v2.4). | Example |
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 |
stickyHeadersInit | Event triggered when the stickyHeader widget has finished initializing (v2.10.4). | |
Pager Events | ||
pageMoved | This event fires when the pager plugin begins to change to the selected page (v2.4.4). | 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). | |
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 |
pagerInitialized | This event fires when the pager plugin has completed initialization (v2.4.4). | Example |
Variable |
Type |
Description |
Link |
---|---|---|---|
$.tablesorter.instanceMethods | Object | This variable contains all instance methods of the config object. Added using addInstanceMethods function before table initialization (v2.21.0).
|
|
$.tablesorter.language | Object | This object contains the phrases (in English by default) added to the aria-label on each header column. |
|
$.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.
|
|
core | Access the table configuration variables (config ) using any of these methods:
|
||
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 | jQuery Object | Internally stored jQuery object of the table (v2.7.1) | |
config.$tbodies | jQuery Object | Internally stored jQuery object of table non-info block tbodies (v2.7.1) | |
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:
|
1 2 3 |
config.table | DOM element | Internally stored DOM table element (v2.17.5) | |
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) | |
hasInitialized | Boolean | Boolean value indicating that tablesorter has been initialized on a table | |
widgets | Access the widgetOptions (wo ) using any of these methods:
|
||
config.$filters | jQuery Object | Only available when the filter widget is active. This variable contains all table cells within the filter row. | |
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. | |
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.
|
|
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. |
|
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.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 one-based index of the current page visible in the pager. | |
p.size | Numeric | Contains the currently selected page size. | |
p.startRow | Numeric | Contains a one-based index of the first row visible in the pager. | |
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 | |
addInstanceMethods | This function allows to add custom methods for config object (v2.21.0). |
addParser | This function allows the adding of custom parser scripts to the tablesorter core. |
addWidget | This function allows the adding of custom widget scripts to the tablesorter core (v2.19.0). |
applyWidget | This function applys (refreshes) all currently selected widgets on a table (v2.16.0; v2.19.0). |
bindEvents | This function adds header event listeners to the targeted cells (v2.8; v2.16.2). |
clearTableBody | This function empties ALL of the table tbodies (v2.17.2). |
computeColumnIndex | Adds the correct data-column indexing to all rows passed to this function (v2.16).
|
destroy | This function completely removes tablesorter, including all widgets, associated data & event handlers from the table (v2.3.2). |
fixColumnWidth | This function adds a colgroup element to the table when widthFixed is true .
|
formatFloat | This function converts a number string into a number type. |
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). |
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). |
getParserById | This function returns the named parser object. |
getWidgetById | This function returns the named widget object. |
hasWidget | This function allows the checking to see if a widget is installed (v2.17.4). |
isDigit | This function determines if a string contains a number after removing commas, periods, quotes and spaces. |
isProcessing | This function adds the processing (indeterminant loading icon) to specific or all header cells while processing table elements (v2.4). |
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). |
processTbody | This function detaches the targeted tbody from the DOM to allow faster manipulation of the tbody contents (v2.4). |
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). |
replaceAccents | This function replaces basic accented characters to better sorting & filtering of table contents (v2.2). |
restoreHeaders | This function restores the table headers cells with their original content (v2.8). |
showError | This function allows adding/removing a row to the thead, to display any errors (v2.15; Updated v2.23.1). |
sortNatural | This function sorts the a & b parameter using a natural sort (v2.12). |
sortText | This function sorts the a & b parameter using a basic sort (renamed v2.12). |
Widget Functions | |
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).
|
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): |
getFilters | This filter widget function allows getting an array of the currently applied filters (v2.9; v2.15) |
resizableReset | This resizable widget function allows resetting column width changes and clearing out the saved set widths (v2.4; v2.10.1) |
setFilters | This filter widget function allows setting of the filters; include a true boolean to actually apply the search (v2.9; v2.16):
|
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:
John Resig for the fantastic jQuery