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 751.9 Bill $2.414 2018-09-25
1 108.1 Joe $60.495 2018-05-11
2 638 Bob $30.555 2019-02-10
3 331.4 Matt $80.905 2020-03-14
4 935.6 Mark $34.155 2018-03-22
tbody #2
5 844.1 Tom $95.565 2018-04-23
6 507.4 Jake $3.634 2017-05-07
7 54.5 Greg $21.925 2020-01-18
8 95.8 Adam $73.365 2017-08-10
9 994.2 Steve $55.495 2017-03-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 670.7 Bill $30.685 2017-04-06
1 191.8 Joe $41.485 2019-03-07
2 594.7 Bob $5.284 2020-02-24
3 234.7 Matt $38.415 2019-07-18
4 218.9 Mark $31.975 2017-06-15
5 578.7 Tom $16.375 2017-04-25
6 965.4 Jake $67.115 2017-06-06
7 48.9 Greg $72.565 2018-02-15
8 984.6 Adam $82.135 2017-04-12
9 150.8 Steve $81.545 2019-01-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 $0.43
1 1 Joe $1.03
2 2 Bob $1.93
3 3 Matt $0.53
4 4 Mark $1.43
5 0 Tom $0.73
6 1 Jake $1.83
7 2 Greg $0.63
8 3 Bill $0.83
9 4 Joe $1.83
10 0 Bob $1.03
11 1 Matt $1.63
12 2 Mark $1.33
13 3 Tom $1.53
14 4 Jake $0.23
15 0 Greg $1.53
16 1 Bill $0.63
17 2 Joe $0.53
18 3 Bob $1.73
19 4 Matt $0.53
20 0 Mark $1.93
21 1 Tom $1.93
22 2 Jake $0.63
23 3 Greg $1.33
24 4 Bill $0.63
25 0 Joe $0.63
26 1 Bob $1.03
27 2 Matt $0.73
28 3 Mark $0.93
29 4 Tom $0.63
30 0 Jake $1.93
31 1 Greg $1.33
32 2 Bill $1.63
33 3 Joe $1.83
34 4 Bob $1.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 455.9 Bill $22.04 2019-07-24
1 728.3 Joe $61.14 2019-02-25
2 235.4 Bob $38.74 2018-01-12
3 961.2 Matt $48.24 2017-04-16
4 265.8 Mark $74.14 2019-12-12
5 535.7 Tom $67.14 2019-10-13
6 854.5 Jake $32.64 2017-06-29
7 157.9 Greg $80.34 2018-07-27
8 612 Adam $9.53 2018-06-07
9 250.1 Steve $87.34 2018-01-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 2017-06-28
1 Joe 2018-02-14
2 Bob 2018-10-02
3 Matt 2019-12-21
4 Mark 2017-04-06
5 Tom 2017-07-08
6 Jake 2018-11-14
7 Greg 2018-01-03
8 Adam 2018-09-29
9 Steve 2019-10-28
10 George 2017-11-19
11 John 2017-02-06
12 Phil 2020-01-12
13 Jack 2018-09-23
14 Paul 2019-06-14
15 Rob 2019-09-22
16 Walt 2017-04-03
17 Nathan 2018-05-29
18 Dan 2019-04-04
19 Jeff 2019-12-18
20 Bill 2019-06-10
21 Joe 2019-09-01
22 Bob 2017-04-18
23 Matt 2018-10-25
24 Mark 2017-12-26
25 Tom 2019-03-27
26 Jake 2019-02-11
27 Greg 2019-05-03
28 Adam 2020-01-10
<< 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 514.4 Bill $1.93 2017-04-08
1 843.1 Joe $54.54 2020-02-27
2 900.1 Bob $68.34 2018-10-11
3 192.4 Matt $20.84 2018-05-07
4 445.9 Mark $21.44 2018-02-15