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 616.4 Bill $48.495 2019-04-23
1 97 Joe $92.575 2019-02-02
2 393.1 Bob $21.175 2019-01-20
3 546 Matt $21.425 2021-04-24
4 486.1 Mark $50.225 2018-10-06
tbody #2
5 947.6 Tom $59.285 2021-03-30
6 488.1 Jake $8.064 2021-03-18
7 208.8 Greg $8.704 2021-04-02
8 302.8 Adam $40.925 2018-05-25
9 478.4 Steve $12.265 2019-07-01
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 166.4 Bill $73.905 2021-01-12
1 507.5 Joe $83.595 2020-10-18
2 779.2 Bob $22.905 2018-04-20
3 39.5 Matt $77.495 2018-12-24
4 12.6 Mark $26.105 2020-07-27
5 181.5 Tom $20.855 2019-04-13
6 133.6 Jake $69.655 2019-07-15
7 75.1 Greg $90.535 2019-10-23
8 29.3 Adam $20.805 2021-02-08
9 82.8 Steve $68.645 2018-04-29

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

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 787.8 Bill $74.04 2020-07-12
1 927.1 Joe $57.54 2021-03-05
2 105.8 Bob $18.44 2019-05-28
3 297 Matt $5.53 2019-12-22
4 669.7 Mark $13.44 2018-06-05
5 175.9 Tom $90.94 2021-05-10
6 757.2 Jake $59.04 2019-07-13
7 367.6 Greg $47.84 2020-08-01
8 60.9 Adam $5.33 2018-07-27
9 237.7 Steve $48.14 2018-12-29

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-09-17
1 Joe 2019-01-29
2 Bob 2021-05-03
3 Matt 2019-11-05
4 Mark 2018-11-06
5 Tom 2019-12-28
6 Jake 2019-08-16
7 Greg 2019-03-08
8 Adam 2020-07-28
9 Steve 2020-10-19
10 George 2020-02-15
11 John 2020-09-29
12 Phil 2019-05-18
13 Jack 2019-01-28
14 Paul 2021-03-02
15 Rob 2019-07-30
16 Walt 2019-08-20
17 Nathan 2020-11-17
18 Dan 2019-07-15
19 Jeff 2018-11-12
20 Bill 2019-07-31
21 Joe 2020-11-02
22 Bob 2020-01-11
23 Matt 2021-02-03
24 Mark 2020-01-11
25 Tom 2020-03-22
26 Jake 2021-04-06
27 Greg 2020-05-15
28 Adam 2020-12-22
<< 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 438.6 Bill $91.84 2020-04-15
1 707 Joe $89.94 2018-09-27
2 902.5 Bob $45.54 2020-02-19
3 203.6 Matt $19.54 2019-07-16
4 801.8 Mark $98.94 2020-09-08