How to manage stateSave value when we change the table?
How to manage stateSave value when we change the table?
Hi,
How to manage stateSave value when the table get changed?
I'm wondering what will be the best approach in the case we have stateSave values for a table
and the table get changed if we add, remove a column or change column order ....
Because when doing this datatables will throw an error if we don't clear the stateSave values...
Does the only available method is to clear the stateSave values?
As it is not easy to parse the stateSave value so I'm out of idea...
This question has an accepted answers - jump to answer
Answers
Hi @lenamtl ,
The callback function,
stateLoadCallback
, is a good place to manipulate the saved data. You could probably detect if the table shape has changed and just destroy that saved information so that it starts fresh.Cheers,
Colin
How do you detect the table shape have changed?
By counting the columns and the rows. You could store the value that was relevant to the saved state in the saved data with
stateSaveParams
, and compare it again when it's reloaded.It won't cover the case if a column was changed, let say the column was for address and get change to phone, so column equal the same qty as before...
is there a way to save custom settings in stateSaveParams?
Maybe having a way to version individual table could be another solution,
For now, I will continue to delete the stateSave value using my update script as there is no easy way to update the stateSave values (this is not easy to parse the stateSave values) and may produce errors and delay for nothing if there is no changes..
Hi @lenamtl ,
stateSave
isn't that smart - see this example here. It only stores the current searches, orders, and paging position (plus a time check). So if the column types changed, it wouldn't know about it, or care even.Cheers,
Colin
Yes I know this is why this is hard to parse...
How would you compare both result ?
Hi @lenamtl .
If you take a look at the console in that example I posted, you'll see it's just a structure. So you can do checks like
data.columns.length
for example.Cheers,
Colin
I figured out
From Datatables
from LocalStorage