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 370.5 Bill $13.615 2020-02-12
1 721.2 Joe $23.195 2018-07-06
2 278.9 Bob $0.684 2019-04-25
3 559 Matt $64.135 2020-01-02
4 148 Mark $65.605 2017-07-27
tbody #2
5 274.4 Tom $54.465 2018-03-15
6 403.7 Jake $23.975 2017-03-11
7 449.9 Greg $46.395 2017-05-02
8 7 Adam $12.065 2020-02-22
9 666.4 Steve $86.795 2018-08-29
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 541.2 Bill $23.845 2019-02-02
1 528.1 Joe $95.965 2019-10-29
2 8.6 Bob $23.845 2019-11-06
3 743 Matt $79.745 2018-09-16
4 695 Mark $94.535 2017-08-14
5 878.7 Tom $21.975 2019-05-07
6 262.1 Jake $62.335 2020-02-08
7 326.5 Greg $7.324 2018-05-28
8 435.9 Adam $8.014 2018-10-15
9 431.7 Steve $74.645 2018-05-15

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.93
1 1 Joe $0.63
2 2 Bob $1.43
3 3 Matt $1.23
4 4 Mark $1.63
5 0 Tom $1.33
6 1 Jake $1.03
7 2 Greg $1.63
8 3 Bill $1.83
9 4 Joe $0.83
10 0 Bob $1.13
11 1 Matt $1.33
12 2 Mark $1.93
13 3 Tom $0.53
14 4 Jake $1.23
15 0 Greg $0.33
16 1 Bill $0.33
17 2 Joe $1.73
18 3 Bob $1.83
19 4 Matt $0.83
20 0 Mark $0.93
21 1 Tom $1.83
22 2 Jake $1.53
23 3 Greg $1.13
24 4 Bill $0.73
25 0 Joe $0.33
26 1 Bob $1.23
27 2 Matt $1.83
28 3 Mark $1.23
29 4 Tom $0.73
30 0 Jake $0.73
31 1 Greg $1.13
32 2 Bill $1.33
33 3 Joe $0.03
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 460.3 Bill $65.04 2019-03-13
1 284.4 Joe $52.24 2017-05-11
2 851.5 Bob $19.24 2017-03-30
3 113.5 Matt $80.74 2017-10-05
4 254.3 Mark $64.14 2017-06-19
5 657 Tom $9.83 2017-02-13
6 386.3 Jake $62.94 2018-03-11
7 551.4 Greg $24.04 2017-11-23
8 148.2 Adam $59.74 2018-12-24
9 704.2 Steve $24.24 2019-01-12

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-10-14
1 Joe 2019-03-19
2 Bob 2017-12-03
3 Matt 2018-10-29
4 Mark 2020-02-11
5 Tom 2019-07-30
6 Jake 2019-03-13
7 Greg 2019-08-23
8 Adam 2017-01-06
9 Steve 2019-06-15
10 George 2020-01-01
11 John 2019-07-28
12 Phil 2017-01-21
13 Jack 2017-08-21
14 Paul 2018-06-07
15 Rob 2017-07-15
16 Walt 2019-09-20
17 Nathan 2018-09-29
18 Dan 2017-09-02
19 Jeff 2017-10-10
20 Bill 2017-07-27
21 Joe 2018-11-15
22 Bob 2019-07-10
23 Matt 2018-04-30
24 Mark 2019-10-13
25 Tom 2019-12-28
26 Jake 2017-01-19
27 Greg 2018-08-09
28 Adam 2019-01-20
<< 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 261.7 Bill $15.54 2018-09-07
1 963.5 Joe $45.04 2017-05-08
2 949.5 Bob $26.74 2019-07-24
3 787 Matt $27.64 2018-11-10
4 737.9 Mark $9.13 2018-12-05