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 240.9 Bill $35.365 2019-07-27
1 976.1 Joe $75.465 2020-07-05
2 380.2 Bob $43.855 2019-02-03
3 392.7 Matt $74.945 2020-01-11
4 424.4 Mark $23.355 2018-08-20
tbody #2
5 167.2 Tom $80.125 2018-06-28
6 799.3 Jake $67.505 2017-12-03
7 848.8 Greg $39.775 2019-06-29
8 605.8 Adam $44.345 2018-01-22
9 497.9 Steve $6.684 2018-04-14
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 296 Bill $30.775 2019-05-28
1 873.1 Joe $28.375 2018-08-17
2 747.5 Bob $66.395 2020-01-06
3 173.7 Matt $5.654 2019-03-22
4 895.8 Mark $48.095 2019-12-17
5 177.6 Tom $64.805 2019-05-01
6 413.9 Jake $44.725 2018-04-20
7 471.4 Greg $29.605 2019-07-24
8 23.9 Adam $90.185 2017-10-18
9 124.3 Steve $39.965 2018-01-03

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.63
1 1 Joe $1.43
2 2 Bob $0.83
3 3 Matt $1.63
4 4 Mark $1.13
5 0 Tom $1.43
6 1 Jake $0.23
7 2 Greg $0.63
8 3 Bill $0.73
9 4 Joe $1.63
10 0 Bob $1.03
11 1 Matt $0.83
12 2 Mark $0.63
13 3 Tom $0.83
14 4 Jake $1.83
15 0 Greg $2.03
16 1 Bill $1.13
17 2 Joe $1.13
18 3 Bob $1.03
19 4 Matt $2.03
20 0 Mark $1.93
21 1 Tom $1.33
22 2 Jake $0.93
23 3 Greg $0.53
24 4 Bill $0.53
25 0 Joe $0.93
26 1 Bob $0.33
27 2 Matt $0.53
28 3 Mark $1.23
29 4 Tom $1.13
30 0 Jake $0.73
31 1 Greg $1.83
32 2 Bill $0.53
33 3 Joe $1.53
34 4 Bob $1.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 833.6 Bill $41.14 2020-04-25
1 149.6 Joe $75.14 2019-09-27
2 639.3 Bob $14.74 2020-08-23
3 24.6 Matt $2.43 2020-08-07
4 587.6 Mark $54.94 2018-12-24
5 564.4 Tom $52.24 2017-12-01
6 12.5 Jake $79.04 2018-09-04
7 484.4 Greg $96.04 2019-06-30
8 80.6 Adam $52.94 2020-07-30
9 972.5 Steve $79.44 2019-09-27

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-11-29
1 Joe 2019-09-24
2 Bob 2017-11-14
3 Matt 2019-04-26
4 Mark 2020-03-15
5 Tom 2020-04-01
6 Jake 2018-02-23
7 Greg 2019-01-22
8 Adam 2020-09-18
9 Steve 2017-11-18
10 George 2019-02-20
11 John 2020-10-16
12 Phil 2020-09-28
13 Jack 2017-10-31
14 Paul 2019-05-13
15 Rob 2018-10-24
16 Walt 2019-08-15
17 Nathan 2017-11-05
18 Dan 2018-12-28
19 Jeff 2019-08-29
20 Bill 2020-05-07
21 Joe 2019-12-05
22 Bob 2018-01-09
23 Matt 2020-03-22
24 Mark 2018-07-06
25 Tom 2018-04-13
26 Jake 2018-09-24
27 Greg 2018-03-07
28 Adam 2018-03-12
<< 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 106.6 Bill $76.94 2020-05-12
1 734.4 Joe $81.04 2018-10-09
2 511.8 Bob $60.24 2019-03-07
3 928.4 Matt $54.14 2019-04-27
4 369.5 Mark $50.44 2019-02-26