Colvis with server-side stateSaveCallback() is broken
Colvis with server-side stateSaveCallback() is broken
Minimal test case:
http://live.datatables.net/jebacowu/5/edit
During init, the visible
parameters are submitted as strings (see console).
When changing the visibility of a single column, the visible
parameters are submitted as boolean (see console).
Every second click in the "Column visibility" dropdown works.
Replies
Workaround (or maybe best practice?):
stringify the whole data, set content type to application/json and use the request body in the serverside script
Working example:
http://live.datatables.net/jebacowu/7/edit
Hi Pascal,
It is because the data being send back from the server from the state load is coming back as strings:
DataTables doesn't do any type correction - so when the state is next saved (which is almost immediately is for the first draw), those values are used - even although they are invalid.
In short, the data returned from the server is invalid from the looks of things. I think your workaround handles this nicely as it will preserve the types of the data, and then presumably your PHP script can just dump that whole object into the database - retaining the typing all the way though.
So yes, do what you've done . It applies here - it might not apply for everyone, so if anyone else reads this with the same problem, make sure you look at your type handling.
Allan
For anyone else reading this:
JSON.stringify()
and withcontentType: 'application/json'
$_REQUEST
but the request body withCase closed.