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 212.1 Bill $64.035 2014-09-23
1 458.2 Joe $36.905 2016-12-16
2 104.7 Bob $73.895 2015-06-09
3 229.8 Matt $0.874 2016-04-21
4 438.9 Mark $88.485 2015-06-03
tbody #2
5 51.1 Tom $22.165 2015-09-22
6 279.1 Jake $47.225 2015-04-17
7 294.5 Greg $44.885 2017-03-30
8 920.2 Adam $90.695 2016-04-29
9 1000 Steve $47.675 2016-03-05
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 805.3 Bill $68.875 2015-01-13
1 903.1 Joe $14.695 2016-03-15
2 705.3 Bob $25.155 2015-05-18
3 26.6 Matt $48.135 2015-05-28
4 622.1 Mark $92.015 2015-01-15
5 938.4 Tom $97.125 2015-09-28
6 351 Jake $25.025 2017-03-28
7 627.4 Greg $54.465 2015-06-28
8 519.3 Adam $46.475 2015-03-13
9 122.3 Steve $46.465 2016-09-14

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.53
2 2 Bob $0.83
3 3 Matt $1.83
4 4 Mark $0.33
5 0 Tom $1.13
6 1 Jake $0.93
7 2 Greg $1.83
8 3 Bill $1.63
9 4 Joe $1.53
10 0 Bob $1.83
11 1 Matt $0.63
12 2 Mark $0.13
13 3 Tom $1.13
14 4 Jake $0.43
15 0 Greg $0.53
16 1 Bill $0.93
17 2 Joe $0.43
18 3 Bob $1.33
19 4 Matt $1.63
20 0 Mark $0.93
21 1 Tom $1.13
22 2 Jake $0.93
23 3 Greg $2.03
24 4 Bill $1.83
25 0 Joe $1.93
26 1 Bob $0.93
27 2 Matt $0.33
28 3 Mark $0.23
29 4 Tom $1.83
30 0 Jake $1.73
31 1 Greg $1.53
32 2 Bill $0.43
33 3 Joe $0.63
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 348.2 Bill $82.94 2014-08-22
1 226.3 Joe $63.84 2016-12-24
2 131 Bob $92.84 2017-02-20
3 657.7 Matt $13.94 2014-10-02
4 122.8 Mark $32.04 2016-11-09
5 938.8 Tom $75.24 2015-06-12
6 382.2 Jake $72.84 2015-02-08
7 344.9 Greg $16.94 2015-07-18
8 429.7 Adam $7.43 2015-02-06
9 191.6 Steve $24.94 2015-12-17

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-12
1 Joe 2016-04-23
2 Bob 2015-06-02
3 Matt 2017-04-03
4 Mark 2017-01-10
5 Tom 2017-06-09
6 Jake 2016-08-25
7 Greg 2017-06-11
8 Adam 2017-03-18
9 Steve 2016-03-15
10 George 2016-05-10
11 John 2014-06-25
12 Phil 2016-07-15
13 Jack 2016-09-29
14 Paul 2015-07-01
15 Rob 2015-10-23
16 Walt 2016-07-21
17 Nathan 2014-09-16
18 Dan 2016-11-02
19 Jeff 2014-08-05
20 Bill 2017-01-06
21 Joe 2017-07-11
22 Bob 2015-09-09
23 Matt 2017-07-20
24 Mark 2015-06-25
25 Tom 2017-01-18
26 Jake 2014-08-14
27 Greg 2016-03-01
28 Adam 2014-06-27
<< 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 312.6 Bill $3.83 2017-02-06
1 910.2 Joe $35.34 2016-10-09
2 734 Bob $30.74 2015-11-01
3 688.7 Matt $18.84 2014-06-14
4 301 Mark $20.84 2016-07-28