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 126.5 Bill $23.065 2008-07-07
1 994.2 Joe $35.535 2011-05-09
2 997.3 Bob $5.204 2010-12-30
3 998.9 Matt $99.465 2009-01-07
4 384.9 Mark $80.815 2009-06-13
tbody #2
5 476.7 Tom $13.685 2009-11-21
6 197.7 Jake $17.075 2011-02-18
7 331.3 Greg $99.515 2009-08-02
8 25.4 Adam $7.624 2010-09-14
9 309.7 Steve $6.844 2010-11-13
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 80.2 Bill $19.495 2008-06-05
1 132.7 Joe $18.905 2009-07-21
2 80.5 Bob $18.635 2009-09-19
3 915.8 Matt $18.515 2009-09-13
4 127.5 Mark $57.005 2009-02-03
5 474.3 Tom $4.674 2009-07-11
6 960.3 Jake $24.435 2010-01-25
7 838.9 Greg $57.565 2010-01-19
8 229.3 Adam $60.095 2010-04-17
9 972.3 Steve $91.065 2010-07-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 $1.53
1 1 Joe $2.03
2 2 Bob $1.83
3 3 Matt $1.63
4 4 Mark $0.23
5 0 Tom $0.13
6 1 Jake $0.33
7 2 Greg $0.43
8 3 Bill $0.53
9 4 Joe $1.23
10 0 Bob $0.23
11 1 Matt $0.93
12 2 Mark $0.13
13 3 Tom $0.53
14 4 Jake $0.03
15 0 Greg $0.53
16 1 Bill $1.43
17 2 Joe $0.13
18 3 Bob $1.33
19 4 Matt $1.43
20 0 Mark $0.63
21 1 Tom $0.43
22 2 Jake $1.13
23 3 Greg $1.83
24 4 Bill $1.43
25 0 Joe $1.53
26 1 Bob $0.93
27 2 Matt $0.73
28 3 Mark $1.43
29 4 Tom $0.83
30 0 Jake $0.03
31 1 Greg $1.03
32 2 Bill $0.83
33 3 Joe $1.83
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 498.8 Bill $95.54 2009-10-14
1 702.7 Joe $20.74 2008-07-13
2 822.3 Bob $64.44 2008-08-18
3 69.4 Matt $65.04 2009-06-23
4 790.7 Mark $70.44 2011-07-01
5 472.3 Tom $0.13 2008-11-24
6 992.7 Jake $87.54 2011-03-05
7 742.4 Greg $34.94 2009-01-19
8 464.4 Adam $73.34 2009-02-03
9 953.2 Steve $10.84 2008-09-28

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-02-02
1 Joe 2010-04-10
2 Bob 2008-08-07
3 Matt 2010-07-11
4 Mark 2009-04-30
5 Tom 2009-04-03
6 Jake 2010-09-16
7 Greg 2008-10-07
8 Adam 2011-04-18
9 Steve 2010-12-29
10 George 2008-12-26
11 John 2010-03-09
12 Phil 2008-12-13
13 Jack 2011-06-29
14 Paul 2009-03-31
15 Rob 2008-12-05
16 Walt 2009-10-26
17 Nathan 2009-04-02
18 Dan 2009-06-24
19 Jeff 2009-10-18
20 Bill 2008-11-07
21 Joe 2009-02-18
22 Bob 2008-12-24
23 Matt 2009-12-16
24 Mark 2009-11-02
25 Tom 2010-06-14
26 Jake 2009-02-10
27 Greg 2010-08-01
28 Adam 2010-04-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 349.2 Bill $83.04 2011-01-17
1 956.2 Joe $90.94 2010-01-19
2 265.8 Bob $19.54 2009-03-30
3 397.7 Matt $12.44 2008-09-19
4 598.9 Mark $70.44 2009-04-27