getOptions / setOptions - Filter dropdown blank

3 posts, 1 answers
  1. Marv
    Marv avatar
    3 posts
    Member since:
    Apr 2015

    Posted 03 Oct 2016 Link to this post

    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 mvc version, but I was able to reproduce this error in the browser using the javascript console on both the 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. Answer
    Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 05 Oct 2016 Link to this post

    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.

    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
  3. Marv
    Marv avatar
    3 posts
    Member since:
    Apr 2015

    Posted 05 Oct 2016 in reply to Maria Ilieva Link to this post

    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!

Back to Top