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 758.5 Bill $40.935 2020-05-18
1 878.3 Joe $49.745 2019-09-18
2 361.8 Bob $47.415 2018-09-13
3 905.6 Matt $85.445 2019-07-08
4 220.9 Mark $17.665 2020-07-30
tbody #2
5 62.9 Tom $5.964 2019-08-09
6 128.1 Jake $66.405 2017-11-12
7 145.4 Greg $22.315 2018-10-17
8 819.8 Adam $97.905 2019-03-06
9 998.6 Steve $20.485 2017-11-09
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 142.9 Bill $96.335 2019-02-26
1 975.8 Joe $84.155 2020-09-23
2 598.6 Bob $20.335 2019-01-23
3 902 Matt $10.895 2018-08-08
4 462 Mark $32.985 2019-02-28
5 357.3 Tom $39.265 2019-05-08
6 945.1 Jake $52.065 2018-04-14
7 984.9 Greg $66.605 2018-12-28
8 317.3 Adam $48.575 2018-12-04
9 770.6 Steve $48.435 2019-07-29

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.63
1 1 Joe $1.33
2 2 Bob $1.13
3 3 Matt $0.53
4 4 Mark $1.23
5 0 Tom $0.83
6 1 Jake $0.43
7 2 Greg $0.43
8 3 Bill $1.23
9 4 Joe $1.23
10 0 Bob $0.23
11 1 Matt $1.43
12 2 Mark $1.83
13 3 Tom $1.13
14 4 Jake $0.13
15 0 Greg $0.73
16 1 Bill $1.93
17 2 Joe $0.83
18 3 Bob $1.73
19 4 Matt $1.73
20 0 Mark $1.93
21 1 Tom $0.03
22 2 Jake $1.73
23 3 Greg $1.23
24 4 Bill $0.83
25 0 Joe $0.33
26 1 Bob $0.23
27 2 Matt $1.63
28 3 Mark $1.93
29 4 Tom $1.13
30 0 Jake $0.73
31 1 Greg $1.53
32 2 Bill $0.43
33 3 Joe $1.83
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 804 Bill $28.64 2018-05-14
1 5.3 Joe $87.34 2020-04-24
2 108.6 Bob $56.84 2019-12-14
3 673.8 Matt $59.34 2017-11-03
4 596.3 Mark $1.13 2020-07-05
5 463.9 Tom $94.94 2020-07-21
6 316.4 Jake $55.34 2018-09-05
7 486.1 Greg $64.34 2017-12-28
8 426.3 Adam $21.74 2019-02-19
9 173.9 Steve $41.84 2018-10-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 2018-04-18
1 Joe 2018-06-12
2 Bob 2019-09-26
3 Matt 2018-12-03
4 Mark 2018-06-18
5 Tom 2019-05-01
6 Jake 2018-04-29
7 Greg 2018-10-21
8 Adam 2017-12-18
9 Steve 2020-07-15
10 George 2017-10-09
11 John 2019-11-04
12 Phil 2020-08-21
13 Jack 2019-08-30
14 Paul 2019-11-17
15 Rob 2020-03-28
16 Walt 2017-12-17
17 Nathan 2019-09-19
18 Dan 2019-11-19
19 Jeff 2018-12-19
20 Bill 2018-04-20
21 Joe 2020-10-27
22 Bob 2020-07-03
23 Matt 2020-05-04
24 Mark 2017-11-26
25 Tom 2018-09-08
26 Jake 2017-11-10
27 Greg 2019-04-19
28 Adam 2019-03-28
<< 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 455.7 Bill $83.54 2019-10-17
1 678 Joe $46.44 2017-10-21
2 905.5 Bob $96.64 2018-05-22
3 241.6 Matt $3.63 2018-01-06
4 251.5 Mark $70.04 2017-09-29