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 624 Bill $59.735 2015-08-14
1 713 Joe $99.605 2014-07-28
2 128.7 Bob $71.215 2015-01-21
3 850.2 Matt $8.314 2016-06-03
4 304 Mark $47.645 2015-12-29
tbody #2
5 729.9 Tom $43.815 2017-07-03
6 753.8 Jake $5.824 2014-12-12
7 635.8 Greg $83.405 2016-07-25
8 298.5 Adam $70.365 2017-07-26
9 500.2 Steve $89.195 2014-08-09
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 168.3 Bill $51.585 2016-07-01
1 501.9 Joe $22.875 2016-06-26
2 505 Bob $35.745 2015-07-29
3 661.3 Matt $20.765 2015-11-02
4 248.9 Mark $51.155 2017-05-06
5 700.5 Tom $24.135 2015-07-26
6 629.5 Jake $99.515 2015-10-01
7 751.1 Greg $63.095 2015-03-23
8 383.5 Adam $92.935 2017-06-14
9 331.7 Steve $42.945 2017-02-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 $0.73
1 1 Joe $1.23
2 2 Bob $0.73
3 3 Matt $1.93
4 4 Mark $0.23
5 0 Tom $1.13
6 1 Jake $1.13
7 2 Greg $1.23
8 3 Bill $1.83
9 4 Joe $1.83
10 0 Bob $0.53
11 1 Matt $0.23
12 2 Mark $0.63
13 3 Tom $1.03
14 4 Jake $1.33
15 0 Greg $0.33
16 1 Bill $0.43
17 2 Joe $1.73
18 3 Bob $1.03
19 4 Matt $1.73
20 0 Mark $1.73
21 1 Tom $1.73
22 2 Jake $1.23
23 3 Greg $1.03
24 4 Bill $0.13
25 0 Joe $2.03
26 1 Bob $0.83
27 2 Matt $2.03
28 3 Mark $0.63
29 4 Tom $1.73
30 0 Jake $1.63
31 1 Greg $1.33
32 2 Bill $0.93
33 3 Joe $0.23
34 4 Bob $1.23

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 547.9 Bill $65.34 2015-02-16
1 152.3 Joe $55.94 2014-10-05
2 417.9 Bob $67.34 2015-09-02
3 932.3 Matt $29.84 2016-03-12
4 147.2 Mark $16.54 2017-09-22
5 991.5 Tom $2.63 2017-04-11
6 586.9 Jake $51.84 2017-06-27
7 565.6 Greg $94.04 2017-06-04
8 876.1 Adam $79.14 2016-09-27
9 532.6 Steve $23.94 2017-01-26

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-01-09
1 Joe 2017-01-20
2 Bob 2015-12-21
3 Matt 2015-08-04
4 Mark 2017-07-15
5 Tom 2014-07-29
6 Jake 2015-10-17
7 Greg 2015-09-10
8 Adam 2016-09-15
9 Steve 2016-11-25
10 George 2015-06-24
11 John 2017-08-26
12 Phil 2015-05-15
13 Jack 2015-12-11
14 Paul 2015-01-02
15 Rob 2015-05-14
16 Walt 2015-12-01
17 Nathan 2015-02-01
18 Dan 2014-11-29
19 Jeff 2014-08-10
20 Bill 2016-09-23
21 Joe 2014-09-02
22 Bob 2016-05-26
23 Matt 2016-07-16
24 Mark 2017-07-14
25 Tom 2016-01-03
26 Jake 2015-11-17
27 Greg 2016-07-18
28 Adam 2017-09-11
<< 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 654.5 Bill $41.94 2014-12-28
1 441.5 Joe $86.44 2016-01-08
2 380.8 Bob $86.84 2017-04-02
3 738 Matt $54.54 2016-06-03
4 27.5 Mark $52.14 2017-03-25