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 155.9 Bill $85.995 2018-02-16
1 617.4 Joe $44.195 2018-05-11
2 447.5 Bob $7.684 2017-11-16
3 353.2 Matt $83.735 2016-06-12
4 726.6 Mark $40.835 2018-06-04
tbody #2
5 523.2 Tom $53.405 2016-09-10
6 358.7 Jake $1.344 2017-11-08
7 180.1 Greg $19.175 2016-08-20
8 499.2 Adam $0.804 2016-08-23
9 935.1 Steve $44.325 2016-11-18
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 935.6 Bill $59.905 2016-06-09
1 811 Joe $21.635 2017-11-02
2 759 Bob $66.385 2018-01-30
3 554.8 Matt $1.694 2017-07-26
4 899.2 Mark $74.355 2015-09-10
5 867.3 Tom $26.665 2017-05-20
6 290.3 Jake $62.525 2017-06-04
7 79.2 Greg $80.525 2018-01-12
8 483.3 Adam $30.435 2018-01-21
9 890.2 Steve $23.935 2016-04-17

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

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 936.4 Bill $45.54 2016-08-07
1 681 Joe $23.04 2017-09-26
2 980.4 Bob $2.23 2017-11-30
3 179 Matt $55.84 2018-06-05
4 244.8 Mark $36.04 2017-10-19
5 600.9 Tom $78.74 2016-01-28
6 36 Jake $1.93 2017-01-09
7 954.4 Greg $55.54 2017-07-05
8 763 Adam $33.14 2015-10-07
9 943.8 Steve $28.14 2016-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-01-05
1 Joe 2016-01-17
2 Bob 2018-04-19
3 Matt 2016-02-02
4 Mark 2018-03-15
5 Tom 2015-11-10
6 Jake 2018-06-21
7 Greg 2018-02-20
8 Adam 2015-12-06
9 Steve 2017-11-10
10 George 2015-07-16
11 John 2017-09-11
12 Phil 2017-10-06
13 Jack 2016-04-24
14 Paul 2015-09-01
15 Rob 2017-01-15
16 Walt 2018-03-21
17 Nathan 2018-02-27
18 Dan 2017-10-04
19 Jeff 2018-05-01
20 Bill 2018-03-21
21 Joe 2016-04-05
22 Bob 2018-03-09
23 Matt 2016-10-22
24 Mark 2018-06-02
25 Tom 2017-06-08
26 Jake 2017-11-08
27 Greg 2015-08-29
28 Adam 2017-04-04
<< 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 70.6 Bill $57.04 2016-09-29
1 288.1 Joe $49.84 2017-06-24
2 186.7 Bob $65.84 2017-06-05
3 65.6 Matt $83.94 2016-10-05
4 123.5 Mark $57.84 2016-01-01