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 2.1 Bill $11.145 2011-08-03
1 1.5 Joe $25.835 2010-08-27
2 900.2 Bob $10.785 2010-12-23
3 654.9 Matt $32.405 2010-01-19
4 120.8 Mark $92.525 2011-01-22
tbody #2
5 913.2 Tom $59.345 2011-08-12
6 521.7 Jake $71.105 2010-01-18
7 723.1 Greg $76.025 2011-10-21
8 207.2 Adam $75.305 2010-02-02
9 633.3 Steve $31.555 2011-07-23
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 22.5 Bill $31.765 2011-11-29
1 730.9 Joe $31.905 2009-07-24
2 144.7 Bob $21.915 2009-11-25
3 659.8 Matt $87.405 2010-12-05
4 883.3 Mark $99.485 2010-09-10
5 424.8 Tom $90.795 2009-05-27
6 140.4 Jake $42.955 2011-08-28
7 363 Greg $15.255 2010-11-23
8 139.3 Adam $35.975 2010-02-10
9 374.6 Steve $99.305 2011-02-11

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

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 886.9 Bill $16.34 2011-10-31
1 777.9 Joe $57.74 2012-03-27
2 328.6 Bob $86.54 2011-01-22
3 762.6 Matt $14.84 2011-03-25
4 621.4 Mark $33.84 2011-06-16
5 620.5 Tom $95.84 2010-10-30
6 982.5 Jake $73.04 2011-10-03
7 483.7 Greg $86.24 2010-04-12
8 359.4 Adam $98.74 2010-07-28
9 308.5 Steve $12.84 2010-06-22

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 2009-10-16
1 Joe 2009-05-22
2 Bob 2010-12-28
3 Matt 2012-04-11
4 Mark 2011-11-08
5 Tom 2009-08-25
6 Jake 2012-01-01
7 Greg 2009-09-22
8 Adam 2012-05-23
9 Steve 2010-07-19
10 George 2012-02-22
11 John 2009-09-09
12 Phil 2012-06-06
13 Jack 2010-12-10
14 Paul 2010-10-05
15 Rob 2011-05-18
16 Walt 2009-09-27
17 Nathan 2010-08-17
18 Dan 2009-09-10
19 Jeff 2009-09-07
20 Bill 2009-10-09
21 Joe 2012-02-07
22 Bob 2011-03-21
23 Matt 2012-07-03
24 Mark 2009-11-13
25 Tom 2012-05-10
26 Jake 2012-06-18
27 Greg 2011-02-05
28 Adam 2010-03-01
<< 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 112 Bill $90.94 2010-08-11
1 126.4 Joe $42.94 2010-05-18
2 918.5 Bob $52.64 2009-11-12
3 39.3 Matt $48.74 2011-01-25
4 922.5 Mark $59.74 2010-12-27