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 854 Bill $85.605 2017-05-26
1 32.2 Joe $97.265 2018-10-19
2 87.7 Bob $33.415 2018-04-15
3 225.6 Matt $7.124 2018-05-15
4 722.5 Mark $83.165 2017-06-27
tbody #2
5 967.6 Tom $32.515 2017-11-15
6 166 Jake $70.935 2016-09-25
7 50.8 Greg $99.105 2016-07-05
8 290.1 Adam $34.845 2018-10-31
9 239.1 Steve $17.765 2016-12-20
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 704.9 Bill $3.164 2016-07-06
1 17 Joe $6.384 2016-06-04
2 770.9 Bob $15.145 2017-06-26
3 363.1 Matt $37.695 2017-09-16
4 981.6 Mark $9.944 2017-03-05
5 321.9 Tom $6.694 2018-03-17
6 783.9 Jake $23.295 2017-04-14
7 886 Greg $28.365 2017-04-04
8 917.3 Adam $57.375 2018-05-12
9 681.3 Steve $81.285 2018-12-03

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

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 538 Bill $11.94 2019-03-19
1 843.4 Joe $15.84 2016-10-14
2 511.9 Bob $57.54 2018-10-30
3 161.9 Matt $9.13 2018-06-21
4 133.8 Mark $67.44 2016-09-27
5 889.5 Tom $48.94 2019-01-20
6 531.1 Jake $58.94 2019-01-17
7 90 Greg $26.14 2017-10-25
8 330.2 Adam $74.74 2019-02-07
9 428.2 Steve $75.04 2016-08-30

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 2017-09-24
1 Joe 2017-04-28
2 Bob 2017-01-14
3 Matt 2017-05-12
4 Mark 2016-10-29
5 Tom 2017-07-17
6 Jake 2017-09-27
7 Greg 2018-06-13
8 Adam 2019-05-13
9 Steve 2016-12-27
10 George 2018-12-18
11 John 2016-06-25
12 Phil 2019-01-19
13 Jack 2019-05-21
14 Paul 2018-08-14
15 Rob 2019-05-19
16 Walt 2019-01-13
17 Nathan 2016-12-30
18 Dan 2018-11-08
19 Jeff 2017-07-20
20 Bill 2018-11-11
21 Joe 2018-04-27
22 Bob 2017-11-01
23 Matt 2016-07-09
24 Mark 2016-07-22
25 Tom 2018-11-18
26 Jake 2018-11-21
27 Greg 2019-04-02
28 Adam 2017-01-25
<< 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 532.9 Bill $97.64 2018-05-22
1 821.2 Joe $17.54 2019-05-05
2 952.8 Bob $53.24 2017-07-02
3 596.4 Matt $46.44 2018-01-30
4 401.7 Mark $48.74 2017-07-20