Client-Side Table Sorting Basic Example
Click on column headers to sort by the column. Sorting is done within the two tbody sections, not across them, and the header and footer are not changed.
The table is auto-striped and auto-sorted on the first column on page load.
Client-Side Sorting With Large Table
See the Client-Side Sorting With 500 Rows example to see how fast it sorts on your computer.
Rowspan/Colspan Correction
When cells span rows or columns, their cellIndex property is misleading. A cell may be the first td in a row, but actually occupy the second position in the table "grid" because a cell in a row above it has a rowspan > 1. Since the column to sort is calculated automatically based on the cell clicked, the correct column index must be computed rather than relying blindly on the cellIndex property of the clicked cell. The example below demonstrates this complex requirement.
Also, it shows that only classes that are marked as "sortable" will receive the sorted class names. This is important, because you don't want every header cell that is in the same column as the sorted column to be marked as sorted - only the ones you specify.
Rowspan/Colspan Correction |
Index |
First Two Columns |
Second Two Columns |
Numeric |
Text |
Currency |
Date |
0 |
8.5 |
Bill |
$62.975 |
2018-01-27 |
1 |
389.9 |
Joe |
$81.175 |
2019-04-16 |
2 |
419.1 |
Bob |
$93.235 |
2017-01-09 |
3 |
357.3 |
Matt |
$60.185 |
2019-08-26 |
4 |
348.9 |
Mark |
$16.915 |
2017-02-28 |
5 |
452.3 |
Tom |
$87.335 |
2018-04-16 |
6 |
962 |
Jake |
$93.895 |
2019-10-04 |
7 |
666.3 |
Greg |
$16.275 |
2017-06-16 |
8 |
188.7 |
Adam |
$5.484 |
2018-06-12 |
9 |
732.1 |
Steve |
$69.885 |
2016-09-16 |
Client-Side Table Filtering
Client-side table filtering works by scanning each row in the table and matching it against the criteria passed into the filter. Filter values are stored, so adding or removing another filter maintains any other filters that still apply.
The filters in this example were created manually, not using the auto-filter functionality. The first filter is a manually-create select list, the second is a text input for entering free-form text, and the third uses custom functions to do the filtering.
Table Striping
If a table has alternate rows highlighted and it is sorted, filtered, or otherwise manipulated, the sorted row colors can be mixed up. This function simply re-stripes rows by applying a class name to each odd row and removing it from each even row.
Table Striping
(Click here to shade alternate rows in this table)
|
Index |
Numeric |
Text |
Currency |
Date |
0 |
706.4 |
Bill |
$55.94 |
2017-12-18 |
1 |
222.5 |
Joe |
$96.24 |
2017-09-06 |
2 |
95.8 |
Bob |
$96.74 |
2017-04-07 |
3 |
318 |
Matt |
$14.14 |
2017-05-23 |
4 |
992.5 |
Mark |
$18.84 |
2019-03-11 |
5 |
628.9 |
Tom |
$17.44 |
2017-10-15 |
6 |
931.6 |
Jake |
$32.24 |
2017-03-24 |
7 |
423 |
Greg |
$52.64 |
2018-06-30 |
8 |
646.4 |
Adam |
$42.84 |
2016-09-07 |
9 |
349.7 |
Steve |
$3.73 |
2016-12-18 |
Client-Side Table Paging
Although paging through results or records is usually done by making a trip back to the server, it can sometimes be helpful to page through results on the client side.
Index |
Name |
Date |
0 |
Bill |
2019-10-05 |
1 |
Joe |
2018-12-22 |
2 |
Bob |
2018-09-27 |
3 |
Matt |
2017-12-09 |
4 |
Mark |
2019-09-05 |
5 |
Tom |
2018-08-14 |
6 |
Jake |
2019-01-02 |
7 |
Greg |
2016-10-24 |
8 |
Adam |
2018-07-07 |
9 |
Steve |
2019-08-26 |
10 |
George |
2017-10-27 |
11 |
John |
2018-12-17 |
12 |
Phil |
2017-04-04 |
13 |
Jack |
2017-10-18 |
14 |
Paul |
2019-07-22 |
15 |
Rob |
2016-08-29 |
16 |
Walt |
2016-08-14 |
17 |
Nathan |
2016-12-08 |
18 |
Dan |
2017-10-31 |
19 |
Jeff |
2019-07-28 |
20 |
Bill |
2017-12-17 |
21 |
Joe |
2018-06-10 |
22 |
Bob |
2017-09-29 |
23 |
Matt |
2019-08-17 |
24 |
Mark |
2017-02-23 |
25 |
Tom |
2016-08-15 |
26 |
Jake |
2017-10-24 |
27 |
Greg |
2017-03-20 |
28 |
Adam |
2017-09-24 |
<< Previous
1
2
3
4
5
6
Next >>
|
Alternate Styles Examples
This example shows how simply changing your css can change the sort interface without any code changes necessary.
Click on an icon set to try it on.
Browse icon files for download...
Index |
Numeric |
Text |
Currency |
Date |
0 |
414.3 |
Bill |
$29.94 |
2017-09-15 |
1 |
157.7 |
Joe |
$96.84 |
2019-01-10 |
2 |
123.6 |
Bob |
$59.94 |
2018-03-30 |
3 |
185.1 |
Matt |
$19.74 |
2018-02-09 |
4 |
564.7 |
Mark |
$93.64 |
2018-09-30 |