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 119.3 Bill $74.345 2019-06-20
1 596.2 Joe $75.165 2018-02-06
2 874.3 Bob $38.275 2020-04-01
3 21 Matt $43.545 2020-01-06
4 537.8 Mark $35.945 2018-10-13
tbody #2
5 825.4 Tom $2.604 2020-06-26
6 749.2 Jake $19.735 2020-10-20
7 90.1 Greg $63.555 2018-11-26
8 617.6 Adam $39.645 2018-06-03
9 391.9 Steve $70.345 2020-12-31
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 758.5 Bill $82.275 2020-03-09
1 227.4 Joe $41.885 2019-05-26
2 265.3 Bob $29.315 2020-08-11
3 981.3 Matt $31.405 2018-10-27
4 622.8 Mark $85.175 2019-12-17
5 876.2 Tom $67.715 2020-01-16
6 667 Jake $42.635 2020-09-01
7 557.5 Greg $51.635 2019-07-07
8 849 Adam $13.395 2020-10-08
9 988.3 Steve $52.575 2019-10-30

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 $0.83
3 3 Matt $1.33
4 4 Mark $1.03
5 0 Tom $1.63
6 1 Jake $0.23
7 2 Greg $1.63
8 3 Bill $0.23
9 4 Joe $1.83
10 0 Bob $1.53
11 1 Matt $0.93
12 2 Mark $0.43
13 3 Tom $0.83
14 4 Jake $0.63
15 0 Greg $1.63
16 1 Bill $0.53
17 2 Joe $1.93
18 3 Bob $0.93
19 4 Matt $1.93
20 0 Mark $0.83
21 1 Tom $0.63
22 2 Jake $1.03
23 3 Greg $1.83
24 4 Bill $1.63
25 0 Joe $0.73
26 1 Bob $0.13
27 2 Matt $1.33
28 3 Mark $0.63
29 4 Tom $1.13
30 0 Jake $0.53
31 1 Greg $0.53
32 2 Bill $1.73
33 3 Joe $1.33
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 358 Bill $48.24 2021-02-01
1 134.7 Joe $59.94 2020-10-26
2 892.5 Bob $3.13 2018-03-22
3 273.1 Matt $31.44 2020-10-09
4 529.9 Mark $27.54 2019-01-19
5 453.6 Tom $66.14 2020-01-06
6 934.7 Jake $56.44 2019-05-06
7 264.7 Greg $60.14 2018-04-16
8 583 Adam $16.44 2019-02-01
9 842.3 Steve $1.03 2017-12-31

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 2020-04-27
1 Joe 2019-02-23
2 Bob 2019-07-11
3 Matt 2020-04-05
4 Mark 2019-07-29
5 Tom 2018-04-03
6 Jake 2019-12-06
7 Greg 2019-03-26
8 Adam 2018-05-09
9 Steve 2020-03-03
10 George 2020-02-05
11 John 2019-05-08
12 Phil 2019-10-18
13 Jack 2018-08-10
14 Paul 2020-03-21
15 Rob 2020-11-12
16 Walt 2020-01-17
17 Nathan 2019-02-23
18 Dan 2019-09-25
19 Jeff 2019-11-02
20 Bill 2020-12-07
21 Joe 2021-02-03
22 Bob 2020-09-04
23 Matt 2019-09-02
24 Mark 2018-03-27
25 Tom 2019-05-10
26 Jake 2020-03-09
27 Greg 2019-05-05
28 Adam 2018-11-08
<< 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 706.7 Bill $43.54 2018-01-10
1 74.6 Joe $92.34 2020-04-22
2 577.1 Bob $0.93 2019-02-01
3 972 Matt $12.74 2018-02-09
4 640.1 Mark $55.94 2019-12-04