Save state and data-visible="false"
Save state and data-visible="false"
anzerkree
Posts: 2Questions: 1Answers: 0
Hello,
I have a table with columns that I want to hide by default using the data attribute data-visible="false".
<thead>
<tr>
<th data-exclude="true" data-width="50"></th>
<th data-orderable="false" >Col 2</th>
<th data-visible="false" >Col 3</th>
</tr>
</thead>
Everything works fine until I enable stateSave: true in my DataTable configuration.
var table = $(tableIdentifier).DataTable({
data: datas,
stateSave: true,
....
At that point, the data-visible attribute is no longer considered, and all columns become visible.
Is there a way to make both work?
That is, if no state exists, use the data attribute and otherwise override it with what's stored in memory?
Answers
data-visible="false"
withstateSave
seems to work in this test case:https://live.datatables.net/jowopitu/1/edit
Can you update the test case or provide a link to an example showing the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Are you doing something that might make the column visible? In this case the saved state will be what is used.
Kevin
Okay, I must be the biggest idiot ever and you're absolutely right.
I've just tested with another browser and then implemented a button to clear the datatables cache / state and it works fine on initialization.
Sorry to have bothered you for nothing
Not an idiot.
stateSave
can be confusing and frustrating sometimes when you expect a certain config and the saved state is restored to a different config.You could use
stateLoadParams
to stop the restoration of the visibility for that column. Or maybe useinitComplete
orready()
along withcolumn().visible()
to hide the column after the state has loaded.Kevin