Hey,
I am trying to choose a different template for a popup editor depending on whether a new entry is inserted or an already existing one is modified. I am aware that I probably have to subscribe to the "beforeEdit" event of the grid and act depending on whether e.model.isNew() returns true or false.
However, I was not able to set a different template based on this decision yet. Could you please outline what the cleanest way for doing this would be?
So far my code looks similar to this:
@(Html.Kendo().Grid<
Data.Promotion
>()
.Name("promotionGrid")
.Columns(c =>
{
...
c.Command(cmd => cmd.Edit()).Width(120);
c.Command(cmd => cmd.Destroy()).Width(120);
})
.Events(e =>
{
e.BeforeEdit("beforeEdit");
e.Edit("edit");
})
.DataSource(c =>
{
c.Ajax()
.Read(o => o.Url("CodeManagement?handler=Read").Data("forgeryToken"))
...
.Model(m =>
{
m.Id("PromotionId");
...
});
})
.ToolBar(c =>
{
c.Create();
})
.Editable(c =>
{
c.Mode(GridEditMode.PopUp);
c.TemplateName("Promotion"); // using a static template right now, we want to change that
})
)
Moreover, in the Edit-template, I have to constrain a DatePicker based on some model properties. However, the Model field is not set which leads to a NullReferenceException. Is there any way to set the Model field of the template to the entry that is currently being edited/created?
Thank you.