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 912.4 Bill $95.445 2017-06-11
1 39.7 Joe $22.445 2015-12-31
2 876.6 Bob $64.265 2015-10-07
3 912.5 Matt $56.565 2017-08-03
4 247.6 Mark $24.275 2016-12-06
tbody #2
5 21.5 Tom $36.415 2017-05-29
6 872.9 Jake $34.735 2017-09-23
7 200.9 Greg $96.915 2017-01-03
8 378.8 Adam $49.495 2016-02-20
9 968.6 Steve $54.965 2016-03-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 147.4 Bill $46.195 2016-01-15
1 0.8 Joe $50.155 2016-10-01
2 398.2 Bob $37.805 2015-08-14
3 721.7 Matt $29.055 2017-05-30
4 620.7 Mark $53.805 2015-01-04
5 312.4 Tom $55.945 2016-02-29
6 154.4 Jake $43.235 2017-04-06
7 97.3 Greg $63.325 2017-03-01
8 813.4 Adam $1.204 2015-07-26
9 255 Steve $98.055 2017-04-22

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.43
1 1 Joe $0.33
2 2 Bob $0.63
3 3 Matt $0.23
4 4 Mark $0.33
5 0 Tom $1.63
6 1 Jake $1.53
7 2 Greg $1.13
8 3 Bill $0.33
9 4 Joe $0.13
10 0 Bob $0.53
11 1 Matt $0.93
12 2 Mark $1.83
13 3 Tom $1.73
14 4 Jake $2.03
15 0 Greg $1.93
16 1 Bill $0.43
17 2 Joe $1.13
18 3 Bob $0.83
19 4 Matt $0.73
20 0 Mark $1.93
21 1 Tom $0.43
22 2 Jake $0.93
23 3 Greg $1.23
24 4 Bill $1.93
25 0 Joe $0.53
26 1 Bob $1.23
27 2 Matt $0.53
28 3 Mark $1.03
29 4 Tom $1.23
30 0 Jake $0.13
31 1 Greg $0.43
32 2 Bill $1.43
33 3 Joe $0.63
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 853.2 Bill $8.83 2015-01-09
1 379.9 Joe $24.04 2015-02-16
2 628.3 Bob $68.24 2017-11-26
3 497.2 Matt $66.14 2017-10-12
4 678.5 Mark $20.04 2015-11-30
5 14.1 Tom $17.24 2016-07-26
6 447 Jake $77.64 2016-06-25
7 693.3 Greg $39.24 2017-03-22
8 194.6 Adam $98.94 2017-05-11
9 406.8 Steve $71.44 2015-03-10

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 2017-01-31
1 Joe 2016-07-15
2 Bob 2015-06-20
3 Matt 2017-05-15
4 Mark 2017-09-27
5 Tom 2016-03-24
6 Jake 2017-10-04
7 Greg 2016-07-24
8 Adam 2015-03-21
9 Steve 2017-10-02
10 George 2014-12-20
11 John 2017-04-25
12 Phil 2017-08-16
13 Jack 2017-02-12
14 Paul 2014-10-12
15 Rob 2015-08-18
16 Walt 2017-03-01
17 Nathan 2015-04-29
18 Dan 2017-06-16
19 Jeff 2015-05-30
20 Bill 2017-10-13
21 Joe 2016-01-12
22 Bob 2017-08-10
23 Matt 2015-11-09
24 Mark 2015-05-06
25 Tom 2015-01-21
26 Jake 2015-10-28
27 Greg 2014-10-17
28 Adam 2016-05-05
<< 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 56 Bill $15.94 2015-07-10
1 623.2 Joe $38.94 2014-12-25
2 570.2 Bob $85.84 2014-10-31
3 145.4 Matt $1.03 2017-11-05
4 217.8 Mark $82.24 2017-07-24