Hi ALL,
Now I save the grid's Persist State into my database, my way is convert the grid's options to json first, then transfer to my server and save into database.
My way to convert the grid's options is using custom implementation js, please refer to PersistState1.png. It can convert, save into database, load from database correct. It can work fine except below situation,
1, When my datasource bind with schema fileds type like boolean, date. these two type will make error when load data, error message refer to PersistState2.png, PersistState3.png. The relevant code is PersistState4.png
This issue just occur when apply the Persist State from server, if I comment the boolean, date type field out, then I can load data fine.
So I am think if the custom implementation js can convert the grid's options well or there maybe some variable (like the dt and ft in screen) need to be redeclare?
5 Answers, 1 is accepted
Hello Nick,
There should be a problem rather with the case when Kendo UI Grid is filtered by data than simply when there is a field of the model of type "date". Please refer to the http://dojo.telerik.com/iGEZi example.
A specific case is when grid id filtered by date field. When the options object is retrieved and then serialized into a string through JSON.stringify(options), the filter values are stored as strings as well. This means that they are treated as plain strings instead of Date objects. The problem is that the grid expects a Date object when loads its state. A valid workaround for this case is to parse the date filter values as shown:
function
parseDate(data, grid){
var
options = JSON.parse(data);
for
(
var
i = 0; i < options.dataSource.filter.filters.length; i++) {
if
(options.dataSource.filter.filters[i].field ==
"OrderDate"
){
options.dataSource.filter.filters[i].value =
new
Date(options.dataSource.filter.filters[i].value)
}
}
grid.setOptions(options);
}
Regards,
Boyan Dimitrov
Telerik
Hi Boyan,
Thanks for your help! I have test your solution in my side, but I cannot repeat the issue by using your code, it can work fine.
And I have done more test, I think the different is that my convert Json code is using from this url (https://github.com/tarruda/super-json), refer to persiststate1.png.
And the issue is occur after running the parameterMap function. I don't what is logic to do next that make this error, please give me some advise.
Hello Nick,
As far as I understand the problem occurs when the kendo.strigify() method is called against the options. Could you please try to call JSON.stringify() instead of the kendo.strigify() and give it a try?
Regards,
Boyan Dimitrov
Telerik
Hi Boyan,
I have changed the kendo.stringify() to JSON.stringify(), but the problem still occurs. and I do a test, I think this problem occurs after running the parameterMap method, and base on the error message " 'dt' is underfined", is that the 'dt' variable not register after reset that Grid options?
Hello Nick,
I am afraid that I am not able to replicate this error. Could you please isolate this error in sample dojo example so we can investigate it? A possible way is to use one of the Kendo UI Grid demos and just include the super json library and use it in order to serialize functions.
Regards,
Boyan Dimitrov
Telerik