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 417.8 Bill $82.105 2016-05-02
1 525.2 Joe $76.565 2014-11-21
2 841.2 Bob $74.515 2015-09-24
3 238.5 Matt $44.035 2015-02-05
4 832.2 Mark $52.375 2015-02-10
tbody #2
5 782.6 Tom $29.425 2015-11-30
6 530.4 Jake $57.485 2016-08-10
7 217.6 Greg $12.355 2017-01-01
8 251.9 Adam $59.105 2016-02-05
9 112 Steve $22.255 2014-12-16
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 466.3 Bill $64.025 2017-07-24
1 42.6 Joe $16.535 2016-10-25
2 162.6 Bob $0.644 2016-01-04
3 547.6 Matt $24.495 2017-05-28
4 733.4 Mark $7.714 2015-11-23
5 922.8 Tom $85.965 2016-10-29
6 365.7 Jake $38.995 2015-06-25
7 28.4 Greg $60.755 2015-11-15
8 815.4 Adam $85.935 2014-07-29
9 315.8 Steve $97.125 2015-04-13

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

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 981.2 Bill $63.44 2015-10-08
1 623.7 Joe $68.84 2014-07-26
2 813.9 Bob $98.84 2016-04-05
3 737.3 Matt $36.44 2016-03-04
4 583.5 Mark $60.04 2015-03-26
5 795.4 Tom $22.64 2015-04-06
6 35.6 Jake $45.94 2016-08-26
7 91.1 Greg $55.14 2014-12-09
8 462.3 Adam $61.54 2017-03-01
9 291 Steve $11.64 2015-11-07

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 2016-03-21
1 Joe 2014-10-26
2 Bob 2014-09-09
3 Matt 2017-06-23
4 Mark 2016-10-17
5 Tom 2016-11-13
6 Jake 2017-07-14
7 Greg 2016-03-15
8 Adam 2016-10-30
9 Steve 2016-02-12
10 George 2015-05-16
11 John 2014-10-25
12 Phil 2014-08-11
13 Jack 2017-03-22
14 Paul 2016-09-18
15 Rob 2015-05-02
16 Walt 2016-07-28
17 Nathan 2017-06-06
18 Dan 2016-02-01
19 Jeff 2016-09-07
20 Bill 2015-09-19
21 Joe 2015-01-22
22 Bob 2016-12-21
23 Matt 2017-06-19
24 Mark 2015-06-28
25 Tom 2015-04-09
26 Jake 2016-03-30
27 Greg 2014-12-22
28 Adam 2016-03-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 663.7 Bill $57.04 2014-09-25
1 761 Joe $62.74 2014-07-13
2 482 Bob $37.14 2017-07-21
3 16.9 Matt $10.44 2015-12-29
4 289 Mark $20.04 2016-02-04