Sort command
Let visitors sort table rows by their columns.
Basic Usage (HTML)
data-jkit="[sort:what=text;by=date]"
Advanced Init (JavaScript)
$('#myelement').jKit('sort', { 'what': 'text', 'by': 'date' });
Options
Option | Values | Default | Description |
---|---|---|---|
what | “html”, “class” or “text” | text | On what kind of source to sort the rows |
by | “num”, “date” or “text” | The kind of stuff to sort (date has to be an javascript date datestring) | |
start | Int | 0 | From which starting position in the string to take the sort string (0 = first character) |
end | Int | 0 | From which ending position in the string to take the sort string (0 = last character) |
Events
Event | Description |
---|---|
clicked | Triggered on click |
complete | Triggered after sorting is finished |
Examples
Basic example:
Sort table rows on click (up and down), with different sorting options:
Name | Location | Birthday | Category | Status | Superior | Price (CHF) |
---|---|---|---|---|---|---|
Mr. Max Keller | CH-7278 Davos Monstein | 1-29-1986 | freelancer | active | #120 | 1.00 |
Ms. Sophia Roth | CH-3186 Düdingen | 2-16-1955 | freelancer | active | #120 | 25.25 |
Mr. Fredi Baumann | CH-6543 Arvigo | 11-21-1993 | freelancer | active | 2.99 | |
Ms. Hannah Zimmermann | LI-9493 Mauren | 6-26-1967 | freelancer | active | #1168 | 48.95 |
Ms. Maja Brunner | D-21207 Seevetal | 10-22-1934 | trainee | active | #120 | 200.10 |
Mr. Tom Fischer | LI-9492 Eschen | 5-19-1955 | freelancer | inactive | #1168 | -5.05 |
Ms. Alina Gerber | D-21710 Engelschoff | 10-15-1981 | employee | active | #1168 | 10 |
Mr. Tim Gerber | CH-6543 Arvigo | 12-8-2022 | freelancer | active | #120 | 4721.45 |
Mr. Felix Meier | LI-9486 Schaanwald | 8-26-1975 | guest | active | #120 | 12.55 |
Mr. Fredi Müller | LI-9486 Schaanwald | 10-24-1953 | trainee | active | #120 | 354.50 |
Mr. Tim Gerber | CH-1773 Léchelles | 12-25-1966 | freelancer | active | 42.85 | |
Ms. Lilli Meyer | D-21207 Seevetal | 11-29-1938 | guest | active | 87.41 | |
Ms. Emilie Fischer | D-04299 Leipzig | 11-7-2022 | freelancer | active | #463 | 354.01 |
Mr. Fredi Graf | CH-6534 S. Vittore | 12-7-2022 | employee | active | #120 | 14.12 |
Ms. Cordelia Weber | CH-6543 Arvigo | 2-23-1967 | employee | active | #120 | 10.25 |
Source:
<table class="sort" width="100%"> <thead> <tr> <th data-jkit="[sort:what=text;start=4]">Name</th> <th data-jkit="[sort:what=text]">Location</th> <th data-jkit="[sort:what=text;by=date]">Birthday</th> <th data-jkit="[sort:what=text]">Category</th> <th data-jkit="[sort:what=text]">Status</th> <th data-jkit="[sort:what=text;start=2]">Superior</th> <th data-jkit="[sort:what=text;by=num]">Price (CHF)</th> </tr> </thead> <tbody> <tr><td>Mr. Max Keller</td><td>CH-7278 Davos Monstein</td><td>1-29-1986</td><td>freelancer</td><td>active</td><td>#120</td><td>1.00</td></tr> <tr><td>Ms. Sophia Roth</td><td>CH-3186 Düdingen</td><td>2-16-1955</td><td>freelancer</td><td>active</td><td>#120</td><td>25.25</td></tr> <tr><td>Mr. Fredi Baumann</td><td>CH-6543 Arvigo</td><td>11-21-1993</td><td>freelancer</td><td>active</td><td></td><td>2.99</td></tr> <tr><td>Ms. Hannah Zimmermann</td><td>LI-9493 Mauren</td><td>6-26-1967</td><td>freelancer</td><td>active</td><td>#1168</td><td>48.95</td></tr> <tr><td>Ms. Maja Brunner</td><td>D-21207 Seevetal</td><td>10-22-1934</td><td>trainee</td><td>active</td><td>#120</td><td>200.10</td></tr> <tr><td>Mr. Tom Fischer</td><td>LI-9492 Eschen</td><td>5-19-1955</td><td>freelancer</td><td>inactive</td><td>#1168</td><td>-5.05</td></tr> <tr><td>Ms. Alina Gerber</td><td>D-21710 Engelschoff</td><td>10-15-1981</td><td>employee</td><td>active</td><td>#1168</td><td>10</td></tr> <tr><td>Mr. Tim Gerber</td><td>CH-6543 Arvigo</td><td>12-8-1943</td><td>freelancer</td><td>active</td><td>#120</td><td>4721.45</td></tr> <tr><td>Mr. Felix Meier</td><td>LI-9486 Schaanwald</td><td>8-26-1975</td><td>guest</td><td>active</td><td>#120</td><td>12.55</td></tr> <tr><td>Mr. Fredi Müller</td><td>LI-9486 Schaanwald</td><td>10-24-1953</td><td>trainee</td><td>active</td><td>#120</td><td>354.50</td></tr> <tr><td>Mr. Tim Gerber</td><td>CH-1773 Léchelles</td><td>12-25-1966</td><td>freelancer</td><td>active</td><td></td><td>42.85</td></tr> <tr><td>Ms. Lilli Meyer</td><td>D-21207 Seevetal</td><td>11-29-1938</td><td>guest</td><td>active</td><td></td><td>87.41</td></tr> <tr><td>Ms. Emilie Fischer</td><td>D-04299 Leipzig</td><td>11-7-1942</td><td>freelancer</td><td>active</td><td>#463</td><td>354.01</td></tr> <tr><td>Mr. Fredi Graf</td><td>CH-6534 S. Vittore</td><td>12-7-1971</td><td>employee</td><td>active</td><td>#120</td><td>14.12</td></tr> <tr><td>Ms. Cordelia Weber</td><td>CH-6543 Arvigo</td><td>2-23-1967</td><td>employee</td><td>active</td><td>#120</td><td>10.25</td></tr> </tbody> </table>
Sort, events and the cycle command:
In this example we are using the jKit event system to trigger the cycle command whenever the table is sorted:
Source:
<div data-jkit="[cycle:what=css.background;where=table > tbody > tr;scope=all;sequence=#ddd,#fff][cycle:onevent=tablesort.complete;what=css.background;where=table > tbody > tr;scope=all;sequence=#ddd,#fff]"> <table class="sort" width="100%"> <thead> <tr> <th data-jkit="[sort.tablesort:what=text;start=4]">Name</th> <th data-jkit="[sort.tablesort:what=text]">Location</th> <th data-jkit="[sort.tablesort:what=text;by=date]">Birthday</th> <th data-jkit="[sort.tablesort:what=text]">Category</th> <th data-jkit="[sort.tablesort:what=text]">Status</th> <th data-jkit="[sort.tablesort:what=text;start=2]">Superior</th> <th data-jkit="[sort.tablesort:what=text;by=num]">Price (CHF)</th> </tr> </thead> <tbody> <tr><td>Mr. Max Keller</td><td>CH-7278 Davos Monstein</td><td>1-29-1986</td><td>freelancer</td><td>active</td><td>#120</td><td>1.00</td></tr> <tr><td>Ms. Sophia Roth</td><td>CH-3186 Düdingen</td><td>2-16-1955</td><td>freelancer</td><td>active</td><td>#120</td><td>25.25</td></tr> <tr><td>Mr. Fredi Baumann</td><td>CH-6543 Arvigo</td><td>11-21-1993</td><td>freelancer</td><td>active</td><td></td><td>2.99</td></tr> <tr><td>Ms. Hannah Zimmermann</td><td>LI-9493 Mauren</td><td>6-26-1967</td><td>freelancer</td><td>active</td><td>#1168</td><td>48.95</td></tr> <tr><td>Ms. Maja Brunner</td><td>D-21207 Seevetal</td><td>10-22-1934</td><td>trainee</td><td>active</td><td>#120</td><td>200.10</td></tr> <tr><td>Mr. Tom Fischer</td><td>LI-9492 Eschen</td><td>5-19-1955</td><td>freelancer</td><td>inactive</td><td>#1168</td><td>-5.05</td></tr> <tr><td>Ms. Alina Gerber</td><td>D-21710 Engelschoff</td><td>10-15-1981</td><td>employee</td><td>active</td><td>#1168</td><td>10</td></tr> <tr><td>Mr. Tim Gerber</td><td>CH-6543 Arvigo</td><td>12-8-1943</td><td>freelancer</td><td>active</td><td>#120</td><td>4721.45</td></tr> <tr><td>Mr. Felix Meier</td><td>LI-9486 Schaanwald</td><td>8-26-1975</td><td>guest</td><td>active</td><td>#120</td><td>12.55</td></tr> <tr><td>Mr. Fredi Müller</td><td>LI-9486 Schaanwald</td><td>10-24-1953</td><td>trainee</td><td>active</td><td>#120</td><td>354.50</td></tr> <tr><td>Mr. Tim Gerber</td><td>CH-1773 Léchelles</td><td>12-25-1966</td><td>freelancer</td><td>active</td><td></td><td>42.85</td></tr> <tr><td>Ms. Lilli Meyer</td><td>D-21207 Seevetal</td><td>11-29-1938</td><td>guest</td><td>active</td><td></td><td>87.41</td></tr> <tr><td>Ms. Emilie Fischer</td><td>D-04299 Leipzig</td><td>11-7-1942</td><td>freelancer</td><td>active</td><td>#463</td><td>354.01</td></tr> <tr><td>Mr. Fredi Graf</td><td>CH-6534 S. Vittore</td><td>12-7-1971</td><td>employee</td><td>active</td><td>#120</td><td>14.12</td></tr> <tr><td>Ms. Cordelia Weber</td><td>CH-6543 Arvigo</td><td>2-23-1967</td><td>employee</td><td>active</td><td>#120</td><td>10.25</td></tr> </tbody> </table> </div>
Replacements
There are currently no replacements for this command.
[ Learn more about replacements ]
Discussions
Do you have questions or do you want to suggest new features? Than head over to our new community:
[ jKit Community ]