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

SetOptions and Toolbar

3 Answers 613 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gusev
Top achievements
Rank 1
Gusev asked on 20 Dec 2017, 12:49 PM
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

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 22 Dec 2017, 09:31 AM
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.
0
Jigisha
Top achievements
Rank 1
answered on 27 Sep 2019, 11:35 PM

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);
          }
      })

0
Viktor Tachev
Telerik team
answered on 01 Oct 2019, 10:49 AM

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.
Tags
Grid
Asked by
Gusev
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Jigisha
Top achievements
Rank 1
Share this question
or