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 836.2 Bill $74.185 2016-02-16
1 407.8 Joe $86.475 2015-07-10
2 397.1 Bob $4.824 2016-11-10
3 305.1 Matt $44.265 2016-05-26
4 648.1 Mark $76.745 2017-12-31
tbody #2
5 551.8 Tom $24.585 2015-04-05
6 303.2 Jake $81.005 2015-10-30
7 207.9 Greg $46.035 2015-04-19
8 554 Adam $18.735 2017-09-04
9 159.4 Steve $79.765 2017-02-09
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 129.9 Bill $63.385 2016-04-16
1 462 Joe $4.154 2015-11-12
2 603.3 Bob $43.865 2016-01-06
3 166.9 Matt $74.375 2017-06-02
4 585.1 Mark $39.175 2016-09-05
5 508.2 Tom $94.355 2017-06-17
6 566.7 Jake $24.675 2016-11-09
7 804.6 Greg $45.465 2015-02-23
8 874.9 Adam $0.854 2015-09-28
9 695.9 Steve $16.795 2015-02-05

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

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 134.8 Bill $39.44 2016-12-18
1 497.7 Joe $51.54 2017-10-24
2 27.4 Bob $38.04 2017-11-02
3 142.2 Matt $63.64 2016-04-19
4 765.2 Mark $83.64 2017-02-22
5 954.8 Tom $28.34 2016-08-08
6 949 Jake $18.44 2016-02-18
7 818 Greg $9.43 2016-04-30
8 382.9 Adam $17.14 2016-07-19
9 286.1 Steve $54.74 2015-08-20

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-12-18
1 Joe 2017-03-26
2 Bob 2016-11-17
3 Matt 2016-09-07
4 Mark 2015-08-23
5 Tom 2015-05-05
6 Jake 2016-04-03
7 Greg 2015-09-23
8 Adam 2016-07-18
9 Steve 2015-11-07
10 George 2016-03-06
11 John 2015-05-24
12 Phil 2017-01-27
13 Jack 2015-06-08
14 Paul 2018-01-16
15 Rob 2015-12-23
16 Walt 2015-04-17
17 Nathan 2015-10-09
18 Dan 2017-07-03
19 Jeff 2015-02-17
20 Bill 2016-05-09
21 Joe 2015-05-24
22 Bob 2017-09-21
23 Matt 2016-08-26
24 Mark 2016-08-25
25 Tom 2015-10-07
26 Jake 2017-03-12
27 Greg 2018-02-14
28 Adam 2016-09-02
<< 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 215.7 Bill $13.84 2016-05-23
1 897 Joe $70.84 2018-01-01
2 75.9 Bob $79.24 2016-01-06
3 282.2 Matt $25.64 2016-10-16
4 630.7 Mark $35.64 2015-08-16