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 546.2 Bill $47.025 2017-10-26
1 160.6 Joe $56.665 2019-05-09
2 935.2 Bob $34.125 2019-11-21
3 603.6 Matt $38.335 2017-10-14
4 9.2 Mark $49.445 2017-10-21
tbody #2
5 148.2 Tom $43.925 2020-08-24
6 116.1 Jake $17.965 2017-09-20
7 336.6 Greg $77.315 2020-06-29
8 807.4 Adam $76.135 2020-05-22
9 808 Steve $82.675 2020-01-25
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 109 Bill $37.295 2018-05-21
1 184.5 Joe $53.355 2020-03-07
2 744.3 Bob $46.865 2018-02-04
3 472.7 Matt $7.214 2019-04-23
4 538.2 Mark $8.124 2017-09-15
5 609.8 Tom $22.945 2019-02-05
6 578.1 Jake $34.545 2019-09-01
7 622.9 Greg $68.195 2018-12-12
8 542.2 Adam $48.935 2018-03-11
9 428.9 Steve $29.725 2017-08-22

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

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 587.5 Bill $14.04 2017-11-22
1 922.4 Joe $53.44 2019-04-29
2 730 Bob $0.13 2019-04-27
3 75.7 Matt $54.84 2019-06-10
4 31.1 Mark $32.54 2017-11-28
5 564.6 Tom $44.84 2018-06-20
6 720.9 Jake $25.24 2020-05-24
7 419.4 Greg $54.54 2019-10-07
8 546.7 Adam $13.64 2019-03-13
9 887.6 Steve $13.24 2019-11-16

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-15
1 Joe 2019-11-11
2 Bob 2020-04-25
3 Matt 2020-02-06
4 Mark 2019-08-13
5 Tom 2018-11-03
6 Jake 2018-09-05
7 Greg 2018-10-04
8 Adam 2018-11-04
9 Steve 2020-06-01
10 George 2018-12-31
11 John 2020-07-30
12 Phil 2019-02-09
13 Jack 2019-02-05
14 Paul 2018-06-10
15 Rob 2019-06-10
16 Walt 2017-09-19
17 Nathan 2019-11-10
18 Dan 2020-04-29
19 Jeff 2020-01-01
20 Bill 2020-08-28
21 Joe 2019-12-22
22 Bob 2018-02-28
23 Matt 2019-03-20
24 Mark 2018-12-28
25 Tom 2019-11-23
26 Jake 2019-08-24
27 Greg 2020-08-10
28 Adam 2019-07-16
<< 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 784.8 Bill $68.04 2018-07-30
1 504.7 Joe $54.44 2017-12-05
2 147 Bob $94.24 2019-01-10
3 519.3 Matt $34.04 2018-09-11
4 967.2 Mark $28.74 2020-03-23