Search code examples
angularprimengangular8primeng-turbotableprimeng-table

How to Maintain Order in multiselect PrimeNG when i am using this to hide table columns?


I am using multiselect PrimeNG to show or hide the columns of my ptable it's working fine for hiding columns but when i show them back they come and append to the last of the table so this is destroying the order of the table columns as i think multiselect creates a array of columns to show or hide it pops on hide and add back to the array hence it comes at last.


Solution

  • You have to just maintain two arrays one selected columns list say "selectedColumns" and other array of all columns say "columnsList" now on multiselect onChange event create a function say toggle() now in this function traverse the array columnsList and check whether the selectedColumns have that column name in it, that's it you will be able to maintain the order of the table columns even if you hide the columns in between or undo it.


    This is the correct approach just you have to understand it and implement. Hope it helps.