# | Name | Birthday | Grocery item | Price | Version | Filesize |
---|---|---|---|---|---|---|
1 | Gonzo the Great | 12-2-70 | Radishes | $0.63 | 31.0.1650.57 | 124k |
2 | Ernie | 10/11/69 | Fish | $12.09 | 11.0.1 | 134.56 GB |
3 | Bert | 10/11/1969 | Broccoli | $0.79 | 18.0.1284.49 | 134 B |
4 | Cookie Monster | 1/09/1966 | Oreo cookies | $2.78 | 3.0.0 | 4.13 TiB |
5 | Kermit | 12-05-1955 | Granola | $4.73 | 3.0.9 | 12 YB |
6 | Sam the Eagle | 04/07/75 | Corn dog | $5.50 | 3.1.2 | 19.4 K |
See all available sort types in the sort directory of the project. Defaults to string if no sort types are provided.
You can pass an alternate sort order as a second parameter. By default sort is ascending. To change this, set:
For columns or rows that do not require sorting, you can add attribute data-sort-method='none'
to a columns th
or a tr
element.
Sometimes text inside cells is not normalized. Using a data-sort
attribute you can use optional data to sort on.
You can use a custom attribute (instead of data-sort
) using the sortAttribute
option:
By adding a data-sort-method
attribute to a table heading you can force Tablesort to use a specific sorting method rather than guessing it. The value of data-sort-method
corresponds to the name of a sort function.
If you have two or more table heading rows you can specify the one that enables sorting by adding a data-sort-method='thead'
attribute to desired <tr>
element.
Tablesort supports two custom events beforeSort
& afterSort
.
Name | Born |
---|---|
Roy Eldridge | 1911 |
Tim Hagans | 1954 |
Freddie Hubbard | 1938 |
Tablesort supports sorting when new data has been added. Simply call the refresh method.
Name | Born |
---|---|
Roy Eldridge | 1911 |
Tim Hagans | 1954 |
Freddie Hubbard | 1938 |
It is possible to automatically sort the table once you create a Tablesort instance by adding data-sort-default
attribute.
Name | Born |
---|---|
Roy Eldridge | 1911 |
Tim Hagans | 1954 |
Freddie Hubbard | 1938 |
Sometimes, tables can have more complex column structures, especially when using colspans. In these cases, you can
explicitly connect a header to the cells in each row that it should sort by, by using the data-sort-column-key
attribute.
This example sorts products by price, even though the prices are not in the same column as their header.
Product | Price | |
---|---|---|
Apples | Sale! | 20 |
Bread | Out of stock | 10 |
Radishes | In Stock! | 30 |
Add the styling from tablesort.css file to your CSS or roll with your own.
MIT