# tablesorter

## Sort multiple tbodies by primary row (beta)

### Flexible client-side table sorting

Back to documentation

### Notes

- In v2.27.9, added `sortTbody_lockHead` option. Thanks to Chris Rogers!
- This widget (v2.22.2) allows the sorting of tbodies (not rows) based on a specified row set by the `sortTbody_primaryRow` option.
- This widget replaces the `cssInfoBlock` setting:
  - The value is replaced with the value from `sortTbody_noSort` option so as to include info-only tbodies in the tbody sort.
  - Due to this modification, tbodies with `colspan` and `rowspan` cells may not sort or filter as expected, so it would be best to avoid `colspan` and `rowspan` cells in the primary row!
- This widget also modifies the `serverSideSorting` option:
  - This value is set to `true` to disable tbody internal row sorting.
  - This value is set to `false` (default) when the `sortTbody_sortRows` widget option is `true`.
  - This modification should not dramatically affect other widgets; at least none that I can think of right now.
- In these demos,
  - Primary Rows are styled with a light yellow background as an indicator.
  - The primary row color difference is important in the third table when the sorting of internal rows is enabled (`sortTbody_sortRows` is `true`).
  - The first two tables:
    - Primary rows are clickable. Clicking on them toggles the sibling rows (in the first table), or child rows (in the second table).
    - Primary rows have a dark top border to add a visual separation of each tbody.
    - *NOTE* when filtering the content of the first table, sibling rows that do not match the query will be hidden. Toggling their view is only possible because the `"filtered"` class (used by the filter widget & set by the `filter_filteredRow` widget option) is toggled.
- *ALERT* This widget requires tablesorter v2.22.2+ and jQuery 1.4+

### Options

TIP! Click on the link in the option column to reveal full details (or toggle|show|hide all) or double click to update the browser location.

Option | Default | Description
--- | --- | ---
sortTbody_lockHead | false | When `true`, the primary row will be moved to the top of the sorted tbody. Setting this option will also require setting the `sortTbody_sortRows` option to `true`. See the Sort tbodies and lock the header (primary) row demo below.
sortTbody_primaryRow | null | Set this option to a string containing a jQuery selector pointing to the primary row to use for tbody sorting. If a sortable tbody does not contain a primary row, or the primary row is not found, it will be sorted at the bottom of the table. In these demos, all primary rows have a class name of `"main"`, so this option is then set as follows:
    sortTbody_primaryRow : '.main'
*NOTE* This will accept any jQuery selector, so it is possible to target multiple classes `'.main, .primary'`, but only the first found cell in the sorted column will be used when sorting the tbody. *WARNING* This widget was not designed to deal with `colspan` or `rowspan` within the primary row, so it is best to avoid them.
sortTbody_sortRows | false | When `true`, all rows within each `tbody` will also be sorted; the primary row is included!
sortTbody_noSort | 'tablesorter-no-sort-tbody' | Add the class name from this option to any tbodies that are to remain static. They will not be sorted.

# Demo

Sort info-only tbodies by their primary row
Rank | First Name | Last Name | Superhero Name
--- | --- | --- | ---
3 | Bruce | Wayne | Batman
Batman is the superhero protector of Gotham City, a man dressed like a bat who fights against evil and strikes terror into the hearts of criminals everywhere. In his secret identity he is Bruce Wayne, billionaire industrialist and notorious playboy. Although he has no superhuman powers, he is one of the world's smartest men and greatest fighters. His physical prowess and technical ingenuity make him an incredibly dangerous opponent. He is also a founding member of the Justice League and the Outsiders.
4 | Hal | Jordan | Green Latern
Hal Jordan is the most well-known Green Lantern. He was the first earthman ever inducted into the Green Lantern Corps, and has been heralded as possibly the greatest Green Lantern of all time. Green Lantern is also a founding member of the Justice League of America.
2 | Clark | Kent | Superman
Superman, also known as the Man of Steel, is one of the most powerful superheroes in the DC Universe. His abilities include incredible super-strength, super-speed, invulnerability, freezing breath, flight, and heat-vision.
5 | Charles | Xavier | Professor X
Charles Francis Xavier was born in New York City to the wealthy Brian Xavier, a well-respected nuclear scientist, and Sharon Xavier. After Brian died in an accident, his science partner Kurt Marko comforts and marries the grieving Sharon. When Xavier's telepathic mutant powers emerge, he discovers Kurt cares only about his mother's money.
1 | Susan | Richards | Invisible Woman
Susan's primary power deals with light waves, allowing her to render herself and others invisible.

Sort tbodies by their primary row (using child rows for extra info)
Rank | First Name | Last Name | Superhero Name
--- | --- | --- | ---
3 | Bruce | Wayne | Batman
Batman is the superhero protector of Gotham City, a man dressed like a bat who fights against evil and strikes terror into the hearts of criminals everywhere. In his secret identity he is Bruce Wayne, billionaire industrialist and notorious playboy. Although he has no superhuman powers, he is one of the world's smartest men and greatest fighters. His physical prowess and technical ingenuity make him an incredibly dangerous opponent. He is also a founding member of the Justice League and the Outsiders.
4 | Hal | Jordan | Green Latern
Hal Jordan is the most well-known Green Lantern. He was the first earthman ever inducted into the Green Lantern Corps, and has been heralded as possibly the greatest Green Lantern of all time. Green Lantern is also a founding member of the Justice League of America.
2 | Clark | Kent | Superman
Superman, also known as the Man of Steel, is one of the most powerful superheroes in the DC Universe. His abilities include incredible super-strength, super-speed, invulnerability, freezing breath, flight, and heat-vision.
5 | Charles | Xavier | Professor X
Charles Francis Xavier was born in New York City to the wealthy Brian Xavier, a well-respected nuclear scientist, and Sharon Xavier. After Brian died in an accident, his science partner Kurt Marko comforts and marries the grieving Sharon. When Xavier's telepathic mutant powers emerge, he discovers Kurt cares only about his mother's money.
1 | Susan | Richards | Invisible Woman
Susan's primary power deals with light waves, allowing her to render herself and others invisible.

`sortTbody_sortRows`:
(sort internal rows)

Sortable & non-sortable tbodies
# | ID | First | Last | State | Info
--- | --- | --- | --- | --- | ---
1 | 337 | Denise | Harris | CT | lectus tortor vestibulum
2 | 268 | Brien | Barrow | KY | ipsum aenean eros
3 | 665 | Mikel | Absalom | FL | amet vestibulum adipiscing
4 | 540 | LaShonda | Buikema | SD | pulvinar at consectetur
Tbody "tablesorter-no-sort-tbody" spacer 1
5 | 212 | Leif | Choate | UT | porttitor mattis sit
6 | 367 | Ericka | Ragusa | MA | at sollicitudin hendrerit
7 | 136 | Waddie | Maynard | NH | sollicitudin ac mi
8 | 305 | Ken | Weissmann | AK | magna sit at
Tbody "tablesorter-no-sort-tbody" spacer 2
9 | 983 | Petr | Kunselman | WI | amet convallis eros
10 | 306 | Melanie | Nabors | MA | tincidunt risus porttitor
11 | 345 | Emil | Corson | MO | dui aliquam aliquam
12 | 335 | Theodore | Brill | WV | sit pulvinar eros
Tbody "tablesorter-no-sort-tbody" spacer 3
13 | 430 | Nishal | Smith | DE | tortor tincidunt porttitor
14 | 470 | Sheryl | Scheppe | ID | sed massa hendrerit
15 | 795 | Christopher | Pollard | CT | sed lacus adipiscing
16 | 400 | Raymond | Jessica | IN | mi vestibulum amet
Tbody "tablesorter-no-sort-tbody" spacer 4
17 | 927 | Donovan | Joslin | MN | amet augue aliquam
18 | 882 | Ning | Mccollum | KS | sed egestas vestibulum
19 | 772 | Sarah | Radist | DE | ipsum odio dui
20 | 975 | Aisha | Badertscher | CT | mi nec massa

Sort tbodies and lock the header (primary) row
Dealer | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
Dealer 48 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
Site 3 | 77 | 84 | 197 | 33 | 136 | 166 | 158 | 58 | 170 | 154 | 92 | 25
Site 18 | 151 | 187 | 112 | 91 | 155 | 74 | 81 | 92 | 52 | 140 | 3 | 109
Site 25 | 177 | 24 | 125 | 168 | 116 | 122 | 123 | 141 | 13 | 10 | 41 | 66
Site 4 | 131 | 46 | 188 | 56 | 37 | 162 | 160 | 178 | 73 | 39 | 99 | 165
Site 20 | 87 | 20 | 65 | 61 | 87 | 139 | 17 | 159 | 75 | 108 | 119 | 171
Dealer 29 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
Site 3 | 45 | 25 | 188 | 12 | 131 | 63 | 189 | 150 | 63 | 57 | 50 | 189
Site 18 | 122 | 6 | 121 | 169 | 90 | 131 | 65 | 74 | 188 | 78 | 180 | 82
Site 25 | 72 | 151 | 83 | 38 | 121 | 2 | 35 | 54 | 92 | 113 | 185 | 38
Site 4 | 79 | 62 | 53 | 173 | 18 | 1 | 93 | 9 | 58 | 48 | 57 | 129
Site 20 | 33 | 51 | 175 | 104 | 125 | 123 | 1 | 56 | 66 | 159 | 84 | 117
Dealer 62 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
Site 3 | 85 | 56 | 168 | 78 | 115 | 104 | 8 | 151 | 144 | 20 | 105 | 60
Site 18 | 189 | 28 | 76 | 88 | 16 | 97 | 194 | 144 | 31 | 47 | 192 | 176
Site 25 | 156 | 145 | 132 | 81 | 193 | 130 | 102 | 9 | 196 | 48 | 99 | 37
Site 4 | 154 | 5 | 31 | 58 | 31 | 119 | 184 | 32 | 9 | 169 | 87 | 46
Site 20 | 13 | 19 | 41 | 82 | 174 | 48 | 177 | 157 | 19 | 134 | 85 | 176
Dealer 25 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
Site 3 | 175 | 58 | 196 | 186 | 88 | 46 | 4 | 109 | 187 | 167 | 109 | 104
Site 18 | 109 | 2 | 53 | 170 | 163 | 116 | 36 | 125 | 43 | 57 | 179 | 194
Site 25 | 109 | 13 | 169 | 41 | 166 | 20 | 38 | 175 | 69 | 180 | 176 | 8
Site 4 | 129 | 28 | 137 | 61 | 38 | 70 | 156 | 200 | 141 | 178 | 76 | 70
Site 20 | 3 | 65 | 69 | 162 | 114 | 179 | 101 | 157 | 56 | 149 | 134 | 85

# Page Header

    <link rel="stylesheet" href="../css/theme.blue.css">
    <script src="js/jquery-latest.min.js"></script>
    <script src="../js/jquery.tablesorter.js"></script>

    <!-- Tablesorter: widgets (optional) -->
    <script src="../js/jquery.tablesorter.widgets.js"></script>
    <script src="../js/widgets/widget-sortTbodies.js"></script>

# CSS

# Javascript

# HTML