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 825.7 Bill $35.565 2019-01-03
1 126.1 Joe $22.355 2018-01-03
2 905.1 Bob $6.884 2016-10-23
3 959.6 Matt $61.985 2018-02-13
4 827.8 Mark $8.504 2019-04-03
tbody #2
5 453.6 Tom $76.525 2017-08-31
6 105 Jake $99.645 2018-07-20
7 42.8 Greg $37.195 2019-11-28
8 95.5 Adam $7.104 2017-03-12
9 968.5 Steve $76.995 2017-01-04
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 195.8 Bill $59.555 2018-02-20
1 901.3 Joe $72.155 2018-11-05
2 291.3 Bob $62.655 2019-01-24
3 304.3 Matt $58.615 2017-11-10
4 730.4 Mark $41.395 2018-02-16
5 514.1 Tom $86.745 2017-05-20
6 796.5 Jake $97.235 2017-05-16
7 358 Greg $1.514 2018-07-20
8 347.7 Adam $11.065 2018-10-11
9 481.4 Steve $7.904 2018-01-17

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

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 840.7 Bill $83.84 2017-05-16
1 307.9 Joe $18.44 2018-07-16
2 79.3 Bob $11.64 2017-08-17
3 581.1 Matt $46.24 2018-01-26
4 597 Mark $67.54 2019-02-16
5 409.3 Tom $86.14 2017-08-14
6 579.5 Jake $6.13 2017-11-21
7 97.3 Greg $37.24 2016-12-30
8 96.6 Adam $76.24 2017-05-19
9 653.3 Steve $42.74 2017-10-04

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 2017-05-27
1 Joe 2017-08-14
2 Bob 2017-03-31
3 Matt 2018-01-02
4 Mark 2018-08-05
5 Tom 2017-10-30
6 Jake 2019-10-10
7 Greg 2018-11-05
8 Adam 2018-03-14
9 Steve 2017-06-17
10 George 2017-07-08
11 John 2019-08-31
12 Phil 2018-10-05
13 Jack 2019-05-30
14 Paul 2018-08-20
15 Rob 2017-12-13
16 Walt 2017-07-15
17 Nathan 2018-03-12
18 Dan 2018-10-19
19 Jeff 2019-05-17
20 Bill 2018-05-22
21 Joe 2019-12-02
22 Bob 2019-09-06
23 Matt 2019-07-26
24 Mark 2016-12-22
25 Tom 2016-10-25
26 Jake 2018-10-24
27 Greg 2017-08-02
28 Adam 2018-11-21
<< 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 71 Bill $56.94 2019-07-09
1 338.4 Joe $71.94 2017-08-01
2 913.6 Bob $5.43 2017-06-02
3 568.1 Matt $50.54 2018-02-09
4 803.6 Mark $41.84 2016-12-05