This is a migrated thread and some comments may be shown as answers.

getOptions / setOptions - Filter dropdown blank

2 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marv
Top achievements
Rank 1
Marv asked on 03 Oct 2016, 01:19 PM

I was working on the grid persistence with getOptions and setOptions. I believe I was able to get it to work successfully, but I noticed something on one of filters. 

 

My grid has a dropdown selection, like in the 'Grid / Filter menu customization' demo. After the setOptions is called, the filter dropdown is blank.

 

We use the asp.net mvc version, but I was able to reproduce this error in the browser using the javascript console on both the asp.net mvc and the kendo ui versions of the 'Grid / Filter menu customization' demo (which has a filter dropdown on the City column).

 

In my above test of the 'Grid / Filter menu customization' demo, I saw the City filter dropdown go blank after setOptions is called. You are no longer able to select from a dropdown of cities.

 

Any input would be appreciated!

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 05 Oct 2016, 12:02 PM
Hello Marv,

Please note that there are some important things to keep in mind when using getOptions and setOptions.
  • calling setOptions() in a Grid event handler is not possible.
  • calling setOptions() in a function, which is related to the Grid's databinding mechanism may cause an endless loop.
  • JSON.stringify() cannot serialize function references (e.g. event handlers), so if stringification is used for the retrieved Grid state, all configuration fields, which represent function references, will be lost. You have two options to avoid this limitation: use a custom implementation to serialize JavaScript functions, or add the function references back to the deserialized configuration object before passing it to the setOptions method.
  • When using the Grid MVC wrapper, any server templates will not be retrieved by the getOptions method (e.g. toolbar or header templates with @<text></text> razor syntax). This is because the server templates are rendered server-side and do not have corresponding configuration options included in the JavaScript initialization statement that creates the Grid object client-side. As a result, the templates will be lost once the setOptions() method is invoked. There are two options to avoid the issue - use JavaScript initialization instead of an MVC wrapper, or add template configuration to the retrieved Grid state with the JavaScript equivalent syntax (e.g. headerTemplate and toolbar).

Make sure you are not hitting some of the limitation that may lead to the issue you are facing.

Regards,
Maria Ilieva
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Marv
Top achievements
Rank 1
answered on 05 Oct 2016, 01:31 PM

Maria, thank you for your post. It confirmed my suspicion that JSON.stringify() cannot serialize function references, and this was the reason why the custom filter dropdown was lost.

From your suggestion I was able to reset the function references to the deserialized configuration object _before_ passing it to the setOptions method. And this worked, the custom filter dropdown appeared successfully after setOptions was called. My previous attempt incorrectly set the function reference on the grid itself _after_ setOptions was called.

Thanks again!

Tags
Grid
Asked by
Marv
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Marv
Top achievements
Rank 1
Share this question
or