SaveState + ColReorder + ColVis

SaveState + ColReorder + ColVis

SawitarSawitar Posts: 1Questions: 1Answers: 0

Link to test case: https://jsbin.com/kogepehuze/edit?html,js,output
Debugger code (debug.datatables.net): ocahef
Error messages shown: none
Description of problem:

There is a problem while combining ColReorder, ColVis and save stateSave.
Columns shown after loading saved state that had column reordered past other hidden ones are different.
Steps to reproduce:
- user saves state "full"
- user reorder columns (in example i have put "Position" to the end of table)
- user sets visibility of other columns before one that was moved (i have hid "Start Date", "Salary" and "Name")
- user saves "view" state
- user loads "full" state
- user loads "view"
At this point the only columns that will be displayed are Age, Start Date, Salary

Is there any workaround this? It is quite problematic for users :(

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin

    Hi,

    Interesting - thank you. I'm seeing something slightly different at the final step, although it is still wrong. The columns shown for me, based on those instructions are "Name, Office, Age, Start date".

    I'm fairly certain that the state restoration is not taking into account the change in the column indexes. What happens with ColReorder is that is actually changes the column indexes, so any references to an index needs to be updated. I strongly suspect that is the missing piece here.

    I'm currently working on a complete rewrite for ColReorder, so while I don't have an immediate fix (other than to suggest turning off column reordering), I will include this test case as part of my work to see if I can resolve it for the new release.

    Allan

  • allanallan Posts: 63,414Questions: 1Answers: 10,454 Site admin
    Answer ✓

    Thinking about it a bit more - it is an indexing issue, but also ordering. What is happening is that the column visibility is restored on the column ordering first, then the columns reordered. But it needs to be the other way around - set the column order and then manipulate based on the saved column indexes.

    That's going to need a new event from DataTables (pre-state-load or something that ColReorder can work on.

    So yup, no quick fix I'm afraid, but I am going to get it into the current development I'm doing.

    Allan

  • PabloCamaraPabloCamara Posts: 16Questions: 4Answers: 0

    Hola , eso me pasa a mi también. La solución para mi . Table.colreorder.reorder() que establece el orden original. Por que si restauras el estado con el orden modificado se confunde. Así creo. El problema de colreorder es el número de iteraciones. Table.colreorder.order([0,1,,,,,N) creo que es más rápido.

  • PabloCamaraPabloCamara Posts: 16Questions: 4Answers: 0
    edited December 2023

    Si se hace alguna mejora en colreorder sería muy interesante que por cada reorder NO desencadenara evento , es decir que una vez se han re oredenado todas las columnas efectué un único evento( ajax,Draw) , con un indicador sería magnífico.

Sign In or Register to comment.