I'm trying to get some editor templates in child grids. They work fine in the parent grid but when I try to add them to the child grid, the .ToClientTemplate() returns invalid Template format. Not sure what else to do. Thnx
Here's the code :
(Parent grid):
@(Html.Kendo().Grid<PDT.Dashboard.Models.CategoryVM>()
.Name("CategoryGrid")
.HtmlAttributes(new { @class = "expandable-rows grid-within-grid" })
.Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation(false); })
.Columns(columns =>
{
columns.Bound(a => a.CategoryIconId)
.Title("Icon")
.ClientTemplate("<span class='icon30 gray-icon notes-icon-#= CategoryIconId #'></span>")
.EditorTemplateName("EditCategoryIcon")
columns.Bound(a => a.CategoryName)
.EditorTemplateName("EditCategoryName");
columns.Bound(a => a.IsDeleted)
.Title("Active")
.ClientTemplate("<span> #= IsDeleted ? 'Active' : 'Inactive' #</span>")
columns.Bound(a => a.SortOrder)
.EditorTemplateName("EditSortOrder")
columns.Command(command => { command.Edit().HtmlAttributes(new { title = "Edit" }); }).Width(55);
})
.Sortable()
.Pageable(p => p.PageSizes(new[] { 10, 20, 50, 100 }))
.ClientDetailTemplateId("AdminSubCategoryTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("GetCategories", "Permissions"))
.Create(create => create.Action("AddCategory", "Permissions"))
.Update(update => update.Action("UpdateCategory", "Permissions"))
.Model(model => { model.Id(m => m.CategoryId); })
.Sort(s => { s.Add(m => m.SortOrder).Ascending(); })
.Events(e =>
{
e.Error("categoryErrorHandler");
})
))
@(Html.Kendo().Grid<PDT.Dashboard.Models.SubCategoryVM>()
.Name("grid_#=CategoryId#")
.Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation(false); })
.ToolBar(tb => tb.Create())
.Columns(columns =>
{
columns.Bound(a => a.SubCategoryName)
.EditorTemplateName("EditSubCategoryName");
columns.Bound(a => a.IsDeleted)
.Title("Active")
.ClientTemplate("<span> \\#= IsDeleted ? 'Active' : 'Inactive' \\#</span>")
columns.Bound(a => a.SortOrder).Width(100);
columns.Command(command => { command.Edit(); }).Width(70);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetSubCategories", "Permissions", new { categoryId = "#=CategoryId#" }))
.Create(create => create.Action("AddSubCategory", "Permissions", new { parentCategoryId = "#=CategoryId#" }))
.Update(update => update.Action("UpdateSubCategory", "Permissions"))
.Model(model =>
{
model.Id(m => m.SubCategoryId);
model.Field(m => m.CategoryId).Editable(false);
})
.Sort(s => { s.Add(m => m.SortOrder).Ascending(); })
.Events(e =>
{
e.Error("subcategoryErrorHandler");
})
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
EditCategoryName.cshtml:
<span class="k-widget k-numerictextbox" >
<span class="k-numeric-wrap k-state-default k-expand-padding">
<input class="k-input text-box single-line" id="CategoryName" name="CategoryName" type="text" value="" data-bind="value:CategoryName">
</span>
</span>
EditSubCategoryName.cshtml:
<span class="k-widget k-numerictextbox" >
<span class="k-numeric-wrap k-state-default k-expand-padding">
<input class="k-input text-box single-line" id="SubCategoryName" name="SubCategoryName" type="text" value="" data-bind="value:SubCategoryName">
</span>
</span>
Here's the code :
(Parent grid):
@(Html.Kendo().Grid<PDT.Dashboard.Models.CategoryVM>()
.Name("CategoryGrid")
.HtmlAttributes(new { @class = "expandable-rows grid-within-grid" })
.Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation(false); })
.Columns(columns =>
{
columns.Bound(a => a.CategoryIconId)
.Title("Icon")
.ClientTemplate("<span class='icon30 gray-icon notes-icon-#= CategoryIconId #'></span>")
.EditorTemplateName("EditCategoryIcon")
columns.Bound(a => a.CategoryName)
.EditorTemplateName("EditCategoryName");
columns.Bound(a => a.IsDeleted)
.Title("Active")
.ClientTemplate("<span> #= IsDeleted ? 'Active' : 'Inactive' #</span>")
columns.Bound(a => a.SortOrder)
.EditorTemplateName("EditSortOrder")
columns.Command(command => { command.Edit().HtmlAttributes(new { title = "Edit" }); }).Width(55);
})
.Sortable()
.Pageable(p => p.PageSizes(new[] { 10, 20, 50, 100 }))
.ClientDetailTemplateId("AdminSubCategoryTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("GetCategories", "Permissions"))
.Create(create => create.Action("AddCategory", "Permissions"))
.Update(update => update.Action("UpdateCategory", "Permissions"))
.Model(model => { model.Id(m => m.CategoryId); })
.Sort(s => { s.Add(m => m.SortOrder).Ascending(); })
.Events(e =>
{
e.Error("categoryErrorHandler");
})
))
@(Html.Kendo().Grid<PDT.Dashboard.Models.SubCategoryVM>()
.Name("grid_#=CategoryId#")
.Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation(false); })
.ToolBar(tb => tb.Create())
.Columns(columns =>
{
columns.Bound(a => a.SubCategoryName)
.EditorTemplateName("EditSubCategoryName");
columns.Bound(a => a.IsDeleted)
.Title("Active")
.ClientTemplate("<span> \\#= IsDeleted ? 'Active' : 'Inactive' \\#</span>")
columns.Bound(a => a.SortOrder).Width(100);
columns.Command(command => { command.Edit(); }).Width(70);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("GetSubCategories", "Permissions", new { categoryId = "#=CategoryId#" }))
.Create(create => create.Action("AddSubCategory", "Permissions", new { parentCategoryId = "#=CategoryId#" }))
.Update(update => update.Action("UpdateSubCategory", "Permissions"))
.Model(model =>
{
model.Id(m => m.SubCategoryId);
model.Field(m => m.CategoryId).Editable(false);
})
.Sort(s => { s.Add(m => m.SortOrder).Ascending(); })
.Events(e =>
{
e.Error("subcategoryErrorHandler");
})
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
EditCategoryName.cshtml:
<span class="k-widget k-numerictextbox" >
<span class="k-numeric-wrap k-state-default k-expand-padding">
<input class="k-input text-box single-line" id="CategoryName" name="CategoryName" type="text" value="" data-bind="value:CategoryName">
</span>
</span>
EditSubCategoryName.cshtml:
<span class="k-widget k-numerictextbox" >
<span class="k-numeric-wrap k-state-default k-expand-padding">
<input class="k-input text-box single-line" id="SubCategoryName" name="SubCategoryName" type="text" value="" data-bind="value:SubCategoryName">
</span>
</span>