Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions jquery.tablesorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
sortForce: null,
sortAppend: null,
sortLocaleCompare: true,
sortChildren: false,
sortInPlace: false,
textExtraction: "simple",
parsers: {}, widgets: [],
widgetZebra: {
Expand Down Expand Up @@ -258,6 +260,10 @@
row: [],
normalized: []
};

if (table.config.sortChildren) {
cache.normalizedChildren = [];
}

for (var i = 0; i < totalRows; ++i) {

Expand All @@ -269,6 +275,20 @@
// continue to the next row
if (c.hasClass(table.config.cssChildRow)) {
cache.row[cache.row.length - 1] = cache.row[cache.row.length - 1].add(c);

// if we are planning to sort child rows, add the row to the special "normalizedChildren" Array
if (table.config.sortChildren) {
if (cache.normalizedChildren[cache.row.length - 1] === undefined) {
cache.normalizedChildren[cache.row.length - 1] = [];
}
var normalizedChild = [];
for (var j = 0; j < totalCells; ++j) {
normalizedChild.push(parsers[j].format(getElementText(table.config, c[0].cells[j]), table, c[0].cells[j]));
}
normalizedChild.push(cache.normalizedChildren[cache.row.length - 1].length); // add position for rowCache
cache.normalizedChildren[cache.row.length - 1].push(normalizedChild);
}

// go to the next for loop
continue;
}
Expand All @@ -287,7 +307,7 @@
if (table.config.debug) {
benchmark("Building cache for " + totalRows + " rows:", cacheTime);
}

return cache;
};

Expand Down Expand Up @@ -336,9 +356,13 @@
checkCell = (n[0].length - 1),
tableBody = $(table.tBodies[0]),
rows = [];



if (table.config.sortChildren) {
var nc = c.normalizedChildren;
}

for (var i = 0; i < totalRows; i++) {

var pos = n[i][checkCell];

rows.push(r[pos]);
Expand All @@ -347,12 +371,20 @@

//var o = ;
var l = r[pos].length;

for (var j = 0; j < l; j++) {
tableBody[0].appendChild(r[pos][j]);
if (table.config.sortChildren && (j > 0)) {
// if this row has children and they need to be sorted...
var childIndex = nc[pos][j - 1][checkCell] + 1;
tableBody[0].appendChild(r[pos][childIndex]);
} else {
tableBody[0].appendChild(r[pos][j]);
}
}

//
}

}


Expand Down Expand Up @@ -630,8 +662,18 @@

eval(dynamicExp);

cache.normalized.sort(sortWrapper);

// don't sort parent rows, if children rows are expanded and the "sort in place" setting is enabled
if (!table.config.sortInPlace || !$(table).find('.' + table.config.cssChildRow).is(':visible')) {
cache.normalized.sort(sortWrapper);
}

if (table.config.sortChildren) {
var ncl = cache.normalizedChildren.length;
for (var i = 0; i < ncl; i++) {
cache.normalizedChildren[i].sort(sortWrapper);
}
}

if (table.config.debug) {
benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time:", sortTime);
}
Expand Down