What I want to do is create a grid, and when you click on it opens up a detail grid for the user to choose. I created them like this
@(Html.Kendo().Grid(Model.items).Name("Access")
.Columns(columns =>
{
columns.Bound("ProjId").Width(220).Title("Project #");
})
.ClientDetailTemplateId("detailTemplateId")
.Selectable()
.Events(events => events.DetailInit("initDetailGrid"))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
)
)
<script id="detailTemplateId" type="text/kendo-tmpl">
@(Html.Kendo().Grid(Model.items.subItems).Name("detailGrid")
.Columns(columns => columns.Bound("itemsName").Title("Select"))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
)
.ToClientTemplate()
)
</script>
The model is created like this
public class ItemModel
{
public List<myItems> items;
public ItemModel()
{
items = new List<myItems>();
}
}
the myItems class is defined elsewhere, and inside the myItems class is a sub class which is the subItems that I am trying to get
public class myItems
{
public int ProjId;
public List<otherItems> subItems;
public myItems(){
subItems = new List<otherItems>();
}
public class otherItems()
{
public String itemsName;
public int itemId
}
}
but when I try to bind it here @(Html.Kendo().Grid(Model.items.subItems).Name("detailGrid")
says that it cannot resolve symbol? Am I doing it the right way? or do I have to bing it to items, then get the values in inside the columns using the columns template?
Basically when dealing with server-bound Grids you should use DetailTemplate instead of DetailTemplateID
Here is an example:
@model IEnumerable<Kendo.Mvc.Examples.Models.Product>
@helper ThirdLevelHelper(Kendo.Mvc.Examples.Models.Product x)
{
@(Html.Kendo().Grid(Model)
.Name("Grid"+Guid.NewGuid())
.Columns(columns => {
columns.Bound(p => p.ProductID).Groupable(false);
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice);
columns.Bound(p => p.UnitsInStock);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Groupable()
)
}
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.ProductID).Groupable(false);
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice);
columns.Bound(p => p.UnitsInStock);
})
.DetailTemplate(@<text>
@(Html.Kendo().Grid(Model)
.Name("Grid"+item.ProductID)
.Columns(columns => {
columns.Bound(p => p.ProductID).Groupable(false);
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice);
columns.Bound(p => p.UnitsInStock);
})
.DetailTemplate(x=>ThirdLevelHelper(x))
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Groupable()
)
</text>)
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Groupable()
)
Nitice that for the 3rd level of the hierarchy you will have to use helper method, because Razor does not allow such nesting @ operators.
ALso you have to find a way and guarantee that the name of each Grid widget down the hierarchy is unique. This is usually done by appening sufix.
Also take a closer look and see how context is propagated down to the nested Grids, by passing the current item, it is slightly different when using a helper.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments