Potential bug: column selector + ColReorder
Potential bug: column selector + ColReorder
Selecting a column by index does not seem to work according to the documentation when the ColReorder extension is used. According to the documentation for column-selector
, the following code should select a column according to the internal data index, which never changes:
$(...).DataTable().column(1)
However, this seems to not be true. To see this potential bug, go to this colReorder example and open the Javascript console.
Run the following code, which returns the header name of the 2nd column (0-based indexing):
$($('#example').DataTable().column(1).header()).html()
As expected, it returns Position
, which is the text in the header for the 2nd column.
Now, drag to switch the ordering of the Name and Position columns so that Position comes first. Run the code above. I would expect it to return Position
again, because Position is still the 2nd column in the internal data index. However, it now returns Name
instead. Why?
Answers
Actually, ColReorder does intentionally change the column indexes. The
colReorder.transpose()
method can be used to convert from the original index to the new (and the other way around).Normally with ColReorder it can be useful to use
columns.name
to name each column and then use the name in the selector.Allan
Gotcha, thanks for clarifying that for me!