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 654 Bill $22.285 2021-07-15
1 882.1 Joe $25.605 2020-12-30
2 374.3 Bob $58.565 2021-03-04
3 387.1 Matt $33.755 2020-08-14
4 292.1 Mark $5.034 2021-03-15
tbody #2
5 847.3 Tom $16.125 2019-04-27
6 821.8 Jake $1.594 2019-05-14
7 137.2 Greg $82.925 2019-04-08
8 88 Adam $28.495 2019-04-16
9 327.8 Steve $17.645 2019-09-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 108.6 Bill $83.045 2020-06-11
1 78.4 Joe $71.245 2021-04-03
2 878 Bob $8.664 2019-12-10
3 733.1 Matt $47.365 2021-01-04
4 413.8 Mark $76.575 2021-03-03
5 278.4 Tom $61.295 2018-07-06
6 548.6 Jake $43.475 2018-07-24
7 833.2 Greg $57.195 2021-03-10
8 86.7 Adam $65.985 2018-12-03
9 347.3 Steve $98.765 2019-06-25

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

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 726.8 Bill $76.54 2020-08-03
1 779.1 Joe $71.54 2019-09-14
2 564.5 Bob $13.94 2021-05-13
3 763.6 Matt $32.94 2019-05-25
4 241.1 Mark $13.14 2020-08-22
5 267.1 Tom $36.84 2018-10-25
6 126.3 Jake $17.74 2019-09-19
7 72.1 Greg $64.54 2021-01-28
8 365.2 Adam $10.24 2020-04-13
9 407.5 Steve $65.44 2019-12-21

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-27
1 Joe 2019-09-02
2 Bob 2019-03-24
3 Matt 2020-01-11
4 Mark 2018-12-20
5 Tom 2021-06-29
6 Jake 2021-04-08
7 Greg 2020-10-04
8 Adam 2018-10-07
9 Steve 2021-01-01
10 George 2020-01-04
11 John 2019-10-22
12 Phil 2018-10-07
13 Jack 2020-10-09
14 Paul 2020-03-22
15 Rob 2020-12-10
16 Walt 2021-08-14
17 Nathan 2021-05-22
18 Dan 2021-04-18
19 Jeff 2018-11-07
20 Bill 2018-10-12
21 Joe 2019-05-19
22 Bob 2019-01-29
23 Matt 2020-10-28
24 Mark 2018-10-27
25 Tom 2020-03-27
26 Jake 2021-02-23
27 Greg 2020-08-22
28 Adam 2021-07-11
<< 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 500.7 Bill $16.34 2020-12-19
1 881.3 Joe $40.44 2019-05-14
2 40.9 Bob $36.04 2019-01-01
3 765 Matt $45.54 2021-07-16
4 252.7 Mark $87.94 2018-09-03