tablesorter is a <aclass="external"href="http://jquery.com">jQuery</a> 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:
</p>
<ul>
<li>Multi-column sorting</li>
<li>Multi-tbody sorting - see the <ahref="#options">options</a> table below</li>
<li>Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. <ahref="example-parsers.html">Add your own easily</a></li>
<li>Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)</li>
<li>Extensibility via <ahref="example-widgets.html">widget system</a></li>
<li>Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+</li>
<li>Small code size</li>
</ul>
<aid="Demo"></a>
<h1>Demo</h1>
<tableid="tablesorter-demo"class="tablesorter">
<thead>
<tr>
<th>Account #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Total</th>
<th>Discount</th>
<th>Difference</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>A42b</td>
<td>Peter</td>
<td>Parker</td>
<td>28</td>
<td>$9.99</td>
<td>20.9%</td>
<td>+12.1</td>
<td>Jul 6, 2006 8:14 AM</td>
</tr>
<tr>
<td>A255</td>
<td>John</td>
<td>Hood</td>
<td>33</td>
<td>$19.99</td>
<td>25%</td>
<td>+12</td>
<td>Dec 10, 2002 5:14 AM</td>
</tr>
<tr>
<td>A33</td>
<td>Clark</td>
<td>Kent</td>
<td>18</td>
<td>$15.89</td>
<td>44%</td>
<td>-26</td>
<td>Jan 12, 2003 11:14 AM</td>
</tr>
<tr>
<td>A1</td>
<td>Bruce</td>
<td>Almighty</td>
<td>45</td>
<td>$153.19</td>
<td>44.7%</td>
<td>+77</td>
<td>Jan 18, 2001 9:12 AM</td>
</tr>
<tr>
<td>A102</td>
<td>Bruce</td>
<td>Evans</td>
<td>22</td>
<td>$13.19</td>
<td>11%</td>
<td>-100.9</td>
<td>Jan 18, 2007 9:12 AM</td>
</tr>
<tr>
<td>A42a</td>
<td>Bruce</td>
<td>Evans</td>
<td>22</td>
<td>$13.19</td>
<td>11%</td>
<td>0</td>
<td>Jan 18, 2007 9:12 AM</td>
</tr>
</tbody>
</table>
<pclass="tip">
<em>TIP!</em> Sort multiple columns simultaneously by holding down the shift key and clicking a second, third or even fourth column header!
</p>
<aid="Getting-Started"></a>
<h1>Getting started</h1>
<p>
To use the tablesorter plugin, include the <aclass="external"href="http://jquery.com">jQuery</a>
library and the tablesorter plugin inside the <code><head></code> tag
of your HTML document:
</p>
<preclass="html"><!-- choose a theme file -->
<em>NOTE!</em> tablesorter will auto-detect most data types including numbers, dates, ip-adresses for more information see <ahref="#Examples">Examples</a>
</p>
<aid="Examples"></a>
<h1>Examples</h1>
<p>
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.
</p>
<divclass="box">
<h3>Basic</h3>
<h4>Sorting</h4>
<ul>
<li><ahref="example-option-sort-list.html">Set an initial sorting order using options</a></li>
<li><ahref="example-trigger-sort.html">Sort table using a link outside the table</a></li>
<li><ahref="example-option-sort-force.html">Force a default sorting order</a></li>
<li><ahref="example-option-sort-append.html">Append a sort to the selected sorting order</a></li>
<li><ahref="example-child-rows.html">Child rows; how to add rows that sort with their parent row</a></li>
<li><ahref="example-child-rows-filtered.html">Child rows + filter widget; how they work together</a></li>
<li><ahref="example-option-sort-order.html">Direction of initial sort</a></li>
<li>*Note* you can use class names (version 2.0.11+, <ahref="example-parsers-class-name.html">demo</a>), or jQuery data (version 2.3+, <ahref="example-parsers-jquery-data.html">demo</a>) instead of meta data</li>
<li><ahref="example-meta-sort-list.html">Set a initial sorting order using metadata.</a></li>
<li><ahref="example-meta-headers.html">Disable header using metadata</a></li>
<li><ahref="example-meta-parsers.html">Setting column parser using metadata</a></li>
</ul>
</div>
<brclass="clear">
<aid="Configuration"></a>
<h1>Configuration</h1>
<divclass="tip">
<p></p>
tablesorter has many options you can pass in at initialization to achieve different effects<br>
<em>TIP!</em> Click on the link in the property column to reveal full details (or <ahref="#"class="toggleAll">toggle</a>|<ahref="#"class="showAll">show</a>|<ahref="#"class="hideAll">hide</a> all) or double click to update the browser location.
<td>Indicates if tablesorter should disable selection of text in the table header (TH). Makes header behave more like a button.</td>
<td></td>
</tr>
<trid="cssasc">
<td><ahref="#"class="toggle2">cssAsc</a></td>
<td>String</td>
<td>"tablesorter-headerSortUp"</td>
<td>The CSS style used to style the header when sorting ascending. Example from the blue skin:
<divclass="collapsible">
<preclass="css">th.tablesorter-headerSortUp {
background-color: #8dbdd8;
background-image: url(black-asc.gif);
}</pre></div>
</td>
<td></td>
</tr>
<trid="csschildrow">
<td><aclass="toggle"href="#">cssChildRow</a></td>
<td>String</td>
<td>"tablesorter-childRow"</td>
<td>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", <spanclass="tip"><em>Changed!</em></span> in v2.4.</td>
<td>The CSS style used to style the header row. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
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.
</div>
</td>
<td></td>
</tr>
<trid="cssicon">
<td><ahref="#"class="toggle2">cssIcon</a></td>
<td>String</td>
<td>"tablesorter-icon"</td>
<td>The CSS style used to style the header cell icon. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
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 <code>cssicon</code> option to an empty string.
<td>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 <ahref="#showprocessing"><code>showProcessing</code></a> option to <code>false</code>. <spanclass="tip"><em>New!</em></span> v2.4.</td>
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.
<br>
<pclass="tip">
<em>NOTE!</em> 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.
</p>
</div>
</td>
<td></td>
</tr>
<trid="dateformat">
<td><ahref="#"class="toggle2">dateFormat</a></td>
<td>String</td>
<td>"mmddyyyy"</td>
<td>Set the date format. Here are the available options. (Modified v2.0.23).
<divclass="collapsible">
<ul>
<li><code>"mmddyyyy"</code> (default)</li>
<li><code>"ddmmyyyy"</code></li>
<li><code>"yyyymmdd"</code></li>
</ul>
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!<br>
<br>
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 <ahref="example-option-date-format.html">the demo page</a> to see it working.
<preclass="js">$(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
}
});
});</pre>
Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1):
<ul>
<li>jQuery data <code>data-dateFormat="mmddyyyy"</code>.</li>
<li>metadata <code>class="{ dateFormat: 'mmddyyyy'}"</code>. This requires the metadata plugin.</li>
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.
<td>Internal list of each header element as selected using jQuery selectors in the <ahref="#selectorheaders"><code>selectorHeaders</code></a> option. Not really useful for normal usage.</td>
<td></td>
</tr>
<trid="headers">
<td><ahref="#"class="toggle2">headers</a></td>
<td>Object</td>
<td>null</td>
<td>
An object of instructions for per-column controls in the format: <code>headers: { 0: { option: setting }, ... }</code>
<divclass="collapsible">
<br>
For example, to disable sorting on the first two columns of a table: <code>headers: { 0: { sorter: false}, 1: {sorter: false} }</code>.<br>
<br>
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 <ahref="#parsers">default parsers</a> here or <ahref="example-parsers.html">write your own</a>.
<preclass="js">$(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
<td>Apply widgets after table initializes (v2.3.5).
<divclass="collapsible">
When true, all widgets set by the <code>widgets</code> option will apply after tablesorter has initialized, this is the normal behavior.<br>
<br>
If false, the each widget set by the <code>widgets</code> 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.<br>
<br>
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.
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.
<divclass="collapsible">
<br>
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 (<ahref="http://www.pengoworks.com/workshop/jquery/tablesorter/tablesorter.htm">source</a>).
<preclass="js">$(function(){
$("table").tablesorter({
onRenderHeader: function (){
$(this).find('div').addClass('roundedCorners');
}
});
});</pre>and you'll end up with this HTML (only the thead is shown)<preclass="html"><thead>
<tr><th><code>sorter: "currency"</code></th><td>Sort by currency value (supports "£$€¤¥¢").</td></tr>
<tr><th><code>sorter: "ipAddress"</code></th><td>Sort by IP Address.</td></tr>
<tr><th><code>sorter: "url"</code></th><td>Sort by url.</td></tr>
<tr><th><code>sorter: "isoDate"</code></th><td>Sort by ISO date (YYYY-MM-DD or YYYY/MM/DD).</td></tr>
<tr><th><code>sorter: "percent"</code></th><td>Sort by percent.</td></tr>
<tr><th><code>sorter: "usLongDate"</code></th><td>Sort by date (U.S. Standard, e.g. Jan 18, 2001 9:12 AM).</td></tr>
<tr><th><code>sorter: "shortDate"</code></th><td>Sort by a shorten date (see <ahref="#dateformat"><code>dateFormat</code></a>).</td></tr>
<tr><th><code>sorter: "time"</code></th><td>Sort by time (23:59 or 12:59 pm).</td></tr>
<tr><th><code>sorter: "metadata"</code></th><td>Sort by the sorter value in the metadata - requires the metadata plugin.</td></tr>
</tbody></table><br>
Check out the <ahref="#headers"><code>headers</code></a> option to see how to use these parsers in your table (example #1).<br>Or add a header class name using "sorter-" plus the parser name (example #2), this includes custom parsers (example #3).
<td>jQuery selectors used to find cells in the header.
<divclass="collapsible">
You can change this, but the table will still need the required thead and tbody before this plugin will work properly.
<br>Added <code>></code> to the selector in v2.3 to prevent targetting nested table headers. It was modified again in v2.4 to include <code>td</code> cells within the thead. <spanclass="tip"><em>Modified!</em></span> v2.4.
<td>This CSS class name can be applied to all rows that are to be removed prior to triggering a table update. (v2.1).
<divclass="collapsible">
<br>
It was necessary to add this option because some widgets add table rows for styling (see the <ahref="example-widgets.html">writing custom widgets demo</a>) and if a table update is triggered (<code>$('table').trigger('update');</code>) those added rows will automatically become incorporated into the table.
<td>jQuery selector of content within <ahref="#selectorheaders"><code>selectorHeaders</code></a> that is clickable to trigger a sort. <spanclass="tip"><em>New!</em></span> v2.4.</td>
<td>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. <spanclass="tip"><em>New!</em></span> v2.4.</td>
<td>Use to add an additional forced sort that is <strong>prepended</strong> to <ahref="#sortlist"><code>sortList</code></a>.
<divclass="collapsible">
<br>
For example, <code>sortForce: [[0,0]]</code> 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 <ahref="#sortappend"><code>sortAppend</code></a> option will be applied. More explicitly:<br>
<br>
There are three options to determine the sort order and this is the order of priority:
<ol>
<li><ahref="#sortforce"><code>sortForce</code></a> forces the user to have this/these column(s) sorted first (null by default).</li>
<li><ahref="#sortlist"><code>SortList</code></a> is the initial sort order of the columns.</li>
<li><ahref="#sortappend"><code>SortAppend</code></a> is the default sort that is added to the end of the users sort selection (null by default).</li>
</ol>
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: <code>[[columnIndex, sortDirection], ... ]</code> where <code>columnIndex</code> is a zero-based index for your columns left-to-right and <code>sortDirection</code> is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: <code>[[0,0],[1,0]]</code>.
<preclass="js">$(function(){
$("table").tablesorter({
sortForce : [[0,0]], // Always sort first column first
The value contains an array of instructions for per-column sorting and direction in the format: <code>[[columnIndex, sortDirection], ... ]</code> 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: <code>[[0,0],[1,0]]</code>. Please see <ahref="#sortforce"><code>sortForce</code></a> for more details on other sort order options.<br>
<br>
This option can also be set using jQuery data (v2.3.1) or metadata on the table:
<td>Use to add an additional forced sort that will be appended to the dynamic selections by the user.
<divclass="collapsible">
<br>
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.<br>
<br>
The value contains an array of instructions for per-column sorting and direction in the format: <code>[[columnIndex, sortDirection], ... ]</code> where <code>columnIndex</code> 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: <code>[[0,0],[1,0]]</code>. Please see <ahref="#sortforce"><code>sortForce</code></a> for more details on other sort order options.
The direction a column sorts when clicking the header for the first time. Valid arguments are <code>"asc"</code> for Ascending or <code>"desc"</code> for Descending.<br>
<divclass="collapsible">
<br>
This order can also be set by desired column using the <ahref="#headers"><code>headers</code></a> option (Added in v2.0.8).<br>
<br>
Individual columns can be modified by adding the following (they all do the same thing), set in order of priority (Modified v2.3.1):
<ul>
<li>jQuery data <code>data-sortInitialOrder="asc"</code>.</li>
<li>metadata <code>class="{ sortInitialOrder: 'asc'}"</code>. This requires the metadata plugin.</li>
Boolean flag indicating if certain accented characters within the table will be replaced with their equivalent characters. (Modified v2.2).
<divclass="collapsible">
<ul>
<li>This option no longer switches the sort to use the <code>String.localeCompare</code> method.</li>
<li>When this option is <code>true</code>, the text parsed from table cells will convert accented characters to their equivalent to allow the alphanumeric sort to properly sort.</li>
<li>If <code>false</code> (default), any accented characters are treated as their value in the standard unicode order.</li>
<li>The following characters are replaced for both upper and lower case (information obtained from <ahref="http://sugarjs.com/sorting">sugar.js sorting equivalents</a> table):
<ul>
<li><code>áàâãä</code> replaced with <code>a</code></li>
<li><code>ç</code> replaced with <code>c</code></li>
<li><code>éèêë</code> replaced with <code>e</code></li>
<li><code>íìİîï</code> replaced with <code>i</code></li>
<li><code>óòôõö</code> replaced with <code>o</code></li>
<li><code>úùûü</code> replaced with <code>u</code></li>
<li><code>ß</code> replaced with <code>S</code></li>
</ul>
</li>
<li>Please see the example page for instrcutions on how to modify the above equivalency table.</li>
<li>If you would like to continuing using the <code>String.localeCompare</code> method, then set the <code>sortLocaleCompare</code> option to <code>false</code> and use the new <ahref="#textsorter"><code>textSorter</code></a> option as follows:
<preclass="js">$('table').tablesorter({
textSorter: function(a,b) {
return a.localeCompare(b);
}
});</pre></li>
</ul>
<pclass="tip">
<em>NOTE:</em> See the <ahref="https://github.com/Mottie/tablesorter/wiki/Language">Language</a> wiki page for language specific examples and how to extend the character equivalent tables seen in the <ahref="example-locale-sort.html">sortLocaleCompare demo</a>.
</p>
<del>Boolean flag indicating whenever to use javascript <code>String.localeCompare</code> method or not.<br>
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.</del>
Setting this option to <code>true</code> will start the sort with the <ahref="#sortinitialorder"><code>sortInitialOrder</code></a> when clicking on a previously unsorted column. (v2.0.31).
<td>The key used to select more than one column for multi-column sorting. Defaults to the shift key. The other options are <code>"ctrlKey"</code> or <code>"altKey"</code>. Reference: <aclass="external"href="https://developer.mozilla.org/en/DOM/MouseEvent">https://developer.mozilla.org/en/DOM/MouseEvent</a></td>
<td>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.
<divclass="collapsible">
<br>Change this option if you are not using the default css, or if you are using a completely custom stylesheet.
</div>
</td>
<td></td>
</tr>
<trid="theme">
<td><ahref="#"class="toggle2">theme</a></td>
<td>String</td>
<td>"default"</td>
<td>This option will add a theme css class name to the table <code>"tablesorter-{theme}"</code> for styling. <spanclass="tip"><em>New</em></span> v2.4.
<divclass="collapsible">
<br>When changing this theme option, make sure that the appropriate css theme file has also been loaded. Included theme files include:
<ahref="themes.html"target="_blank"title="open themes in a new window">see all themes</a><br>
<td>Defines which method is used to extract data from a table cell for sorting.
The built-in option is <code>"simple"</code> which is the equivalent of doing this inside of the textExtraction function: <code>$(node).text();</code>.
<divclass="collapsible">
<br>
You can customize the text extraction by writing your own text extraction function "myTextExtraction" which you define like:
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).
<p>Now if the text you are finding in the script above is say a number, then just include the <ahref="#headers"><code>headers</code></a> 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.</p>
<p>Added <code>table</code> and <code>cellIndex</code> variables to the <code>textExtraction</code> function in version 2.1.2.</p>
Initialize widgets using this option ( e.g. <code>widgets : ['zebra']</code>, or custom widgets <code>widgets: ['zebra', 'myCustomWidget'];</code>, see <ahref="example-widgets.html">this demo</a> on how to write your own custom widget ).
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).
<divclass="collapsible">
<br>
Previously documented widget options <ahref="#widgetzebra"><code>widgetZebra</code></a>, <ahref="#widgetcolumns"><code>widgetColumns</code></a> and <ahref="#widgetuitheme"><code>widgetUitheme</code></a> will be retained for backwards compatibility.<br>
<br>
Use the <ahref="#widgetoptions"><code>widgetOptions</code></a> option as follows, please note that each option is followed by a comma (except the last one):
This option is being <spanclass="deprecated">deprecated</span>!
It has been replaced by <ahref="#widget-columns"><code>widgetOptions.columns</code></a>; but is still available for backwards compatibility.
<divclass="collapsible">
<br>
When the column styling widget is initialized, it automatically applied the default class names of <code>"primary"</code> for the primary sort, <code>"secondary"</code> for the next sort, <code>"tertiary"</code> for the next sort, and so on (add more as needed)... (v2.0.17).
Use the <ahref="#widgetcolumns"><code>widgetColumns</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["columns"], // initialize column styling of the table
This option is being <spanclass="deprecated">deprecated</span>!
It has been replaced by <ahref="#widget-uitheme"><code>widgetOptions.uitheme</code></a>; but is still available for backwards compatibility.
<divclass="collapsible">
<br>
Used when the ui theme styling widget is initialized. It automatically applies the default class names of <code>"ui-icon-arrowthick-2-n-s"</code> for the unsorted column, <code>"ui-icon-arrowthick-1-s"</code> for the descending sort and <code>"ui-icon-arrowthick-1-n"</code> for the ascending sort. (v2.0.9).
Find more jQuery UI class names by hovering over the Framework icons on this page: <aclass="external"href="http://jqueryui.com/themeroller/">http://jqueryui.com/themeroller/</a><br>
<br>
Use the <ahref="#widgetuitheme"><code>widgetUitheme</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["uitheme"], // initialize ui theme styling widget of the table
tablesorter widgets have many options, and to better organize them, they now are grouped together inside of the <code>widgetOptions</code>. Thanks to thezoggy for putting together this jQuery-widget compatibility table, but please note:
<ul>
<li>The applied order will not change depending on the widgets applied, but the numbers will change.</li>
<li>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.</li>
<li>The pager, being a plugin, is actually initialized after tablesorter has initialized and all selected widgets applied.</li>
<li>* The <code>saveSort</code> and <code>resizable</code> widgets use the <code>$.tablesorter.storage</code> function by default and thus need the <code>ParseJSON</code> function which is available in jQuery 1.4.1+.</li>
</ul>
<brclass="clear">
<em>TIP!</em> Click on the link in the property column to reveal full details (or <ahref="#"class="toggleAll">toggle</a>|<ahref="#"class="showAll">show</a>|<ahref="#"class="hideAll">hide</a> all) or double click to update the browser location.
Columns widget: When the column styling widget is initialized, it automatically applied the default class names of <code>"primary"</code> for the primary sort, <code>"secondary"</code> for the next sort, <code>"tertiary"</code> for the next sort, and so on (add more as needed)... (Modified v2.1).
<divclass="collapsible">
<br>
Use the <ahref="#widget-columns"><code>"columns"</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["columns"], // initialize column styling of the table
Columns widget: If true, the class names from the <code>columns</code> option will also be added to the table thead. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-columns-thead"><code>"columns_thead"</code></a> option to add the column class names to the thead as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["columns"], // initialize column styling of the table
Columns widget: If true, the class names from the <code>columns</code> option will also be added to the table tfoot. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-columns-tfoot"><code>"columns_tfoot"</code></a> option to add the column class names to the tfoot as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["columns"], // initialize column styling of the table
Filter widget: If there are child rows in the table (rows with class name from <ahref="#csschildrow"><code>"cssChildRow"</code></a> option) and this option is <code>true</code> and a match is found anywhere in the child row, then it will make that row visible.
(Modified v2.1).
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-childrows"><code>filter_childRows</code></a> option include child row text as follows:
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 <code>"tablesorter-filter"</code> make sure you also update the css! (v2.1).
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-cssfilter"><code>"tablesorter-filter"</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["filter"],
widgetOptions : {
// css class applied to the table row containing the filters & the inputs within that row
Filter widget: Customize the filter widget by adding a select dropdown with content, custom options or custom filter functions (v2.3.6).
<divclass="collapsible">
Use the <ahref="#widget-filter-functions"><code>"filter_functions"</code></a> option in three different ways:
<br>
<ul>
<li>
Make a sorted select dropdown list of all column contents. Repeated content will be combined.
<preclass="js">$(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
}
}
});
});</pre>
Alternately, instead of setting the column filter funtion to true, give the column header a class name of "filter-select". See the <ahref="example-widget-filter-custom.html">demo</a>.<br><br>
</li>
<li>
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.
<h4>Regex example</h4>
<preclass="js">$(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); },
Filter widget: Set this option to <code>true</code> to hide the filter row initially. The rows is revealed by hovering over the filter row or giving any filter input/select focus. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-hidefilters"><code>filter_hideFilters</code></a> option as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["filter"],
widgetOptions : {
filter_hideFilters : true
}
});
});</pre>You can change the style (thickness) of the hidden filter row in the tablesorter theme css. Look for <code>.tablesorter-filter-row</code> (revealed row) and <code>.tablesorter-filter-row.hideme</code> (for the hidden row) css definitions.</div>
Filter widget: Set this option to <code>false</code> to make the column content search case-insensitive, so typing in "a" will not find "Albert". (v2.3.4)
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-ignorecase"><code>filter_ignorecase</code></a> option as follows:
This option is only available when using the advanced filter ("filter") contained in the <code>jquery.tablesorter.widgets.js</code> file. <spanclass="tip"><em>New! v2.4</em></span><br>
<divclass="collapsible"><br>
To use it, point to the quick search input by adding the selector string to this option. For example, add this input (<code><input type="search"></code>) to the table header, or anywhere else on the page. That input will be used as a quick search filter for all table data when the input is targetted as follows:
<br>
Use the <ahref="#widget-filter-quickSearch"><code>filter_quickSearch</code></a> option as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["filter"],
widgetOptions : {
filter_quickSearch : '.quicksearch'
}
});
});</pre>
The quicksearch input:
<ul>
<li>applies to all columns and works with "AND" and "OR" operators (i.e. look for "!female AND >40"). See the updated <ahref="http://mottie.github.com/tablesorter/docs/example-widget-filter-custom.html">custom filter widget demo</a>.</li>
<li>To exclude a specific column from the quick search, use any of the following settings, in order of priority:
<ul>
<li>jQuery data <code>data-filter="noquicksearch"</code>.</li>
<li>metadata <code>class="{ filter: 'noquicksearch'}"</code>. This requires the metadata plugin.</li>
Filter widget: jQuery selector string of an element used to reset the filters. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<p>
To use this option, point to a reset button or link using a jQuery selector. For example, add this button (<code><button class="reset">Reset</button></code>) 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):
</p>
Use the <ahref="#widget-filter-reset"><code>filter_reset</code></a> option as follows:
Filter widget: Set this option to <code>true</code> 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).
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-startswith"><code>filter_startsWith</code></a> option as follows:
Filter widget: If <code>true</code>, ALL filter searches will only use parsed data. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-filter-useParsedData"><code>filter_useParsedData</code></a> option as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["filter"],
widgetOptions : {
filter_useParsedData : false
}
});
});</pre>
<ul>
<li>To only use parsed data in specific columns, set this option to <code>false</code> and use any of the following (they all do the same thing), set in order of priority:
<ul>
<li>jQuery data <code>data-filter="parsed"</code>.</li>
<li>metadata <code>class="{ filter: 'parsed'}"</code>. This requires the metadata plugin.</li>
<li>header class name <code>class="filter-parsed"</code>.</li>
</ul>
</li>
<li>Remember that parsed data most likely doesn't match the actual table cell text, <code>20%</code> becomes <code>20</code> and <code>Jan 1, 2013 12:01 AM</code> becomes <code>1357020060000</code>.</li>
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 <code>"tablesorter-stickyHeader"</code> make sure you also update the css! (v2.1).
<divclass="collapsible">
<br>
Use the <ahref="#widget-sticky-headers"><code>"stickyHeaders"</code></a> option to change the css class name as follows:
Resizable widget: If this option is set to <code>false</code>, resized column widths will not be saved. Previous saved values will be restored on page reload. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-resizable"><code>"resizable"</code></a> option to change the css class name as follows:
saveSort widget: If this option is set to <code>false</code>, new sorts will not be saved. Any previous saved sort will be restored on page reload. <spanclass="tip"><em>New!</em></span> v2.4.
<divclass="collapsible">
<br>
Use the <ahref="#widget-savesort"><code>"saveSort"</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["saveSort"],
widgetOptions : {
// if false, the sort will not be saved for next page reload
** <spanclass="tip"><em>Updated! in tablesorter v2.4</em></span> **<br>
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
<divclass="collapsible">
<p></p>
<preclass="js">// 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)
This widget option replaces the previous <ahref="#widgetuitheme">widgetUitheme</a>. All theme css names are now contained within the <code>$.tablesorter.themes</code> variable. Extend the default theme as seen above.<br>
<br>
The class names from the <code>$.tablesorter.themes.{name}</code> variable are applied to the table as indicated.<br>
<br>
As before the jQuery UI theme applies the default class names of <code>"ui-icon-arrowthick-2-n-s"</code> for the unsorted column, <code>"ui-icon-arrowthick-1-s"</code> for the descending sort and <code>"ui-icon-arrowthick-1-n"</code> 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: <aclass="external"href="http://jqueryui.com/themeroller/">http://jqueryui.com/themeroller/</a><br>
<br>
Use the <ahref="#widget-uitheme"><code>"uitheme"</code></a> option to change the css class name as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["uitheme"], // initialize ui theme styling widget of the table
widgetOptions: {
uitheme : "jui"
}
});
});</pre>
To add a new theme, define it as follows; replace "custom" with the name of your theme:
<preclass="js">$.tablesorter.themes.custom = {
table : 'table', // table classes
header : 'header', // header classes
icons : 'icon', // icon class added to the <i> in the header
zebra widget: When the zebra striping widget is initialized, it automatically applied the default class names of <code>"even"</code> and <code>"odd"</code>. (Modified v2.1).
<divclass="collapsible">
<br>
Use the <ahref="#widget-zebra"><code>"zebra"</code></a> option to change the theme as follows:
<preclass="js">$(function(){
$("table").tablesorter({
widgets: ["zebra"], // initialize zebra striping of the table
tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized.
<br>
<em>TIP!</em> Click on the link in the method column to reveal full details (or <ahref="#"class="toggleAll">toggle</a>|<ahref="#"class="showAll">show</a>|<ahref="#"class="hideAll">hide</a> all) or double click to update the browser location.
</div>
<tableid="methods"class="tablesorter">
<thead>
<tr>
<th>Method</th>
<th>Description</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<trid="addrows">
<td><ahref="#"class="toggle2">addRows</a></td>
<td>Use this method to add table rows. (v2.0.16).
<divclass="collapsible">
It does not work the same as "update" in that it only adds rows, it does not remove them.<br>
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.
<preclass="js">// Add multiple rows to the table
var row = '<tr><td>Inigo</td><td>Montoya</td><td>34</td>' +
<td>Update a table that has had its data dynamically changed; used in conjunction with "update".<br>
<divclass="collapsible">
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".<br>
<br>
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.
<preclass="js">// Table data was just dynamically changed (more than one cell)
<td>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.
<td>Apply 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.
<divclass="collapsible">
<preclass="js">// 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
<td>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. <spanclass="tip"><em>New</em></span> v2.4.
<divclass="collapsible"><br>
Trigger this method using either of the following methods (they are equivalent):
<li>If <code>doAll</code> is <code>true</code> it removes all widgets from the table. If <code>false</code> only non-current widgets (from the <code>widgets</code> option) are removed.</li>
<li>When done removing widgets, the widget re-initializes the currently selected widgets, unless the <code>dontapply</code> parameter is <code>true</code> leaving the table widget-less.</li>
<li>Note that if the <code>widgets</code> 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 <code>$('table')[0].config.widgets = [];</code></li>
tablesorter has some methods available to allow updating, resorting or applying widgets to a table after it has been initialized.
<br>
<em>TIP!</em> Click on the link in the event column to reveal full details (or <ahref="#"class="toggleAll">toggle</a>|<ahref="#"class="showAll">show</a>|<ahref="#"class="hideAll">hide</a> all) or double click to update the browser location.
<td>This event fires when the pager plugin has completed initialization. <spanclass="tip"><em>New</em></span> v2.4.4.
<divclass="collapsible">
<preclass="js">$(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")
});
});</pre></div>
</td>
<td><ahref="example-pager.html">Example</a></td>
</tr>
<trid="pagemoved">
<td><ahref="#"class="toggle2">pageMoved</a></td>
<td>This event fires when the pager plugin begins to change to the selected page. <spanclass="tip"><em>New</em></span> v2.4.4.
<divclass="collapsible">
This event may fire before the <code>pagerComplete</code> event when ajax processing is involved, or after the <code>pagerComplete</code> on normal use.
See <ahref="https://github.com/Mottie/tablesorter/pull/153">issue #153</a>.
<preclass="js">$(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) );
});
});</pre></div>
</td>
<td><ahref="example-pager.html">Example</a></td>
</tr>
</tbody>
<!-- non-sorting tbody -->
<tbodyclass="tablesorter-infoOnly">
<tr><thcolspan="5">Widget Events</th></tr>
</tbody>
<!-- widget events -->
<tbody>
<trid="filterinit">
<td><ahref="#"class="toggle2">filterInit</a></td>
<td>Event triggered when the filter widget has finished initializing. <spanclass="tip"><em>New</em></span> v2.4.
<divclass="collapsible">
You can use this event to modify the filter elements (row, inputs and/or selects) as desired. Use it as follows:<preclass="js">$(function(){
<td>Event triggered when the filter widget has finished processing the search. <spanclass="tip"><em>New</em></span> v2.4.
<divclass="collapsible">
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:<preclass="js">$(function(){
<p><strong>Pick n choose</strong> - Place at least the required files in a directory on your webserver that is accessible to a web browser. Record this location.</p>
<strongid="Download-Required">Required:</strong>
<ul>
<li><aclass="external"href="http://docs.jquery.com/Downloading_jQuery#Download_jQuery">jQuery</a> (1.2.6 or higher; some demos &<ahref="http://api.jquery.com/data/#data-html5">HTML5 data-attributes</a> need jQuery 1.4.3+)</li>
<li><ahref="../js/jquery.tablesorter.min.js">jquery.tablesorter.min.js</a> (19kb, minified for production - please put the file on your server)</li>
<li><ahref="../js/jquery.tablesorter.widgets.js">jquery.tablesorter.widgets.js</a> (36kb/<ahref="../js/jquery.tablesorter.widgets.min.js">17kb min</a>, includes the jQuery UI theme, columns styling, resizable columns, filter, sticky header and save sort widgets.</li>
</ul>
<strongid="Download-Themes">Themes:</strong>
<p>Theme zip files have been removed. There are now numerous themes available which <ahref="themes.html">can be seen here</a></p>
<aid="Compatibility"></a>
<h1>Browser Compatibility</h1>
<p>tablesorter has been tested successfully in the following browsers with Javascript enabled:</p>
<p>If you are having a problem with the plugin or you want to submit a feature request, please <ahref="https://github.com/Mottie/tablesorter/issues">submit an issue</a>.</p>
<p>If you would like to contribute, <ahref="https://github.com/Mottie/tablesorter">fork a copy on github</a>.</p>
<p>Support is also available through the <aclass="external"href="http://jquery.com/discuss/">jQuery Mailing List</a> or <aclass="external"href="http://stackoverflow.com/questions/tagged/tablesorter">StackOverflow</a>.</p>
<p>Access to the jQuery Mailing List is also available through <aclass="external"href="http://www.nabble.com/JQuery-f15494.html">Nabble Forums</a>.</p>
<aid="Credits"></a>
<h1>Credits</h1>
<p>Written by Christian Bach.</p>
<p>
Documentation written by <aclass="external"href="http://www.ghidinelli.com">Brian Ghidinelli</a>,
based on <aclass="external"href="http://malsup.com/jquery/">Mike Alsup's</a> great documention.<br>
Additional & Missing documentation, alphanumeric sort, numerous widgets and other changes added by <aclass="external"href="https://github.com/Mottie/tablesorter">Mottie</a>.
</p>
<p>
<aclass="external"href="http://ejohn.org">John Resig</a> for the fantastic <aclass="external"href="http://jquery.com">jQuery</a>