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 646.6 Bill $88.355 2018-10-07
1 436.7 Joe $31.745 2019-01-15
2 776.3 Bob $64.755 2019-06-24
3 241.8 Matt $77.555 2020-03-26
4 177.1 Mark $13.215 2019-11-25
tbody #2
5 625.2 Tom $93.655 2020-10-21
6 788.6 Jake $18.885 2020-07-11
7 23.2 Greg $1.714 2018-09-08
8 387.1 Adam $48.895 2020-09-02
9 292.7 Steve $67.315 2021-03-08
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 425.3 Bill $31.965 2020-10-24
1 565 Joe $75.635 2018-08-26
2 791.2 Bob $53.255 2020-09-13
3 155.7 Matt $77.435 2019-12-29
4 758.8 Mark $95.135 2020-05-29
5 256.5 Tom $57.655 2020-03-17
6 40 Jake $36.505 2020-10-21
7 735.6 Greg $38.815 2020-11-10
8 850.2 Adam $77.525 2019-03-29
9 591.2 Steve $6.784 2021-05-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.03
2 2 Bob $0.63
3 3 Matt $0.63
4 4 Mark $0.13
5 0 Tom $0.13
6 1 Jake $0.83
7 2 Greg $1.73
8 3 Bill $1.13
9 4 Joe $0.33
10 0 Bob $0.03
11 1 Matt $0.73
12 2 Mark $1.33
13 3 Tom $1.53
14 4 Jake $0.63
15 0 Greg $0.63
16 1 Bill $0.03
17 2 Joe $1.83
18 3 Bob $1.83
19 4 Matt $0.13
20 0 Mark $0.53
21 1 Tom $1.43
22 2 Jake $1.63
23 3 Greg $1.33
24 4 Bill $1.03
25 0 Joe $1.33
26 1 Bob $0.83
27 2 Matt $1.63
28 3 Mark $0.53
29 4 Tom $0.93
30 0 Jake $1.53
31 1 Greg $1.53
32 2 Bill $1.93
33 3 Joe $0.13
34 4 Bob $0.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 19.7 Bill $7.13 2019-07-29
1 868.8 Joe $64.24 2020-01-01
2 873.6 Bob $98.74 2018-12-05
3 637.1 Matt $28.34 2019-12-10
4 657 Mark $15.64 2019-09-02
5 717 Tom $39.44 2018-09-17
6 512.6 Jake $1.93 2020-04-16
7 158.3 Greg $42.04 2019-08-15
8 395.2 Adam $88.94 2018-10-31
9 126 Steve $85.04 2018-12-08

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-10-04
1 Joe 2021-01-29
2 Bob 2019-02-28
3 Matt 2020-01-03
4 Mark 2020-08-30
5 Tom 2021-03-12
6 Jake 2018-07-08
7 Greg 2020-04-06
8 Adam 2021-02-25
9 Steve 2019-02-13
10 George 2019-02-11
11 John 2018-11-19
12 Phil 2020-09-25
13 Jack 2021-03-12
14 Paul 2019-05-18
15 Rob 2018-11-29
16 Walt 2020-04-19
17 Nathan 2020-08-16
18 Dan 2019-04-20
19 Jeff 2018-10-02
20 Bill 2020-09-07
21 Joe 2021-04-08
22 Bob 2019-04-03
23 Matt 2018-11-06
24 Mark 2019-05-26
25 Tom 2020-07-04
26 Jake 2018-06-30
27 Greg 2019-11-27
28 Adam 2020-11-27
<< 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 904.9 Bill $69.34 2021-05-04
1 774.9 Joe $95.74 2019-11-09
2 513.7 Bob $86.44 2020-01-18
3 125.9 Matt $75.74 2020-11-04
4 375.2 Mark $93.44 2020-02-02