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 956.6 Bill $15.215 2011-09-15
1 923.2 Joe $52.505 2011-08-20
2 734.6 Bob $12.415 2010-02-19
3 567.7 Matt $81.955 2011-05-04
4 152.5 Mark $90.365 2011-03-13
tbody #2
5 716.6 Tom $11.125 2012-01-08
6 936.1 Jake $79.925 2010-06-11
7 393.8 Greg $34.515 2010-04-22
8 136.2 Adam $44.525 2012-06-14
9 448.6 Steve $42.805 2012-04-14
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 712.5 Bill $38.455 2012-10-07
1 241.2 Joe $30.775 2011-04-06
2 747.3 Bob $4.234 2011-08-28
3 780.9 Matt $60.995 2011-01-31
4 193.4 Mark $76.235 2010-10-11
5 561.1 Tom $47.885 2011-02-17
6 189 Jake $41.495 2010-06-29
7 318.9 Greg $80.865 2011-08-03
8 405.9 Adam $94.485 2012-12-30
9 170.4 Steve $39.335 2011-03-09

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.83
1 1 Joe $0.23
2 2 Bob $1.53
3 3 Matt $1.53
4 4 Mark $0.73
5 0 Tom $0.13
6 1 Jake $0.33
7 2 Greg $0.23
8 3 Bill $0.23
9 4 Joe $1.33
10 0 Bob $1.83
11 1 Matt $1.43
12 2 Mark $2.03
13 3 Tom $0.13
14 4 Jake $0.93
15 0 Greg $0.43
16 1 Bill $1.33
17 2 Joe $1.93
18 3 Bob $1.13
19 4 Matt $1.63
20 0 Mark $0.73
21 1 Tom $1.43
22 2 Jake $0.33
23 3 Greg $0.33
24 4 Bill $0.43
25 0 Joe $1.13
26 1 Bob $0.23
27 2 Matt $0.33
28 3 Mark $1.43
29 4 Tom $1.03
30 0 Jake $1.03
31 1 Greg $1.23
32 2 Bill $1.23
33 3 Joe $0.53
34 4 Bob $0.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 963.7 Bill $30.84 2011-07-18
1 57.9 Joe $40.64 2010-06-06
2 932.9 Bob $11.54 2010-05-14
3 1.3 Matt $58.54 2011-01-20
4 630.9 Mark $53.54 2012-11-03
5 449.4 Tom $89.94 2011-12-03
6 586.7 Jake $7.23 2012-07-23
7 129.9 Greg $19.04 2012-12-29
8 843.5 Adam $70.14 2011-06-02
9 439.5 Steve $31.84 2012-03-18

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 2012-07-04
1 Joe 2010-12-03
2 Bob 2013-03-09
3 Matt 2010-11-07
4 Mark 2011-02-08
5 Tom 2011-04-22
6 Jake 2011-04-02
7 Greg 2010-11-22
8 Adam 2011-09-01
9 Steve 2011-08-03
10 George 2010-11-23
11 John 2010-05-10
12 Phil 2012-08-11
13 Jack 2012-11-22
14 Paul 2012-01-19
15 Rob 2012-04-02
16 Walt 2011-02-24
17 Nathan 2011-09-24
18 Dan 2010-12-22
19 Jeff 2013-01-03
20 Bill 2011-12-17
21 Joe 2010-05-02
22 Bob 2010-04-02
23 Matt 2012-07-24
24 Mark 2010-02-16
25 Tom 2012-12-03
26 Jake 2011-08-13
27 Greg 2011-07-08
28 Adam 2011-02-23
<< 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 817.3 Bill $15.84 2010-06-16
1 98.5 Joe $15.44 2011-04-12
2 437.6 Bob $55.64 2012-06-30
3 709.5 Matt $7.23 2010-11-20
4 982.7 Mark $17.54 2010-04-19