tristen / tablesort

:arrow_up_down: A small tablesorter in plain JavaScript
https://tristen.ca/tablesort/demo/
MIT License
1.1k stars 179 forks source link

Group with previous row? #155

Open frumbert opened 6 years ago

frumbert commented 6 years ago

Is there a way to create rows in the table that are grouped with the previous row as far as sorting is concerned?

Say I had this ridiculous example:

<table><thead><tr><th>Id</th><th>name</th></tr></thead>
<tbody>
<tr><td>4</td><td>David</td></tr>
<tr class="group-with-previous"><td colspan="2"><td>Hates to be called Dave</td></tr>
<tr><td>1</td><td>Alice</td></tr>
<tr><td>5</td><td>Edward</td></tr>
<tr><td>3</td><td>Charles</td></tr>
<tr><td>2</td><td>Bob</td></tr>
</tbody></table>

after sorting on column 1 (id) it would then look like:

<table><thead><tr><th>Id</th><th>name</th></tr></thead>
<tbody>
<tr><td>1</td><td>Alice</td></tr>
<tr><td>2</td><td>Bob</td></tr>
<tr><td>3</td><td>Charles</td></tr>
<tr><td>4</td><td>David</td></tr>
<tr class="group-with-previous"><td colspan="2"><td>Hates to be called Dave</td></tr>
<tr><td>5</td><td>Edward</td></tr>
</tbody></table>

In this case, the <tr> that has the classname group-with-previous is ignored when sorting, but when its previous row is moved in the dom it also is moved adjacent to it.