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 245.3 Bill $83.295 2015-10-17
1 659.7 Joe $78.235 2014-04-05
2 205.4 Bob $6.084 2014-11-26
3 733.4 Matt $40.345 2016-02-02
4 574.1 Mark $73.205 2016-12-29
tbody #2
5 903.4 Tom $81.945 2014-03-06
6 598.7 Jake $87.715 2016-10-20
7 163.1 Greg $50.495 2016-04-02
8 212.6 Adam $94.595 2014-09-16
9 637 Steve $93.965 2015-12-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 517.9 Bill $18.485 2015-06-02
1 42.1 Joe $84.445 2014-09-23
2 82.2 Bob $4.984 2014-12-02
3 325 Matt $78.315 2016-03-13
4 942.2 Mark $35.725 2015-05-08
5 845 Tom $26.065 2014-10-11
6 859.5 Jake $85.925 2014-05-22
7 702.4 Greg $2.224 2015-12-27
8 371.6 Adam $23.485 2015-10-25
9 553.4 Steve $87.175 2015-08-16

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

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 758.9 Bill $2.83 2015-09-06
1 272.7 Joe $57.74 2015-07-31
2 111.3 Bob $91.04 2014-05-16
3 892.1 Matt $59.94 2014-05-20
4 517.8 Mark $55.04 2015-01-14
5 2.9 Tom $35.94 2015-12-11
6 190.4 Jake $19.04 2015-07-16
7 749.4 Greg $25.64 2016-10-23
8 861.8 Adam $19.44 2016-05-29
9 100.1 Steve $52.14 2014-11-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 2016-11-20
1 Joe 2015-01-08
2 Bob 2015-01-01
3 Matt 2015-04-09
4 Mark 2015-11-20
5 Tom 2016-10-30
6 Jake 2016-09-18
7 Greg 2016-03-28
8 Adam 2016-07-18
9 Steve 2016-12-14
10 George 2015-11-23
11 John 2015-04-11
12 Phil 2017-03-15
13 Jack 2014-05-14
14 Paul 2017-01-06
15 Rob 2014-12-09
16 Walt 2014-05-18
17 Nathan 2014-12-26
18 Dan 2016-09-30
19 Jeff 2014-12-24
20 Bill 2015-08-03
21 Joe 2014-12-26
22 Bob 2014-03-09
23 Matt 2016-05-25
24 Mark 2014-06-30
25 Tom 2016-11-30
26 Jake 2017-01-05
27 Greg 2016-10-08
28 Adam 2017-03-26
<< 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 430.8 Bill $7.93 2016-10-26
1 711.2 Joe $35.44 2014-10-15
2 264.2 Bob $20.54 2014-03-14
3 928.4 Matt $96.74 2017-01-08
4 484.6 Mark $32.74 2016-12-03