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 792.2 Bill $53.295 2019-12-07
1 27.2 Joe $42.005 2020-01-12
2 8.5 Bob $42.105 2019-04-13
3 881.8 Matt $45.235 2018-08-17
4 88.9 Mark $51.025 2019-12-15
tbody #2
5 619.7 Tom $78.115 2019-06-04
6 668.2 Jake $12.435 2018-06-01
7 189.2 Greg $75.185 2018-04-25
8 875.8 Adam $26.825 2019-12-07
9 988 Steve $11.545 2018-09-17
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 112.6 Bill $90.755 2020-05-25
1 804.5 Joe $93.475 2018-07-24
2 527.1 Bob $94.325 2019-11-23
3 13.6 Matt $82.495 2018-02-27
4 293.3 Mark $91.375 2019-10-11
5 992.1 Tom $53.345 2019-01-30
6 523.2 Jake $20.165 2019-06-23
7 736.3 Greg $39.075 2018-09-09
8 917.3 Adam $26.645 2019-07-16
9 608.9 Steve $25.435 2019-11-27

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

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 390.8 Bill $10.24 2019-03-18
1 89.2 Joe $57.04 2018-03-27
2 801.1 Bob $86.24 2020-11-05
3 806.1 Matt $6.93 2019-02-27
4 803.2 Mark $80.94 2018-10-22
5 323.5 Tom $75.04 2020-03-11
6 580 Jake $8.23 2019-05-11
7 753.7 Greg $68.04 2020-04-27
8 536.3 Adam $53.34 2020-04-11
9 233.8 Steve $75.24 2018-12-08

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-11-29
1 Joe 2018-03-12
2 Bob 2019-04-05
3 Matt 2018-03-19
4 Mark 2018-06-23
5 Tom 2017-11-23
6 Jake 2018-09-16
7 Greg 2017-11-05
8 Adam 2020-08-17
9 Steve 2018-08-24
10 George 2020-05-26
11 John 2020-11-04
12 Phil 2020-01-24
13 Jack 2019-10-11
14 Paul 2020-03-28
15 Rob 2017-12-18
16 Walt 2020-10-19
17 Nathan 2019-06-13
18 Dan 2020-06-01
19 Jeff 2019-06-21
20 Bill 2019-09-15
21 Joe 2018-11-12
22 Bob 2018-09-09
23 Matt 2018-09-10
24 Mark 2018-04-12
25 Tom 2020-05-22
26 Jake 2020-05-19
27 Greg 2020-10-25
28 Adam 2017-12-17
<< 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 586 Bill $34.94 2020-02-18
1 729.1 Joe $82.84 2020-08-08
2 961.4 Bob $87.74 2018-05-27
3 994.7 Matt $78.84 2019-04-23
4 834.1 Mark $76.74 2018-06-19