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 171 Bill $66.935 2014-05-17
1 732.6 Joe $18.875 2015-03-13
2 646.9 Bob $53.005 2016-10-03
3 345.9 Matt $92.525 2014-12-26
4 667.3 Mark $82.775 2014-07-12
tbody #2
5 897.4 Tom $88.005 2017-04-16
6 33.5 Jake $73.245 2015-09-13
7 622 Greg $5.844 2014-12-05
8 11.8 Adam $58.425 2016-02-28
9 601.3 Steve $30.415 2015-12-08
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 553.2 Bill $47.515 2014-11-20
1 623.3 Joe $20.765 2015-06-27
2 952.3 Bob $85.445 2017-03-01
3 773.4 Matt $20.035 2016-12-04
4 36 Mark $86.755 2016-05-19
5 154.2 Tom $76.495 2016-01-01
6 143.9 Jake $79.845 2015-02-25
7 631.6 Greg $42.035 2015-05-04
8 876.3 Adam $43.205 2017-03-10
9 509.8 Steve $3.334 2014-12-25

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

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 111.3 Bill $42.54 2015-05-19
1 273.2 Joe $22.44 2014-05-06
2 208.5 Bob $22.34 2016-02-01
3 179.8 Matt $9.03 2016-11-19
4 305.1 Mark $72.14 2016-05-13
5 574.3 Tom $15.14 2016-11-03
6 475 Jake $0.13 2015-05-02
7 252 Greg $28.34 2016-11-10
8 538.8 Adam $59.84 2016-01-18
9 897.6 Steve $49.94 2014-05-27

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 2015-12-05
1 Joe 2016-02-02
2 Bob 2015-10-01
3 Matt 2017-02-25
4 Mark 2016-12-14
5 Tom 2016-06-17
6 Jake 2014-03-05
7 Greg 2014-06-12
8 Adam 2017-03-02
9 Steve 2016-02-09
10 George 2015-01-06
11 John 2014-04-13
12 Phil 2015-09-03
13 Jack 2015-12-25
14 Paul 2016-07-26
15 Rob 2014-09-18
16 Walt 2014-08-19
17 Nathan 2017-01-16
18 Dan 2014-03-26
19 Jeff 2016-02-20
20 Bill 2017-01-17
21 Joe 2015-06-01
22 Bob 2016-12-08
23 Matt 2014-10-10
24 Mark 2014-12-14
25 Tom 2015-06-23
26 Jake 2016-08-31
27 Greg 2016-11-05
28 Adam 2015-02-24
<< 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 292.8 Bill $92.94 2016-12-03
1 903.3 Joe $43.34 2016-10-03
2 787 Bob $16.14 2016-10-11
3 879.1 Matt $11.24 2015-07-26
4 151 Mark $15.24 2017-01-31