The only logical (not necessarily semantically) available for you to group related lines together is <tbody> , since it is valid to have multiple <tbody> elements. However, this will not help you in this case due to the implementation of tablesorter.
I see the undocumented configuration option in the tablesorter source code - appender - which allows you to specify a function that sorts the table, and a data structure containing sorted rows that must be added to it to achieve the desired reordering, but I do not see any parameters that allow you’ll be able to configure which lines it looks at when it is sorting.
If this first part of the puzzle was there, you can use it to limit the rows considered to be sorted by your actual data rows, and use the appender parameter to provide a function that adds each sorted row and its next row.
Edit: Here you can quickly and unpleasantly implement the additional fragment that you need, and an example of use:
Modification of the buildCache method, starting from line 195 onwards to jquery.tablesorter.js:
var rowsToSort = table.config.rowsToSort ? table.config.rowsToSort(table) : table.tBodies[0].rows; var totalRows = rowsToSort.length, totalCells = (rowsToSort[0] && rowsToSort[0].cells.length) || 0, parsers = table.config.parsers, cache = {row: [], normalized: []};
Usage that works for me with your sample table:
$(document).ready(function() { $.tablesorter.defaults.debug = true; // Select every other row as sorting criteria $.tablesorter.defaults.rowsToSort = function(table) { var rows = []; var allRows = table.tBodies[0].rows; for (var i = 0, l = allRows.length; i < l; i += 2) { rows.push(allRows[i]); } return rows; }; // Append each row and its next sibling row $.tablesorter.defaults.appender = function (table, rows) { for (var i = 0, l = rows.length; i < l; i++) { var row = rows[i][0]; var buddyRow = $(row).next("tr").get(0); table.tBodies[0].appendChild(row); table.tBodies[0].appendChild(buddyRow); } }; $("table").tablesorter(); });
Jonny buchanan
source share