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 225.8 Bill $17.305 2019-11-29
1 46.1 Joe $87.855 2020-12-16
2 777.1 Bob $43.935 2021-06-16
3 630.4 Matt $71.085 2019-03-25
4 238.7 Mark $51.585 2019-08-02
tbody #2
5 66 Tom $82.495 2020-06-21
6 228 Jake $49.535 2019-08-07
7 249.7 Greg $65.075 2019-01-15
8 100.6 Adam $57.125 2018-11-13
9 937.3 Steve $8.764 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 808.9 Bill $31.345 2019-07-15
1 231 Joe $35.955 2019-02-24
2 983.8 Bob $13.665 2020-07-17
3 893.9 Matt $76.695 2019-08-17
4 100.7 Mark $0.564 2021-04-05
5 419.8 Tom $7.164 2020-09-14
6 19.1 Jake $29.965 2019-02-08
7 342.8 Greg $54.925 2021-03-02
8 490.4 Adam $64.975 2019-10-23
9 583.4 Steve $58.705 2020-02-01

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

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 238.4 Bill $46.94 2019-10-25
1 849 Joe $75.54 2019-04-01
2 353.4 Bob $80.94 2019-09-26
3 958.4 Matt $86.84 2019-09-27
4 983.2 Mark $99.84 2018-09-15
5 27.1 Tom $42.84 2021-05-16
6 413.7 Jake $40.84 2020-04-18
7 290.7 Greg $3.63 2020-06-15
8 751 Adam $25.24 2018-12-16
9 925.4 Steve $86.44 2019-12-20

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-12-12
1 Joe 2018-11-24
2 Bob 2021-06-14
3 Matt 2020-03-09
4 Mark 2021-08-02
5 Tom 2020-09-04
6 Jake 2020-11-11
7 Greg 2019-07-16
8 Adam 2020-01-26
9 Steve 2018-11-09
10 George 2019-05-29
11 John 2019-08-26
12 Phil 2020-01-08
13 Jack 2019-05-09
14 Paul 2019-08-24
15 Rob 2020-02-25
16 Walt 2019-06-10
17 Nathan 2021-01-01
18 Dan 2019-10-13
19 Jeff 2020-09-30
20 Bill 2019-02-15
21 Joe 2021-07-04
22 Bob 2021-09-02
23 Matt 2019-03-29
24 Mark 2020-03-21
25 Tom 2020-11-17
26 Jake 2020-01-15
27 Greg 2020-08-09
28 Adam 2020-08-23
<< 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 326.4 Bill $8.13 2021-01-06
1 428.5 Joe $99.04 2019-06-18
2 379.5 Bob $65.34 2018-08-01
3 683.9 Matt $12.64 2018-11-12
4 946.6 Mark $46.64 2020-04-24