Logo
doctype [?]
[strict] [loose] [none]

Table Sorting, Filtering, Etc - BETA!


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.

Index Numeric Text Currency Date Checkbox
tbody #1
0 280.3 Bill $7.364 2020-08-31
1 885.6 Joe $19.625 2020-02-24
2 326 Bob $11.015 2021-07-15
3 877.6 Matt $80.975 2020-09-07
4 550.6 Mark $11.835 2020-09-09
tbody #2
5 439.3 Tom $66.045 2019-09-04
6 398.6 Jake $98.105 2020-09-18
7 910.5 Greg $10.965 2019-06-20
8 192.6 Adam $61.385 2021-06-20
9 876 Steve $19.165 2019-05-02
tfoot tfoot tfoot tfoot tfoot tfoot

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 639.1 Bill $47.185 2019-07-26
1 360.2 Joe $35.735 2020-03-09
2 918.6 Bob $68.335 2020-07-14
3 914.1 Matt $56.095 2019-12-07
4 641.1 Mark $11.145 2020-04-22
5 370.5 Tom $55.065 2019-03-26
6 778.8 Jake $94.925 2019-03-03
7 515.8 Greg $85.975 2019-07-08
8 858.9 Adam $5.224 2021-06-18
9 833.1 Steve $92.825 2018-11-25

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 Filtering
Index Number Name Amount
Filter:
0 0 Bill $0.33
1 1 Joe $1.13
2 2 Bob $1.33
3 3 Matt $1.03
4 4 Mark $1.93
5 0 Tom $2.03
6 1 Jake $0.23
7 2 Greg $1.73
8 3 Bill $1.43
9 4 Joe $1.53
10 0 Bob $1.53
11 1 Matt $0.53
12 2 Mark $0.53
13 3 Tom $0.83
14 4 Jake $0.73
15 0 Greg $1.73
16 1 Bill $1.63
17 2 Joe $1.83
18 3 Bob $0.23
19 4 Matt $1.13
20 0 Mark $1.73
21 1 Tom $0.83
22 2 Jake $0.13
23 3 Greg $1.43
24 4 Bill $1.53
25 0 Joe $1.93
26 1 Bob $1.53
27 2 Matt $1.43
28 3 Mark $1.53
29 4 Tom $1.43
30 0 Jake $1.73
31 1 Greg $1.83
32 2 Bill $0.53
33 3 Joe $1.03
34 4 Bob $0.83

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 182.4 Bill $49.44 2019-11-19
1 28.3 Joe $17.04 2019-02-10
2 788.2 Bob $40.64 2019-11-22
3 189.2 Matt $75.54 2019-06-05
4 960.6 Mark $65.34 2019-10-24
5 510.7 Tom $50.14 2020-12-26
6 576.6 Jake $20.94 2020-02-16
7 501.5 Greg $96.94 2019-03-08
8 259.3 Adam $65.74 2018-10-03
9 150.2 Steve $91.24 2020-05-04

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 2020-02-12
1 Joe 2018-09-05
2 Bob 2018-09-26
3 Matt 2018-06-14
4 Mark 2018-10-08
5 Tom 2019-04-10
6 Jake 2019-03-08
7 Greg 2021-04-07
8 Adam 2020-07-23
9 Steve 2020-09-09
10 George 2018-09-11
11 John 2019-10-13
12 Phil 2018-07-26
13 Jack 2018-07-28
14 Paul 2018-09-07
15 Rob 2019-12-31
16 Walt 2020-03-10
17 Nathan 2020-04-10
18 Dan 2019-06-08
19 Jeff 2018-11-06
20 Bill 2020-12-08
21 Joe 2021-03-07
22 Bob 2020-06-08
23 Matt 2020-11-01
24 Mark 2018-10-24
25 Tom 2021-04-04
26 Jake 2019-10-01
27 Greg 2019-03-09
28 Adam 2018-07-26
<< 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 343.5 Bill $87.34 2020-04-20
1 437.5 Joe $98.44 2020-05-15
2 559.7 Bob $26.64 2021-03-03
3 470.1 Matt $95.44 2020-04-24
4 569.6 Mark $39.64 2020-07-01