diff --git a/misc/tabledrag.js b/misc/tabledrag.js index fed674c..a238072 100644 --- a/misc/tabledrag.js +++ b/misc/tabledrag.js @@ -125,7 +125,8 @@ Drupal.tableDrag.prototype.initColumns = function () { var field = $('.' + this.tableSettings[group][d].target + ':first', this.table); if (field.length && this.tableSettings[group][d].hidden) { var hidden = this.tableSettings[group][d].hidden; - var cell = field.closest('td'); + // Find the parent cell -- whether the match was in a td or th element. + var cell = field.closest('td, th'); break; } } @@ -134,7 +135,16 @@ Drupal.tableDrag.prototype.initColumns = function () { 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. - var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1; + // Uses tagName (TH or TD) so selector works regardless of cell type. + var columnIndex = $('> '+cell[0].tagName, cell.parent()).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; + } + }); $('> thead > tr, > tbody > tr, > tr', this.table).each(function () { // Get the columnIndex and adjust for any colspans in this row. var index = columnIndex;