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 756 Bill $31.345 2016-12-10
1 706.9 Joe $10.565 2018-07-21
2 379.7 Bob $92.515 2018-01-07
3 920.8 Matt $81.795 2018-01-02
4 697.6 Mark $13.905 2018-04-02
tbody #2
5 808.7 Tom $36.105 2019-01-24
6 899.4 Jake $48.415 2018-08-27
7 693.5 Greg $39.845 2017-04-09
8 573.5 Adam $91.215 2016-07-01
9 380.7 Steve $31.155 2018-05-31
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 260.3 Bill $6.744 2016-03-28
1 574.8 Joe $77.425 2016-07-28
2 397.4 Bob $15.395 2016-05-02
3 52.3 Matt $7.464 2018-12-05
4 702.9 Mark $77.225 2016-03-13
5 430.7 Tom $58.085 2017-05-05
6 414.8 Jake $48.025 2018-11-16
7 269.8 Greg $17.365 2016-12-19
8 688.1 Adam $74.715 2016-09-09
9 863.4 Steve $12.775 2017-09-04

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.33
1 1 Joe $0.83
2 2 Bob $1.23
3 3 Matt $1.53
4 4 Mark $1.93
5 0 Tom $0.83
6 1 Jake $1.93
7 2 Greg $0.73
8 3 Bill $1.13
9 4 Joe $0.13
10 0 Bob $0.83
11 1 Matt $1.23
12 2 Mark $2.03
13 3 Tom $0.23
14 4 Jake $0.83
15 0 Greg $0.23
16 1 Bill $1.13
17 2 Joe $1.93
18 3 Bob $1.03
19 4 Matt $1.93
20 0 Mark $0.93
21 1 Tom $0.93
22 2 Jake $0.53
23 3 Greg $1.23
24 4 Bill $1.53
25 0 Joe $1.83
26 1 Bob $0.83
27 2 Matt $0.03
28 3 Mark $1.63
29 4 Tom $1.03
30 0 Jake $1.13
31 1 Greg $0.83
32 2 Bill $1.83
33 3 Joe $0.33
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 848.4 Bill $55.04 2016-03-28
1 208.4 Joe $9.23 2016-06-01
2 620.7 Bob $70.84 2016-05-28
3 735.9 Matt $9.73 2016-08-26
4 281.6 Mark $6.63 2018-04-17
5 242.1 Tom $51.54 2016-07-11
6 472.4 Jake $13.94 2018-12-14
7 390.7 Greg $50.94 2018-12-15
8 172.5 Adam $0.73 2017-07-10
9 596.8 Steve $89.24 2018-01-12

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-05-05
1 Joe 2018-04-17
2 Bob 2016-08-09
3 Matt 2018-08-20
4 Mark 2018-12-14
5 Tom 2016-11-23
6 Jake 2019-02-08
7 Greg 2017-10-01
8 Adam 2015-12-21
9 Steve 2016-05-26
10 George 2016-11-29
11 John 2016-04-10
12 Phil 2017-02-08
13 Jack 2017-10-21
14 Paul 2016-06-26
15 Rob 2016-04-14
16 Walt 2018-07-28
17 Nathan 2018-02-12
18 Dan 2016-11-12
19 Jeff 2016-11-24
20 Bill 2018-07-23
21 Joe 2016-09-14
22 Bob 2018-02-19
23 Matt 2016-12-31
24 Mark 2016-07-19
25 Tom 2018-09-07
26 Jake 2017-01-08
27 Greg 2018-02-15
28 Adam 2017-05-28
<< 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 232 Bill $34.74 2016-08-19
1 972.5 Joe $55.64 2016-02-26
2 921.5 Bob $85.64 2016-02-23
3 491.1 Matt $86.44 2016-08-07
4 796.5 Mark $96.84 2017-10-05