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 199.1 Bill $33.495 2017-06-11
1 253.5 Joe $22.045 2016-05-02
2 400.3 Bob $80.725 2015-07-14
3 318.9 Matt $94.645 2015-07-31
4 994.4 Mark $34.655 2017-01-19
tbody #2
5 105.6 Tom $20.495 2014-09-13
6 100.5 Jake $14.295 2016-11-08
7 801.6 Greg $98.965 2016-01-02
8 306.2 Adam $39.205 2015-06-16
9 357.1 Steve $54.935 2016-10-13
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 854.3 Bill $74.835 2014-09-04
1 781.4 Joe $0.184 2015-05-17
2 359 Bob $40.205 2014-10-06
3 683.1 Matt $72.085 2014-08-05
4 21.9 Mark $71.525 2015-09-10
5 826 Tom $82.075 2016-05-04
6 887.6 Jake $92.125 2016-10-17
7 629.8 Greg $72.275 2016-10-04
8 103 Adam $2.894 2014-11-01
9 403.6 Steve $38.605 2016-07-28

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.23
1 1 Joe $0.53
2 2 Bob $0.83
3 3 Matt $0.43
4 4 Mark $0.13
5 0 Tom $0.83
6 1 Jake $0.93
7 2 Greg $0.83
8 3 Bill $1.63
9 4 Joe $1.13
10 0 Bob $0.13
11 1 Matt $1.13
12 2 Mark $1.13
13 3 Tom $0.23
14 4 Jake $0.53
15 0 Greg $1.93
16 1 Bill $1.83
17 2 Joe $0.13
18 3 Bob $1.03
19 4 Matt $1.63
20 0 Mark $2.03
21 1 Tom $0.53
22 2 Jake $0.93
23 3 Greg $1.43
24 4 Bill $1.93
25 0 Joe $1.13
26 1 Bob $1.53
27 2 Matt $0.13
28 3 Mark $1.93
29 4 Tom $0.23
30 0 Jake $1.43
31 1 Greg $0.13
32 2 Bill $0.73
33 3 Joe $0.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 381.9 Bill $51.24 2016-09-07
1 762.4 Joe $31.74 2015-03-18
2 825.9 Bob $84.34 2016-12-28
3 911.3 Matt $8.43 2016-10-16
4 822.7 Mark $14.64 2015-04-06
5 621.7 Tom $12.84 2016-01-08
6 50.4 Jake $83.44 2015-11-12
7 582.1 Greg $56.84 2016-01-15
8 517.3 Adam $68.84 2015-02-11
9 575.7 Steve $4.93 2015-06-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-28
1 Joe 2015-11-14
2 Bob 2017-01-30
3 Matt 2016-02-02
4 Mark 2015-02-12
5 Tom 2014-12-02
6 Jake 2016-10-16
7 Greg 2014-07-25
8 Adam 2017-08-04
9 Steve 2016-02-10
10 George 2017-06-14
11 John 2014-09-08
12 Phil 2015-03-26
13 Jack 2016-11-21
14 Paul 2015-02-24
15 Rob 2015-12-27
16 Walt 2015-09-10
17 Nathan 2015-07-22
18 Dan 2017-07-02
19 Jeff 2015-11-07
20 Bill 2015-01-11
21 Joe 2015-09-10
22 Bob 2014-07-11
23 Matt 2016-10-29
24 Mark 2017-03-24
25 Tom 2016-03-01
26 Jake 2015-11-03
27 Greg 2014-08-31
28 Adam 2014-10-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 470.3 Bill $35.24 2017-05-23
1 900.8 Joe $16.64 2015-10-22
2 93.7 Bob $29.74 2014-12-04
3 112.4 Matt $27.14 2016-07-13
4 42.5 Mark $32.94 2017-04-04