Все ленты — последние статьи

Tablesorter представляет собой jQuery-плагин для преобразования стандартной HTML-таблицы с тэгами THEAD и TBODY в сортируемую таблицы без обновления страницы

 

Tablesorter представляет собой jQuery-плагин для преобразования стандартной HTML-таблицы с тэгами THEAD и TBODY в сортируемую таблицы без обновления страницы. Tablesorter может успешно парсить и сортировать многие типы данных, включая ссылочные данные в ячейках.

От себя: сортирует быстро даже 500 записей: Два архива: Полный с документацией и примерами и взял стили — голубые

Взял часть сайта автора, но в архивах все есть, примеры рабочие, тестил вообще на древних Linux браузерах.

 

Getting started

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

<script type="text/javascript" src="/path/to/jquery-latest.js"></script>
<script type="text/javascript" src="/path/to/jquery.tablesorter.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>..jsmith.com</td>
</tr>
<tr>
    <td>Bach</td>
    <td>Frank</td>
    <td>fbach_yahoo.com</td>
    <td>$50.00</td>
    <td>…frank.com</td>
</tr>
<tr>
    <td>Doe</td>
    <td>Jason</td>
    <td>jdoe_hotmail.com</td>
    <td>$100.00</td>
    <td>....jdoe.com</td>
</tr>
<tr>
    <td>Conway</td>
    <td>Tim</td>
    <td>tconway_earthlink.net</td>
    <td>$50.00</td>
    <td>…timconway.com</td>
</tr>
</tbody>
</table>

 

 

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

$(document).ready(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.

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

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

Examples

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

Basic

Metadata — setting inline options

Advanced

Companion plugins

Configuration

tablesorter has many options you can pass in at initialization to achieve different effects:

PropertyTypeDefaultDescriptionLink
cancelSelection Boolean true Indicates if tablesorter should disable selection of text in the table header (TH). Makes header behave more like a button.  
cssAsc String "headerSortUp" The CSS style used to style the header when sorting ascending. Example from the blue skin:
th.headerSortUp {
background-image: url(../img/small_asc.gif);
background-color: #3399FF;
}
 
cssDesc String "headerSortDown" The CSS style used to style the header when sorting descending. Example from the blue skin:
th.headerSortDown {
background-image: url(../img/small_desc.gif);
background-color: #3399FF;
}
 
cssHeader String "header" The CSS style used to style the header in its unsorted state. Example from the blue skin:
th.header {
background-image: url(../img/small.gif);
cursor: pointer;
font-weight: bold;
background-repeat: no-repeat;
background-position: center left;
padding-left: 20px;
border-right: 1px solid #dad9c7;
margin-left: -1px;
}
 
debug Boolean false Boolean flag indicating if tablesorter should display debuging information usefull for development. Example
headers Object null An object of instructions for per-column controls in the format: headers: { 0: { option: setting }, … } For example, to disable sorting on the first two columns of a table: headers: { 0: { sorter: false}, 1: {sorter: false} } Example
sortForce Array null Use to add an additional forced sort that will be appended to the dynamic selections by the user. For example, can be used to sort people alphabetically after some other user-selected sort that results in rows with the same value like dates or money due. It can help prevent data from appearing as though it has a random secondary sort. Example
sortList Array null An array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], … ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]] Example
sortMultiSortKey String shiftKey The key used to select more than one column for multi-column sorting. Defaults to the shift key. Other options might be ctrlKey, altKey.
Reference: http://developer.mozilla.org/en/docs/DOM:event#Properties
Example
textExtraction String Or Function simple Defines which method is used to extract data from a table cell for sorting. Built-in options include "simple" and "complex". Use complex if you have data marked up inside of a table cell like: <td><strong><em>123 Main Street</em></strong></td>. Complex can be slow in large tables so consider writing your own text extraction function "myTextExtraction" which you define like:
var myTextExtraction = function(node)
{
// extract data from markup and return it
return node.childNodes[0].childNodes[0].innerHTML;
}
$(document).ready(function()
{
$("#myTable").tableSorter( {textExtraction: myTextExtraction} );
}
);
tablesorter will pass a jQuery object containing the contents of the current cell for you to parse and return. Thanks to Josh Nathanson for the examples.
Example
widthFixed Boolean false Indicates if tablesorter should apply fixed widths to the table columns. This is useful for the Pager companion. Requires the jQuery dimension plugin to work. Example

Download

Full release — Plugin, Documentation, Add-ons, Themes jquery.tablesorter.zip

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

Required:

Optional/Add-Ons:

Themes:

  • Green Skin — Images and CSS styles for green themed headers
  • Blue Skin — Images and CSS styles for blue themed headers (as seen in the examples)

Browser Compatibility

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

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

jQuery Browser Compatibility

Support

Support is available through the jQuery Mailing List.

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