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 205 Bill $4.034 2021-08-04
1 885.9 Joe $88.435 2019-10-04
2 192.4 Bob $60.785 2022-03-08
3 508.2 Matt $79.935 2021-03-26
4 796.4 Mark $6.164 2021-06-03
tbody #2
5 769.2 Tom $13.105 2020-11-19
6 450.4 Jake $2.924 2020-05-15
7 885.1 Greg $25.495 2022-03-28
8 809.6 Adam $18.985 2021-05-31
9 956.7 Steve $78.795 2020-08-18
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 323.7 Bill $99.285 2020-10-04
1 991.9 Joe $87.875 2020-05-23
2 81.3 Bob $7.104 2022-04-26
3 935.7 Matt $57.925 2021-09-06
4 490.6 Mark $37.565 2021-11-16
5 105 Tom $14.485 2022-04-17
6 550.1 Jake $59.515 2022-05-20
7 832.9 Greg $48.025 2020-01-09
8 705 Adam $28.985 2020-08-16
9 317 Steve $24.645 2019-12-14

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.43
1 1 Joe $1.13
2 2 Bob $0.33
3 3 Matt $0.23
4 4 Mark $1.13
5 0 Tom $0.13
6 1 Jake $0.83
7 2 Greg $1.33
8 3 Bill $0.23
9 4 Joe $0.63
10 0 Bob $1.23
11 1 Matt $1.43
12 2 Mark $1.93
13 3 Tom $0.13
14 4 Jake $0.13
15 0 Greg $1.53
16 1 Bill $0.33
17 2 Joe $0.43
18 3 Bob $1.23
19 4 Matt $1.43
20 0 Mark $1.63
21 1 Tom $1.13
22 2 Jake $1.13
23 3 Greg $0.53
24 4 Bill $1.43
25 0 Joe $0.53
26 1 Bob $1.13
27 2 Matt $0.13
28 3 Mark $1.23
29 4 Tom $1.63
30 0 Jake $0.53
31 1 Greg $0.53
32 2 Bill $0.83
33 3 Joe $0.73
34 4 Bob $0.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 935.4 Bill $38.64 2021-10-08
1 578.4 Joe $47.94 2022-08-21
2 157 Bob $15.14 2022-07-17
3 226.2 Matt $19.94 2021-09-05
4 400.4 Mark $39.14 2020-06-19
5 124.5 Tom $17.94 2022-02-28
6 681.6 Jake $44.64 2021-03-26
7 943.6 Greg $0.43 2021-06-16
8 522.6 Adam $80.74 2022-02-27
9 783.4 Steve $18.14 2020-02-22

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-11-22
1 Joe 2019-11-04
2 Bob 2021-05-14
3 Matt 2022-03-09
4 Mark 2021-09-04
5 Tom 2019-09-19
6 Jake 2022-03-06
7 Greg 2022-03-04
8 Adam 2020-03-12
9 Steve 2022-01-28
10 George 2019-09-21
11 John 2020-10-28
12 Phil 2021-02-10
13 Jack 2020-12-27
14 Paul 2022-01-24
15 Rob 2022-02-06
16 Walt 2021-05-20
17 Nathan 2022-08-19
18 Dan 2021-08-14
19 Jeff 2020-05-17
20 Bill 2020-11-16
21 Joe 2020-03-17
22 Bob 2020-03-12
23 Matt 2020-11-21
24 Mark 2022-03-11
25 Tom 2021-11-07
26 Jake 2020-04-12
27 Greg 2021-09-14
28 Adam 2021-03-01
<< 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 434.8 Bill $91.44 2021-07-31
1 551 Joe $51.14 2021-02-14
2 245.6 Bob $58.74 2020-08-28
3 97.1 Matt $81.54 2020-02-03
4 174.7 Mark $24.14 2021-09-23