Steps to reproduce:

- Create a table, and add the tabledrag effect to it.
- Put the table inside a collapsible fieldset that is initially collapsed.

Result: The weight-selection cells will disappear, but the "Weight" column heading will remain.

This is because tabledrag.js uses the following code to determine the column index of the weight column that should be hidden:

      var columnIndex = $('> td', cell.parent()).index(cell.get(0)) + 1;
      var headerIndex = $('> td:not(:hidden)', cell.parent()).index(cell.get(0)) + 1;

As you can see, hidden cells are not counted when the header index is calculated. That is done deliberately for the case where several weight-selector columns are in the same table: Since the header cell is deleted while the other cells are just hidden (working around a Safari rendering bug, according to a comment), the header indices will shift while the column indices remain constant. Thus the "not(:hidden)" condition.

Obviously, when the entire table is hidden inside a collapsed fieldset or a vertical tab or any other place, *all* columns count as hidden while this is executed. That makes the headerIndex undefined or completely incorrect.

As a fix, I suggest adding a new class to the hidden cells and checking for that when calculating the headerIndex.

Comments

cburschka’s picture

Status: Active » Needs review
StatusFileSize
new1.34 KB

Simple change, and it works like a charm.

q0rban’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of #303189: Tabledrag doesn't hide columns when the whole table is initially hidden. Please test out the existing patches there.

cburschka’s picture

This patch is both older and simpler than that in the other issue. But oh well.

q0rban’s picture

This patch is both older and simpler than that in the other issue. But oh well.

Please post your patches here, then! :) BUT… simpler is better, IMO.

EDIT: I meant please post your patches in the other issue. d'oh!