visibility bug
visibility bug

This used to work??
I have a session variable defined to hide/show columns that is set on a separate settings page.
Changing the column show/hide value and going back to the table and it is still showing or hiding depending on what it was previously.
Checked the code in the debugger and it is telling it to show when hidden and vice versa.
Example: I just changed the view_all_rooms column to show and yet it is not visible when I come back to the table.
Here is what the debugger is showing.
{ data: 'view_all_rooms', 'visible': 1 }, // 10 View All Rooms Column
Yet if I log out of the web app and back in, it is correct.
I just deleted the session storage key/value for this table: DataTables_staffTable_/team-page.php and refreshed the page, and it worked. I love you session cache values, but when the code says to show or hide a column, that should override what is in the cache. Right? Workaround?
thanks bill a
This question has an accepted answers - jump to answer
Answers
I don't follow how you are using the session variable and updating the Datatable column visibility.
Are you using
stateSave
?Can you post your code to show how you are doing this or better a link to a test case replicating the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
i have "stateSave": true,
the first time i load the page i have
{ data: 'view_all_rooms', 'visible': 1 }, and the column shows
next time i load the page i have
{ data: 'view_all_rooms', 'visible': 0}, yet the column still shows even though i have set visible to 0.
it appears to be using a DT session value for column visible and overriding what i have changed it to in the code.
if i turn off stateSave it works yet none of the other state variables are saved.
Is this the way it is suppose to work?
I can PM you a link to my app and a temp username and password if that helps
The way
stateSave
works is the Datatable will initialize with the configured options then load and apply the saved state. You can usestateLoadParams
to remove the options you don't want restored. For example this will allow the configured visibility of column 1 to be applied no matter what is saved:Try this example:
https://live.datatables.net/pesocito/1/edit
In the JS Bin menu use File > Clone to get a copy you can update. Use the
Run with JS
button or reload the page and you will see both the Position and Office column are hidden from the twocolumn().visible()
statements.Either comment out or remove both
column().visible()
statements and rerun or reload the page. You will see the Position column because ofstateLoadParams
and not see Office because its visibility was restored.The browser's console will show the structure of the saved state after
stateLoadParams
executes.Kevin
Kevin
THANK YOU. that worked perfect. here is how i coded it. is there a cleaner way of doing it?
Looks good to me. Glad its working.
Kevin