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 559.1 Bill $91.545 2016-04-05
1 231.8 Joe $52.875 2017-01-22
2 2.7 Bob $70.035 2019-04-12
3 894.5 Matt $89.765 2017-04-18
4 622.2 Mark $1.274 2018-07-01
tbody #2
5 80.7 Tom $65.755 2018-06-29
6 315.8 Jake $4.584 2019-05-21
7 25 Greg $10.555 2016-06-11
8 872.4 Adam $11.825 2017-05-04
9 230.9 Steve $98.325 2018-08-01
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 907.6 Bill $54.235 2018-04-25
1 911.4 Joe $77.405 2016-10-27
2 167.6 Bob $77.675 2019-01-15
3 123.7 Matt $67.115 2018-09-19
4 454.1 Mark $29.335 2018-10-03
5 163.4 Tom $37.405 2017-09-02
6 871.6 Jake $68.975 2017-10-25
7 861.4 Greg $71.465 2018-02-24
8 923.4 Adam $58.695 2018-07-11
9 267.7 Steve $81.775 2018-06-21

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

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 302.7 Bill $50.94 2019-04-23
1 106.8 Joe $30.34 2018-05-31
2 34.6 Bob $76.84 2016-10-24
3 416.3 Matt $52.64 2017-09-20
4 961.4 Mark $65.84 2016-11-18
5 378.1 Tom $48.04 2017-08-10
6 656.1 Jake $1.63 2017-01-24
7 857.4 Greg $13.94 2018-10-19
8 326.3 Adam $8.03 2016-06-01
9 799.4 Steve $74.64 2017-12-21

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-03-11
1 Joe 2016-05-27
2 Bob 2016-06-01
3 Matt 2019-01-30
4 Mark 2016-09-28
5 Tom 2017-05-17
6 Jake 2018-01-28
7 Greg 2016-11-07
8 Adam 2016-08-21
9 Steve 2018-08-22
10 George 2018-03-03
11 John 2018-04-22
12 Phil 2016-12-10
13 Jack 2018-01-18
14 Paul 2017-03-22
15 Rob 2017-07-30
16 Walt 2019-03-31
17 Nathan 2018-09-28
18 Dan 2018-12-08
19 Jeff 2018-02-26
20 Bill 2018-10-16
21 Joe 2016-08-01
22 Bob 2017-09-14
23 Matt 2019-03-26
24 Mark 2019-02-18
25 Tom 2018-09-27
26 Jake 2016-04-26
27 Greg 2019-04-21
28 Adam 2018-02-06
<< 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 767.8 Bill $50.84 2017-11-15
1 816.7 Joe $56.04 2017-07-16
2 972.2 Bob $91.64 2019-05-14
3 162.3 Matt $3.93 2018-08-03
4 768.7 Mark $68.74 2019-04-13