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 742.4 Bill $57.175 2019-12-12
1 591.5 Joe $91.615 2021-07-10
2 426.5 Bob $30.685 2021-04-14
3 31.4 Matt $74.105 2019-09-14
4 378.6 Mark $95.085 2019-04-24
tbody #2
5 465.9 Tom $10.465 2021-06-23
6 924.9 Jake $66.865 2019-05-06
7 321.6 Greg $7.624 2021-07-12
8 651.1 Adam $33.375 2021-01-14
9 737.5 Steve $11.445 2021-08-21
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 762.9 Bill $85.685 2020-04-12
1 125.8 Joe $44.825 2020-01-06
2 986.9 Bob $87.475 2020-12-26
3 772.3 Matt $90.605 2020-03-01
4 58.6 Mark $28.465 2020-01-04
5 221.2 Tom $75.045 2020-05-05
6 67.2 Jake $67.535 2019-04-17
7 240.6 Greg $99.685 2019-07-14
8 103.1 Adam $64.785 2020-08-03
9 810.7 Steve $38.535 2020-12-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 $1.43
1 1 Joe $0.33
2 2 Bob $1.13
3 3 Matt $0.43
4 4 Mark $0.63
5 0 Tom $2.03
6 1 Jake $1.13
7 2 Greg $0.53
8 3 Bill $1.73
9 4 Joe $0.53
10 0 Bob $0.13
11 1 Matt $1.53
12 2 Mark $1.43
13 3 Tom $0.23
14 4 Jake $0.13
15 0 Greg $0.13
16 1 Bill $0.63
17 2 Joe $1.63
18 3 Bob $1.13
19 4 Matt $0.83
20 0 Mark $1.03
21 1 Tom $1.43
22 2 Jake $1.23
23 3 Greg $0.93
24 4 Bill $1.93
25 0 Joe $1.43
26 1 Bob $0.23
27 2 Matt $1.03
28 3 Mark $1.13
29 4 Tom $1.03
30 0 Jake $0.43
31 1 Greg $0.53
32 2 Bill $1.33
33 3 Joe $1.53
34 4 Bob $0.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 928.2 Bill $71.74 2021-11-25
1 188.9 Joe $57.74 2019-07-15
2 221.8 Bob $34.34 2021-09-16
3 313.2 Matt $39.44 2021-12-06
4 625.8 Mark $19.54 2020-07-11
5 5.5 Tom $67.14 2019-08-16
6 625.7 Jake $14.44 2019-06-15
7 349 Greg $26.54 2021-01-29
8 882.8 Adam $77.14 2021-09-10
9 124.6 Steve $42.54 2020-11-03

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-07-07
1 Joe 2019-12-01
2 Bob 2019-12-11
3 Matt 2020-06-15
4 Mark 2020-07-06
5 Tom 2021-10-08
6 Jake 2021-03-12
7 Greg 2021-03-20
8 Adam 2019-09-09
9 Steve 2020-12-09
10 George 2019-01-15
11 John 2020-12-07
12 Phil 2020-11-27
13 Jack 2021-01-08
14 Paul 2021-07-21
15 Rob 2019-06-21
16 Walt 2021-01-14
17 Nathan 2020-07-05
18 Dan 2020-04-18
19 Jeff 2019-11-08
20 Bill 2020-12-19
21 Joe 2020-12-14
22 Bob 2020-12-16
23 Matt 2021-10-22
24 Mark 2020-01-26
25 Tom 2020-08-02
26 Jake 2021-01-29
27 Greg 2019-10-18
28 Adam 2020-12-25
<< 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 146.5 Bill $96.14 2019-07-15
1 499.8 Joe $32.34 2021-03-12
2 42 Bob $26.24 2020-06-04
3 805.9 Matt $54.44 2019-05-27
4 882.9 Mark $21.94 2021-07-06