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 682 Bill $51.445 2019-09-08
1 639.6 Joe $13.775 2018-09-01
2 716.9 Bob $54.135 2018-07-22
3 619.9 Matt $90.165 2019-11-09
4 596.8 Mark $11.785 2020-02-26
tbody #2
5 654 Tom $91.355 2021-05-04
6 902.4 Jake $1.614 2020-08-26
7 872.4 Greg $98.185 2020-08-03
8 88.5 Adam $28.435 2020-12-27
9 626.5 Steve $46.165 2021-06-21
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 123.3 Bill $14.365 2019-12-07
1 553.2 Joe $78.325 2020-05-15
2 661.5 Bob $50.005 2018-12-01
3 734.7 Matt $11.995 2018-08-09
4 218.1 Mark $71.665 2018-12-23
5 796 Tom $37.065 2018-09-14
6 747.9 Jake $27.295 2018-10-02
7 483.1 Greg $14.525 2018-09-11
8 198.3 Adam $23.365 2019-08-06
9 39.3 Steve $86.015 2021-01-22

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

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 528.4 Bill $10.44 2018-11-18
1 726.3 Joe $39.44 2020-01-25
2 658.9 Bob $80.44 2018-05-13
3 809.6 Matt $93.04 2020-06-25
4 756.1 Mark $42.74 2019-10-24
5 450.5 Tom $19.74 2019-07-28
6 628 Jake $11.24 2019-09-15
7 3.8 Greg $26.14 2021-02-10
8 418.7 Adam $26.94 2018-12-01
9 866.7 Steve $26.14 2019-11-29

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 2021-01-13
1 Joe 2020-10-28
2 Bob 2020-03-29
3 Matt 2018-06-04
4 Mark 2019-12-16
5 Tom 2021-06-28
6 Jake 2020-03-01
7 Greg 2018-11-16
8 Adam 2020-11-13
9 Steve 2020-03-15
10 George 2021-06-10
11 John 2020-08-25
12 Phil 2019-03-12
13 Jack 2020-09-01
14 Paul 2018-11-01
15 Rob 2020-09-06
16 Walt 2018-12-05
17 Nathan 2019-06-17
18 Dan 2018-10-06
19 Jeff 2020-12-01
20 Bill 2019-10-24
21 Joe 2020-02-22
22 Bob 2020-12-05
23 Matt 2020-08-21
24 Mark 2019-10-06
25 Tom 2019-02-01
26 Jake 2021-06-28
27 Greg 2020-05-10
28 Adam 2018-08-31
<< 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 260.4 Bill $14.24 2021-05-17
1 49.7 Joe $74.84 2021-06-23
2 565.3 Bob $74.74 2020-02-24
3 739.8 Matt $55.14 2018-11-11
4 723.8 Mark $28.44 2019-09-25