diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js index f3c6c9e..bda5c11 100644 --- a/core/misc/tabledrag.js +++ b/core/misc/tabledrag.js @@ -160,7 +160,8 @@ var field = $table.find('.' + this.tableSettings[group][d].target + ':first'); if (field.length && this.tableSettings[group][d].hidden) { hidden = this.tableSettings[group][d].hidden; - cell = field.closest('td'); + // Find the parent cell -- whether the match was in a td or th element. + cell = field.closest('td, th'); break; } } @@ -170,7 +171,16 @@ if (hidden && cell[0]) { // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based. // Match immediate children of the parent element to allow nesting. - columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; + // Uses tagName (TH or TD) so selector works regardless of cell type. + columnIndex = cell.parent().find('> '+cell[0].tagName).index(cell.get(0)) + 1; + // Check whether the matching cell is in a row containing colspans. + // If so, adjust columnIndex accordingly. + var origIndex = columnIndex; + cell.parent().children().each(function (n) { + if (n < origIndex && this.colSpan && this.colSpan > 1) { + columnIndex += this.colSpan - 1; + } + }); $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); } }