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 719.7 Bill $48.605 2021-08-17
1 375.1 Joe $77.925 2020-11-01
2 371.8 Bob $96.555 2020-10-21
3 161.2 Matt $99.295 2020-09-26
4 271.7 Mark $70.445 2020-09-13
tbody #2
5 346.9 Tom $69.305 2021-02-24
6 531.4 Jake $6.384 2021-03-08
7 884 Greg $25.595 2021-12-26
8 555.9 Adam $50.025 2020-01-05
9 230.9 Steve $73.215 2020-05-23
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 343.8 Bill $45.185 2021-12-06
1 124.6 Joe $82.685 2021-03-26
2 655.7 Bob $19.865 2021-02-14
3 177.3 Matt $35.985 2021-02-05
4 677.4 Mark $63.145 2020-02-29
5 166.2 Tom $97.835 2019-03-11
6 796.7 Jake $50.975 2019-05-24
7 437.8 Greg $39.365 2020-03-15
8 332.2 Adam $94.955 2021-10-14
9 604 Steve $18.035 2020-12-08

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 $2.03
1 1 Joe $1.13
2 2 Bob $0.03
3 3 Matt $1.83
4 4 Mark $1.33
5 0 Tom $1.73
6 1 Jake $1.13
7 2 Greg $0.63
8 3 Bill $0.13
9 4 Joe $0.33
10 0 Bob $1.03
11 1 Matt $0.83
12 2 Mark $1.53
13 3 Tom $0.33
14 4 Jake $0.13
15 0 Greg $0.23
16 1 Bill $0.73
17 2 Joe $0.03
18 3 Bob $0.23
19 4 Matt $0.23
20 0 Mark $1.03
21 1 Tom $0.33
22 2 Jake $1.13
23 3 Greg $1.83
24 4 Bill $1.03
25 0 Joe $1.83
26 1 Bob $1.73
27 2 Matt $0.73
28 3 Mark $1.03
29 4 Tom $0.13
30 0 Jake $1.83
31 1 Greg $1.03
32 2 Bill $1.13
33 3 Joe $1.83
34 4 Bob $0.73

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 215.6 Bill $75.74 2021-12-23
1 519.8 Joe $79.74 2019-04-15
2 1.3 Bob $19.84 2021-09-17
3 160.2 Matt $23.04 2021-12-24
4 485.1 Mark $24.04 2022-04-14
5 606.7 Tom $75.94 2019-08-30
6 166 Jake $67.24 2021-04-04
7 57.5 Greg $53.54 2019-02-25
8 553 Adam $57.84 2022-01-01
9 43.6 Steve $14.54 2021-09-24

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-06-10
1 Joe 2020-04-17
2 Bob 2020-12-16
3 Matt 2020-02-06
4 Mark 2021-12-09
5 Tom 2020-04-25
6 Jake 2020-03-26
7 Greg 2021-12-11
8 Adam 2020-12-10
9 Steve 2019-08-17
10 George 2019-04-14
11 John 2021-09-02
12 Phil 2019-04-14
13 Jack 2020-10-26
14 Paul 2019-04-06
15 Rob 2019-04-01
16 Walt 2019-07-29
17 Nathan 2021-08-31
18 Dan 2019-10-05
19 Jeff 2020-02-06
20 Bill 2020-08-17
21 Joe 2021-11-12
22 Bob 2020-04-12
23 Matt 2019-02-26
24 Mark 2021-11-12
25 Tom 2022-01-12
26 Jake 2020-12-25
27 Greg 2021-07-18
28 Adam 2022-03-04
<< 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 723 Bill $56.94 2020-04-16
1 83.1 Joe $14.04 2021-03-28
2 963 Bob $50.74 2022-04-27
3 844.1 Matt $7.33 2019-08-16
4 885.3 Mark $86.84 2019-10-04