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 912.9 Bill $52.235 2020-01-15
1 309.6 Joe $51.885 2018-05-16
2 872.5 Bob $60.225 2019-09-22
3 951.4 Matt $76.345 2020-07-19
4 86.8 Mark $28.955 2019-03-16
tbody #2
5 813.3 Tom $99.575 2017-09-09
6 578.5 Jake $24.385 2018-08-09
7 561 Greg $25.935 2019-01-16
8 0.2 Adam $57.005 2019-05-28
9 458.5 Steve $64.955 2020-01-12
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 878 Bill $56.235 2018-07-08
1 712.4 Joe $87.185 2020-02-28
2 20.7 Bob $74.435 2018-11-25
3 756 Matt $69.575 2018-02-24
4 751.6 Mark $78.245 2019-01-25
5 322.3 Tom $59.575 2019-01-20
6 415.6 Jake $17.425 2019-10-29
7 797.2 Greg $73.515 2017-06-24
8 317.4 Adam $73.525 2019-04-14
9 951.3 Steve $19.375 2018-03-05

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.63
1 1 Joe $0.13
2 2 Bob $1.63
3 3 Matt $0.33
4 4 Mark $1.63
5 0 Tom $1.43
6 1 Jake $0.03
7 2 Greg $1.63
8 3 Bill $0.83
9 4 Joe $1.03
10 0 Bob $1.13
11 1 Matt $0.23
12 2 Mark $1.43
13 3 Tom $0.63
14 4 Jake $1.83
15 0 Greg $0.53
16 1 Bill $1.33
17 2 Joe $1.03
18 3 Bob $1.63
19 4 Matt $0.13
20 0 Mark $1.43
21 1 Tom $1.13
22 2 Jake $1.73
23 3 Greg $0.83
24 4 Bill $1.13
25 0 Joe $0.33
26 1 Bob $0.33
27 2 Matt $0.33
28 3 Mark $0.23
29 4 Tom $0.73
30 0 Jake $0.83
31 1 Greg $1.83
32 2 Bill $0.83
33 3 Joe $0.43
34 4 Bob $0.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 191.1 Bill $89.94 2017-07-17
1 995.7 Joe $32.34 2019-01-30
2 556.2 Bob $44.24 2018-03-16
3 868.2 Matt $34.44 2019-01-01
4 502.4 Mark $84.24 2018-04-15
5 552.2 Tom $51.44 2020-01-03
6 399.1 Jake $92.04 2018-08-22
7 563.4 Greg $6.23 2019-02-28
8 679 Adam $39.84 2020-06-18
9 577.8 Steve $80.54 2017-12-26

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-05-05
1 Joe 2020-07-20
2 Bob 2017-08-31
3 Matt 2019-06-27
4 Mark 2020-07-15
5 Tom 2018-09-08
6 Jake 2018-01-02
7 Greg 2019-02-17
8 Adam 2020-02-02
9 Steve 2018-10-24
10 George 2018-09-17
11 John 2018-01-04
12 Phil 2020-06-02
13 Jack 2020-04-21
14 Paul 2017-07-05
15 Rob 2018-02-22
16 Walt 2018-11-20
17 Nathan 2019-02-19
18 Dan 2017-08-02
19 Jeff 2020-02-25
20 Bill 2018-11-19
21 Joe 2018-10-30
22 Bob 2018-10-07
23 Matt 2019-01-30
24 Mark 2017-06-05
25 Tom 2017-10-01
26 Jake 2020-05-05
27 Greg 2020-06-30
28 Adam 2019-07-31
<< 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 734.8 Bill $16.64 2018-05-10
1 730.7 Joe $25.14 2020-06-13
2 722.3 Bob $65.94 2017-11-21
3 270 Matt $50.94 2019-04-23
4 685.9 Mark $70.44 2019-03-01