Hello webix friends.
If someone changes a setting in the datatable, sorts columns, etc., it’s saved in the database, so the user can restore their settings at any time. So far, so good.
But now the datatable is being changed, columns are being added or removed. But then an error occurs when I try to load the saved state back into the table with loadState()…
How can I handle this? Is there a way to prevent table.loadState() from loading?
I found out, that the problem appear if I f.i. add a column. And when I try to do this:
try{
table.setState(state);
}catch (e){
restore(id);
}
The set state give a messed datatable but does not catch the error…
How can I find out the the stored state of a datatable fit into the present config of columns??
Thank you for helping me…
Michael
Hello Michael
You can use getState method to get the current state of the table.
In the example below the state of the table is recieved when hiding or showing the table column (row 65): Code Snippet
Hello Natalia.
Thank you for your response.
But what I mean is. In our development of datatable We will add NEW columns to the actual column list. This is normally no problem, but user may store there state into the database and get them back when they come back. So the last stored state can be reloaded back. This is normally no problem but in the meantime we added some new columns to the datatable. And when some user try to load there older state into this datatable with the new column then datatable.loadState(state) crashes and we get some messy datatable… webix doesn’t know how to config the datatable anymore…
The solution for me would be to check if the stored state from the user fit with the columns of the datatable??
My solution is. To add the origin column list (datatable.config.columns) to the state properties. And compare them with the datatable columns before I load the state into the datatable.
is this a solution or do you have a better one?
Thank you so much
Michael
Hello Michael
You can compare two states of the datatable (the saved user’s table state with the current datatable state) using order array of the state which contains all columns (hidden and not hidden),
Please check the example: Code Snippet
Thank you Natalia.
I have used the ids and count this ids… as solution.
Michael