Problem with fnSaveState and fnLoadState
Problem with fnSaveState and fnLoadState
smithk86
Posts: 3Questions: 0Answers: 0
I am trying to implement fnSaveState and fnLoadState. My implementation is a near-exact replica of the examples in the documentation. When the functions are in place, the cookie-based state saves and loads perfectly; the table draws correctly. Once I enable fnSaveState and fnLoadState, the state saves and loads correctly from the server but the table fails to draw correctly. When the state returned is false (the first time DataTables is called), the table draws correctly. Once a state object is returned and the DataTables attempts to implement the state, two column headers get drawn (one scrolls left and right with the table and the other is fixed) and the JavaScript console throws a "o.aoColumns[iVis] is undefined" error (line 3137 of jquery.dataTables.js; I debug with Firebug). I have examined oLoadedState and the state appears to be loaded correctly. Something is tripping up DataTables when it tried to draw the headers.
I do use ColVis with some columns invisible by default. Thinking maybe ColVis was causing the problem, I tried disabling ColVis and setting all the columns to visible default to no avail.
I've been banging my head on this for 24 hours...any thoughts? I am using v1.9.1
I do use ColVis with some columns invisible by default. Thinking maybe ColVis was causing the problem, I tried disabling ColVis and setting all the columns to visible default to no avail.
I've been banging my head on this for 24 hours...any thoughts? I am using v1.9.1
This discussion has been closed.
Replies
Allan
The table resides on a secure intranet page which contains data that my ISO probably wouldn't want me posting to the world. Would emailing you some images suffice?
Allan
Created a fnStateLoaded callback which was just "function(o,oData){console.log(JSON.stringify(oData));}". I examined the returned JSON string with and without my custom fnStateLoad and fnStateSave callbacks. What did I find? The state returned by my server had quotes around all of the int datatypes - they were no longer integers.
Because of how my server-side code retreives and sends the state back, it made it easier in fnSaveState to do [quote]data: { 'state': oData }[/quote] and encapsulate the oData object into its own variable on the webserver. Because of this, I needed to do [quote]data: { 'state': JSON.stringify( oData ) }[/quote] in fnStateSave, and a [quote]json_decode($oData)[/quote] once PHP retrieved the data. This way, the server receives a JSON string and the server turns it back into an object and stores that object in the session variable.
When fnLoadState is called, the server gets the PHP object, runs json_encode and prints the json string for jQuery to interpret.
WIthout comparing the two JSON strings side by side...it looked like they were the same...
The joy of coding! Thanks again for your help and an awesome tool for anyone dealing with gobs of data!
At some point I really want to do a debug version of DataTables which will just go completely overboard with the amount of trace and debug data to catch exactly this sort of thing. One day...
Great to hear you've got it going now :-)
Allan