DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
627 stars 423 forks source link

ColVis + ColReorder breaks column({string}:name) selector #284

Closed niphlod closed 2 months ago

niphlod commented 3 months ago

It seems that ColVis + ColReorder in 2.0.x have some kind of issue when trying to fetch the index of the column via name

Managed to reproduce a small example here: v2.0.x https://live.datatables.net/cavataha/1

Instructions:

v 1.x https://live.datatables.net/xipuroqi/1

AllanJard commented 2 months ago

Hi, and sorry for the delay in replying back here.

This is actually an intentional change in ColReorder 2. When the column order is changed, it will no longer reorder the source data array. I never really liked that it did that, so instead, when an array data source is used, it will update the data source for the column from the original data array, so it doesn't mess with that array.

When using ColReorder, I generally recommend using objects rather than arrays - it can make the referencing much easier. See this updated example: https://live.datatables.net/cavataha/2/edit .

Another option would be to use [column().dataSrc()](https://datatables.net/reference/api/column().dataSrc()) to get the data source for the specified column, and then use that to get the data from the source array: https://live.datatables.net/cavataha/3/edit .

The second might be a simpler option for upgrading if you have a lot of code that works this way.

niphlod commented 1 month ago

confirmed, dataSrc is working fine.