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

Detect in EditorTemplate if executed from Grid form builder

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
D.
Top achievements
Rank 1
D. asked on 14 Feb 2014, 07:38 AM
Hi,

I've been using Kendo UI with ASP.NET MVC and am very happy with it.
Still, I'm stuck with an issue:

I have an EditorTemplate which ouputs a Kendo UI DropDownList. As a best practice, I call .Deferred() on every widget I'm using to get all the JS initialization at the bottom of the page.
The issue I'm facing is that this EditorTemplate is used by the grid to build insert and edit popup forms, and in this case the .Deferred() does not work because the intialization script is executed before the grid actually builds the form.

What I'd like to achieve to avoid duplicating the EditorTemplates is to know, at runtime, whether the template is executed from a "normal" page or from a Kendo form builder.
I saw that you create your own HtmlHelper, passing along a GridViewDataContainer, but at runtime I'm always faced with the Html.ViewDataContainer being an instance of WebViewPage.

Do you know if there's a possibility of figuring this out so I can defer the JS scripts when appropriate?

Thanks in advance.
Mickaël Derriey

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Feb 2014, 08:16 AM
Hello Mickaël Derriey,

You could pass additional ViewData from the Grid indicating if the widget should be using deferred initialization. If the Grid uses InLine or InCell edit mode then you can pass the additional ViewData with the column EditorViewData method:
columns.Bound(o => o.Field).EditorViewData(new { UseDeffered = false });
@(
 Html.Kendo().DropDownListFor(m => m)
    ...
    .Deferred(ViewData["UseDeffered"] == null || (bool)ViewData["UseDeffered"])
)

If the Grid uses PopUp editing then you can pass the data with the Editable AdditionalViewData method:
.Editable(e => e.Mode(GridEditMode.PopUp).AdditionalViewData(new { UseDeffered = false }))


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
D.
Top achievements
Rank 1
answered on 18 Feb 2014, 03:06 PM
Hey Daniel,

Thanks for the tip, I didn't know data could be passed to the editor template, that's very interesting.
I'll try that ASAP, the way I found to get the information is hacky and dirty as possible...

I'm currently checking for the Id of the FormContext in the EditorTemplate.
Popup edit mode always sets it, and it seems like it's the only case I found where it's set...
Not very future-proof ;-)

Thanks again,
Mickaël Derriey
Tags
Grid
Asked by
D.
Top achievements
Rank 1
Answers by
Daniel
Telerik team
D.
Top achievements
Rank 1
Share this question
or