DataTables state() set function
DataTables state() set function

I have been using the state() function to get the state, and then modify one of the columns' visibility and set the state of the table back to that modified state with table.state(x); table.draw(false);
This has worked for me on v2.x, and I see that on the state() documentation page that this was available since v1.10, but I have not been able to make it work on v1.13. I'm wondering if the set state overload is something that is only available in later versions and it was just not mentioned there?
Thanks.
This question has an accepted answers - jump to answer
Answers
Setting the
state()
in this test case works with 1.13.11:https://live.datatables.net/kawobuvu/1/edit
Do you get console errors with trying to use
state()
with 1.13? For help debugging please update my test case or provide a test case showing the issue.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
If you go to your test case even, you can open the console and see an error when you rerun. It will say:
"TypeError: table.state(...).draw is not a function
I believe this is happening because the overload with the state as an argument doesn't exist, and it defaults to running the normal state() function, which is returning the state of the table, not the DataTables API, on which of course .draw() does not exist.
Here's another example that further illustrates this:
https://live.datatables.net/kawobuvu/2/edit
I got bit by the saved state of testing first with DT 2.3.1 then changing to 1.13.11
I don't know where the 1.x docs are or if they are available to see if
state()
can be used as a setter. @allan can confirm and maybe update the docs to indicate the setter option is only available in 2.x.Maybe you can do something like this instead:
https://live.datatables.net/kawobuvu/4/edit
Kevin
In 1.x no, it cannot be used as a setter. I do actually have a
since
flag for the setter method in the source XML, but it looks like I don't render that into the HTML docs. Sorry about that - I'll fix that.Allan
Oke doke thank you