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 177.4 Bill $71.145 2017-10-29
1 182 Joe $38.435 2016-09-16
2 120.7 Bob $28.555 2019-08-04
3 669.5 Matt $82.795 2019-10-05
4 567.3 Mark $21.525 2016-12-11
tbody #2
5 704.2 Tom $35.555 2018-03-26
6 65.6 Jake $46.325 2018-11-06
7 223.9 Greg $27.405 2018-04-10
8 892.2 Adam $31.265 2018-05-04
9 644 Steve $45.245 2018-12-27
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 8.5 Bill $62.975 2018-01-27
1 389.9 Joe $81.175 2019-04-16
2 419.1 Bob $93.235 2017-01-09
3 357.3 Matt $60.185 2019-08-26
4 348.9 Mark $16.915 2017-02-28
5 452.3 Tom $87.335 2018-04-16
6 962 Jake $93.895 2019-10-04
7 666.3 Greg $16.275 2017-06-16
8 188.7 Adam $5.484 2018-06-12
9 732.1 Steve $69.885 2016-09-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 $1.03
1 1 Joe $1.43
2 2 Bob $1.33
3 3 Matt $1.93
4 4 Mark $0.23
5 0 Tom $0.93
6 1 Jake $1.63
7 2 Greg $1.03
8 3 Bill $0.83
9 4 Joe $1.83
10 0 Bob $1.83
11 1 Matt $0.03
12 2 Mark $1.73
13 3 Tom $0.53
14 4 Jake $0.33
15 0 Greg $0.13
16 1 Bill $1.43
17 2 Joe $0.13
18 3 Bob $1.13
19 4 Matt $1.33
20 0 Mark $2.03
21 1 Tom $1.13
22 2 Jake $0.63
23 3 Greg $0.33
24 4 Bill $1.63
25 0 Joe $1.03
26 1 Bob $0.43
27 2 Matt $0.83
28 3 Mark $0.53
29 4 Tom $1.83
30 0 Jake $0.93
31 1 Greg $1.43
32 2 Bill $1.23
33 3 Joe $0.23
34 4 Bob $1.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 706.4 Bill $55.94 2017-12-18
1 222.5 Joe $96.24 2017-09-06
2 95.8 Bob $96.74 2017-04-07
3 318 Matt $14.14 2017-05-23
4 992.5 Mark $18.84 2019-03-11
5 628.9 Tom $17.44 2017-10-15
6 931.6 Jake $32.24 2017-03-24
7 423 Greg $52.64 2018-06-30
8 646.4 Adam $42.84 2016-09-07
9 349.7 Steve $3.73 2016-12-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 2019-10-05
1 Joe 2018-12-22
2 Bob 2018-09-27
3 Matt 2017-12-09
4 Mark 2019-09-05
5 Tom 2018-08-14
6 Jake 2019-01-02
7 Greg 2016-10-24
8 Adam 2018-07-07
9 Steve 2019-08-26
10 George 2017-10-27
11 John 2018-12-17
12 Phil 2017-04-04
13 Jack 2017-10-18
14 Paul 2019-07-22
15 Rob 2016-08-29
16 Walt 2016-08-14
17 Nathan 2016-12-08
18 Dan 2017-10-31
19 Jeff 2019-07-28
20 Bill 2017-12-17
21 Joe 2018-06-10
22 Bob 2017-09-29
23 Matt 2019-08-17
24 Mark 2017-02-23
25 Tom 2016-08-15
26 Jake 2017-10-24
27 Greg 2017-03-20
28 Adam 2017-09-24
<< 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 414.3 Bill $29.94 2017-09-15
1 157.7 Joe $96.84 2019-01-10
2 123.6 Bob $59.94 2018-03-30
3 185.1 Matt $19.74 2018-02-09
4 564.7 Mark $93.64 2018-09-30