SetOptions and Toolbar

4 posts, 0 answers
  1. Gusev
    Gusev avatar
    83 posts
    Member since:
    Dec 2012

    Posted 20 Dec 2017 Link to this post

    Hello guys,

    I need this functionality (https://demos.telerik.com/kendo-ui/grid/persist-state) but there are some problems.

    I want to clarify one thing:
     - You have a grid (you may check your own link - https://demos.telerik.com/aspnet-mvc/grid/editing-popup)
     - In console I write:
    var grid = $(".k-grid").data("kendoGrid");
    grid.setOptions(grid.getOptions())"
    and suddenly the toolbar breaks down.
      
    I've checked a javascript version (https://demos.telerik.com/kendo-ui/grid/editing-popup) and everything is fine over there.

    Let's check how "grid.options.toolbar" looks like:
    JS:
    {name: "create"}{name: "save"}{name: "cancel"}

    MVC:

    { command: { { name: null, buttonType: "ImageAndText", text: "create"}, ...
    So, it seems as "grid.options.toolbar" is useless when we talk about "MVC Wrappers".

    The most important part - https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-setOptions
    Yes, I see this note "When using the Grid MVC wrapper, any server templates will not be retrieved by the getOptions", but what can be counted as a "server template" talking about "toolbar"? If I use Kendo MVC, then everything or only when I use this one ".ToolBar(s => s.Template("<a random template>"))"?

    So should I use what's described in this link?
    https://github.com/telerik/ui-for-aspnet-mvc-examples/blob/master/grid/grid-preserve-server-toolbar-template-after-set-options/GridPerserveToolbarServerTemplate/Views/Home/Index.cshtml

    Thank you for your time and sorry, probably I'm not the first who's asked it
    Have a nice day
  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2500 posts

    Posted 22 Dec 2017 Link to this post

    Hi,

    Indeed when using a toolbar Template() it will not be persisted out of the box by getOptions. In that scenario it is recommended to use the approach illustrated in the example you are referring to

    This is necessary as the server-side templates are rendered server side. When restoring them via setOptions the templates need to be reinitialized to be displated correctly. 

    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Jigisha
    Jigisha avatar
    1 posts
    Member since:
    Mar 2019

    Posted 27 Sep 2019 Link to this post

    Hi Viktor,

    Can you please provide example for persisting default create toolbar generated using below code. How do I handle conditional part in this scenario.

    .ToolBar(toolbar =>
          {
              if (condition)
              {
                  toolbar.Create().Text(Resources.Constant_AddNewTemplate);
              }
          })

  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2500 posts

    Posted 01 Oct 2019 Link to this post

    Hello Jigisha,

     

    In order to implement the behavior you can add similar condition when restoring the Grid settings. You can access a field in JavaScript using the approach described in the stackoverflow thread below.

    https://stackoverflow.com/a/16361388

    When this is available you can construct the Grid options object accordingly and call setOptions.

     

    Regards,
    Viktor Tachev
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top