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 697.9 Bill $31.695 2019-07-14
1 475.6 Joe $54.965 2019-06-18
2 243.9 Bob $1.744 2017-11-22
3 318 Matt $20.375 2019-07-31
4 815.9 Mark $19.645 2018-12-28
tbody #2
5 263.6 Tom $83.895 2019-04-01
6 319.9 Jake $35.065 2019-04-04
7 150.3 Greg $16.775 2019-08-22
8 145.9 Adam $67.495 2018-07-16
9 36.4 Steve $35.815 2017-05-28
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 412.3 Bill $5.604 2018-05-30
1 344.3 Joe $53.155 2016-12-25
2 254.2 Bob $77.545 2017-01-14
3 669 Matt $9.334 2017-09-06
4 616.2 Mark $90.925 2018-04-22
5 377.7 Tom $17.275 2017-10-17
6 220.2 Jake $49.255 2018-11-27
7 65.1 Greg $64.275 2019-06-09
8 30.6 Adam $78.865 2018-05-29
9 649 Steve $82.505 2019-07-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 $1.83
1 1 Joe $0.53
2 2 Bob $2.03
3 3 Matt $1.03
4 4 Mark $1.23
5 0 Tom $1.13
6 1 Jake $1.23
7 2 Greg $1.73
8 3 Bill $0.63
9 4 Joe $1.53
10 0 Bob $1.03
11 1 Matt $0.83
12 2 Mark $0.23
13 3 Tom $0.23
14 4 Jake $0.63
15 0 Greg $1.33
16 1 Bill $1.03
17 2 Joe $0.93
18 3 Bob $0.13
19 4 Matt $1.43
20 0 Mark $1.93
21 1 Tom $1.63
22 2 Jake $1.63
23 3 Greg $1.23
24 4 Bill $1.43
25 0 Joe $1.63
26 1 Bob $0.83
27 2 Matt $0.53
28 3 Mark $0.93
29 4 Tom $0.53
30 0 Jake $0.43
31 1 Greg $0.83
32 2 Bill $0.93
33 3 Joe $0.43
34 4 Bob $1.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 39.9 Bill $69.84 2018-02-02
1 875.5 Joe $99.64 2017-05-01
2 380 Bob $38.74 2017-09-05
3 500.6 Matt $68.74 2016-07-31
4 998.9 Mark $15.94 2016-09-13
5 717.3 Tom $12.44 2019-02-23
6 500.8 Jake $73.24 2018-02-11
7 314.9 Greg $12.84 2018-11-28
8 777.9 Adam $34.94 2019-06-30
9 151 Steve $80.84 2016-11-18

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-08-13
1 Joe 2019-04-07
2 Bob 2019-02-05
3 Matt 2018-02-16
4 Mark 2018-11-14
5 Tom 2019-01-31
6 Jake 2018-11-19
7 Greg 2016-11-26
8 Adam 2017-02-20
9 Steve 2016-10-24
10 George 2018-06-29
11 John 2019-04-25
12 Phil 2016-10-25
13 Jack 2018-06-27
14 Paul 2016-08-25
15 Rob 2016-12-09
16 Walt 2017-08-04
17 Nathan 2017-01-15
18 Dan 2019-07-05
19 Jeff 2019-03-07
20 Bill 2019-05-12
21 Joe 2017-11-15
22 Bob 2017-01-03
23 Matt 2016-08-06
24 Mark 2017-01-12
25 Tom 2019-06-22
26 Jake 2017-09-15
27 Greg 2016-10-12
28 Adam 2016-10-12
<< 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 163.3 Bill $16.04 2016-10-27
1 10.9 Joe $95.54 2018-05-16
2 734 Bob $74.54 2017-07-04
3 837 Matt $92.24 2017-09-28
4 440.6 Mark $78.54 2017-12-24