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 441.2 Bill $0.844 2018-09-03
1 100.6 Joe $11.735 2019-11-24
2 302.2 Bob $28.085 2017-11-30
3 930.8 Matt $96.665 2018-01-16
4 768.5 Mark $74.055 2019-09-23
tbody #2
5 802.8 Tom $43.095 2019-07-27
6 800 Jake $16.255 2017-02-24
7 735.3 Greg $82.775 2018-08-19
8 240.7 Adam $88.655 2016-12-18
9 405.8 Steve $54.675 2018-02-13
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 570 Bill $98.795 2018-02-23
1 128.5 Joe $8.854 2018-07-09
2 73.4 Bob $39.065 2019-05-30
3 392.3 Matt $32.145 2019-04-21
4 752.5 Mark $8.984 2018-06-24
5 643.6 Tom $89.255 2019-11-05
6 484.7 Jake $69.255 2017-03-11
7 563 Greg $42.785 2019-10-25
8 108.6 Adam $66.845 2019-06-15
9 128.1 Steve $7.424 2018-01-07

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

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 401.8 Bill $32.34 2019-04-13
1 247.8 Joe $14.24 2019-12-07
2 486.1 Bob $28.24 2019-10-25
3 476.8 Matt $51.24 2018-02-07
4 111.1 Mark $63.44 2019-05-03
5 230.1 Tom $44.94 2017-09-08
6 912.1 Jake $69.14 2018-12-14
7 702.5 Greg $60.24 2019-08-06
8 621.1 Adam $58.74 2018-03-10
9 51.9 Steve $21.64 2017-11-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 2018-02-17
1 Joe 2018-11-11
2 Bob 2018-11-17
3 Matt 2017-05-04
4 Mark 2019-08-25
5 Tom 2019-05-01
6 Jake 2017-03-14
7 Greg 2018-01-07
8 Adam 2017-01-20
9 Steve 2016-12-10
10 George 2019-07-12
11 John 2018-09-04
12 Phil 2018-02-22
13 Jack 2019-11-18
14 Paul 2017-07-07
15 Rob 2017-05-30
16 Walt 2017-06-10
17 Nathan 2018-12-09
18 Dan 2018-03-12
19 Jeff 2017-02-28
20 Bill 2017-12-16
21 Joe 2017-01-27
22 Bob 2019-05-22
23 Matt 2019-11-13
24 Mark 2019-10-08
25 Tom 2018-03-09
26 Jake 2018-07-24
27 Greg 2017-11-19
28 Adam 2018-05-09
<< 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 739.2 Bill $61.14 2019-07-31
1 357.3 Joe $23.44 2020-01-07
2 223.1 Bob $0.03 2017-02-23
3 574.9 Matt $4.83 2017-03-10
4 403.5 Mark $60.74 2018-06-06