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 28.4 Bill $34.095 2013-01-28
1 862.7 Joe $71.905 2013-09-11
2 426.9 Bob $66.225 2012-09-01
3 198.3 Matt $58.045 2012-03-02
4 287.7 Mark $44.675 2013-12-23
tbody #2
5 574 Tom $5.764 2014-01-23
6 47.3 Jake $98.235 2012-03-17
7 759 Greg $8.754 2012-04-10
8 349.9 Adam $71.095 2014-08-01
9 950.8 Steve $40.855 2014-09-20
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 176.7 Bill $43.685 2012-08-18
1 536.8 Joe $29.945 2014-11-28
2 92.3 Bob $72.635 2013-11-02
3 324.2 Matt $92.465 2012-07-04
4 398 Mark $21.225 2013-12-03
5 42.9 Tom $78.625 2014-02-08
6 714.5 Jake $83.345 2014-01-18
7 800.7 Greg $59.235 2014-04-30
8 907.8 Adam $94.225 2013-05-30
9 743.7 Steve $89.295 2014-09-15

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

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 196 Bill $56.04 2014-09-16
1 894.6 Joe $89.74 2012-09-30
2 917.3 Bob $15.84 2014-07-13
3 337.9 Matt $63.14 2011-12-19
4 801.5 Mark $89.14 2014-09-27
5 979.5 Tom $98.34 2013-04-16
6 958.1 Jake $66.84 2014-03-27
7 844.6 Greg $29.64 2013-06-27
8 474.7 Adam $81.64 2012-05-05
9 727.3 Steve $40.54 2012-03-07

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 2014-07-16
1 Joe 2013-11-03
2 Bob 2013-12-15
3 Matt 2014-02-22
4 Mark 2013-07-04
5 Tom 2013-08-17
6 Jake 2014-12-16
7 Greg 2013-03-30
8 Adam 2014-02-16
9 Steve 2014-05-20
10 George 2014-04-25
11 John 2012-12-16
12 Phil 2014-05-31
13 Jack 2013-09-07
14 Paul 2012-08-11
15 Rob 2014-01-18
16 Walt 2013-08-14
17 Nathan 2012-07-23
18 Dan 2012-03-27
19 Jeff 2013-06-27
20 Bill 2014-09-05
21 Joe 2014-07-15
22 Bob 2012-12-29
23 Matt 2012-06-12
24 Mark 2012-12-02
25 Tom 2014-07-01
26 Jake 2015-01-12
27 Greg 2013-04-30
28 Adam 2013-08-20
<< 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 382.3 Bill $51.84 2013-01-25
1 983.5 Joe $15.64 2012-02-10
2 479.2 Bob $69.04 2011-12-18
3 892.2 Matt $38.24 2014-05-31
4 643 Mark $70.64 2013-09-21