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 633 Bill $90.475 2016-05-13
1 359.2 Joe $73.905 2015-08-28
2 375.2 Bob $52.405 2016-08-27
3 526.9 Matt $88.155 2016-06-15
4 606.9 Mark $9.414 2014-10-01
tbody #2
5 890.9 Tom $90.215 2015-12-02
6 494 Jake $17.635 2016-01-21
7 284.1 Greg $66.195 2014-07-29
8 974.5 Adam $14.285 2016-05-15
9 671.8 Steve $13.345 2015-11-16
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 863.8 Bill $76.645 2015-07-29
1 483.9 Joe $12.555 2014-09-30
2 880.1 Bob $50.065 2016-05-28
3 591.1 Matt $2.754 2016-01-12
4 239.3 Mark $63.435 2016-04-30
5 349.2 Tom $52.525 2016-01-08
6 828.1 Jake $1.914 2016-07-30
7 349.8 Greg $30.325 2015-07-04
8 404.3 Adam $27.765 2015-12-17
9 26 Steve $94.935 2016-05-19

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.03
1 1 Joe $1.63
2 2 Bob $0.83
3 3 Matt $1.73
4 4 Mark $0.63
5 0 Tom $1.03
6 1 Jake $1.93
7 2 Greg $0.43
8 3 Bill $0.03
9 4 Joe $1.23
10 0 Bob $1.53
11 1 Matt $0.13
12 2 Mark $0.23
13 3 Tom $0.03
14 4 Jake $1.43
15 0 Greg $1.53
16 1 Bill $0.73
17 2 Joe $0.43
18 3 Bob $0.53
19 4 Matt $0.43
20 0 Mark $0.53
21 1 Tom $1.93
22 2 Jake $1.13
23 3 Greg $1.13
24 4 Bill $0.63
25 0 Joe $1.93
26 1 Bob $1.63
27 2 Matt $1.53
28 3 Mark $1.93
29 4 Tom $1.53
30 0 Jake $0.83
31 1 Greg $0.93
32 2 Bill $1.13
33 3 Joe $1.63
34 4 Bob $0.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 863 Bill $29.64 2015-04-25
1 40 Joe $31.44 2017-03-23
2 808.1 Bob $35.84 2014-06-06
3 815.4 Matt $3.73 2016-09-23
4 171.8 Mark $24.14 2017-06-24
5 356.3 Tom $46.44 2017-03-28
6 890.6 Jake $99.04 2014-12-06
7 829.1 Greg $79.44 2017-05-08
8 793.5 Adam $54.74 2015-06-01
9 249.3 Steve $11.34 2014-09-19

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 2016-03-12
1 Joe 2017-06-29
2 Bob 2015-08-28
3 Matt 2017-02-08
4 Mark 2014-06-14
5 Tom 2016-08-25
6 Jake 2016-10-05
7 Greg 2017-01-04
8 Adam 2014-08-13
9 Steve 2016-10-15
10 George 2016-06-04
11 John 2014-09-24
12 Phil 2015-12-13
13 Jack 2016-12-20
14 Paul 2015-06-30
15 Rob 2015-11-10
16 Walt 2014-12-06
17 Nathan 2016-12-18
18 Dan 2015-07-12
19 Jeff 2014-08-01
20 Bill 2016-12-06
21 Joe 2016-01-21
22 Bob 2017-03-18
23 Matt 2016-04-12
24 Mark 2015-11-03
25 Tom 2016-07-22
26 Jake 2014-11-04
27 Greg 2016-11-07
28 Adam 2017-05-06
<< 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 252.1 Bill $87.34 2015-12-22
1 227.9 Joe $26.94 2015-07-06
2 243.6 Bob $97.84 2014-09-13
3 67.3 Matt $4.53 2017-02-01
4 706.4 Mark $14.94 2015-06-20