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 394.4 Bill $30.185 2014-11-13
1 113 Joe $99.485 2015-03-15
2 17.1 Bob $16.125 2017-05-19
3 793.2 Matt $77.715 2015-08-23
4 913.1 Mark $56.305 2016-12-26
tbody #2
5 294 Tom $5.534 2016-11-25
6 342 Jake $61.325 2015-01-06
7 749 Greg $34.925 2017-05-06
8 362.3 Adam $19.005 2016-01-21
9 827.4 Steve $50.375 2016-03-07
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 460.2 Bill $89.815 2017-02-19
1 548.4 Joe $1.104 2017-02-13
2 742.1 Bob $2.814 2017-08-19
3 622.9 Matt $82.125 2016-12-03
4 955.3 Mark $73.435 2015-07-17
5 711.9 Tom $2.834 2015-09-18
6 442.2 Jake $37.025 2017-08-28
7 576.8 Greg $11.915 2015-08-06
8 446.7 Adam $48.135 2016-03-13
9 909.4 Steve $30.875 2014-08-16

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.83
1 1 Joe $1.53
2 2 Bob $1.83
3 3 Matt $0.43
4 4 Mark $0.63
5 0 Tom $1.93
6 1 Jake $0.03
7 2 Greg $0.13
8 3 Bill $1.93
9 4 Joe $2.03
10 0 Bob $1.43
11 1 Matt $1.53
12 2 Mark $1.43
13 3 Tom $1.33
14 4 Jake $1.03
15 0 Greg $0.03
16 1 Bill $0.73
17 2 Joe $1.13
18 3 Bob $0.73
19 4 Matt $1.63
20 0 Mark $1.83
21 1 Tom $0.73
22 2 Jake $0.73
23 3 Greg $0.13
24 4 Bill $1.33
25 0 Joe $1.63
26 1 Bob $1.03
27 2 Matt $0.33
28 3 Mark $1.43
29 4 Tom $1.63
30 0 Jake $0.33
31 1 Greg $0.33
32 2 Bill $1.23
33 3 Joe $0.23
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 897.2 Bill $0.33 2015-10-02
1 956.4 Joe $95.14 2015-09-04
2 638.5 Bob $72.14 2014-10-06
3 275.8 Matt $22.44 2014-10-21
4 625 Mark $75.74 2015-12-21
5 416.4 Tom $65.94 2017-01-13
6 784.5 Jake $68.04 2015-12-10
7 599.3 Greg $18.34 2016-06-14
8 323.5 Adam $99.44 2017-01-01
9 459.5 Steve $57.44 2017-04-06

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-02-27
1 Joe 2016-01-30
2 Bob 2017-04-09
3 Matt 2015-02-26
4 Mark 2015-12-11
5 Tom 2017-02-12
6 Jake 2016-03-29
7 Greg 2014-10-18
8 Adam 2016-03-25
9 Steve 2016-05-31
10 George 2015-09-02
11 John 2016-12-10
12 Phil 2016-08-18
13 Jack 2017-08-26
14 Paul 2016-03-03
15 Rob 2014-11-04
16 Walt 2015-10-20
17 Nathan 2015-02-02
18 Dan 2017-04-16
19 Jeff 2015-02-13
20 Bill 2017-03-30
21 Joe 2015-06-22
22 Bob 2017-01-06
23 Matt 2014-08-27
24 Mark 2017-05-03
25 Tom 2014-11-15
26 Jake 2014-08-20
27 Greg 2016-07-31
28 Adam 2016-04-30
<< 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 588.2 Bill $47.34 2015-09-25
1 59.1 Joe $31.94 2016-04-19
2 486.5 Bob $11.74 2014-10-13
3 552.2 Matt $63.64 2016-08-10
4 893.7 Mark $37.94 2015-06-25