Kendo Ui Model Binding 3 level Object

Jack Thor

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?

Petur Subev

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Model binding issues with Kendo complex object

From Dev

Kendo UI Tabstrip not binding

From Dev

kendo ui template binding

From Dev

kendo ui template binding

From Dev

Binding a Model class object to Kendo Grid using JSON result

From Dev

Binding a Model class object to Kendo Grid using JSON result

From Dev

Model binding fails with Kendo MultiSelect

From Dev

Kendo UI Visible binding is not working

From Dev

Kendo UI grid binding error

From Dev

Kendo UI MVC - DatePickerFor not binding

From Dev

Kendo UI Autocomplete custom binding

From Dev

Kendo UI for loop data binding

From Dev

Kendo UI treemap json binding

From Dev

Kendo UI treemap json binding

From Dev

binding process with angularjs and kendo ui

From Dev

How to bind model in Kendo UI?

From Dev

Kendo UI Treeview giving error "Uncaught TypeError: Object [ has no method 'level' "

From Dev

Model Binding to an object with a collection

From Dev

Changing Kendo chart type by model binding in AngularJS

From Dev

Kendo MVC NumericTextBoxFor default value not binding to model

From Dev

Detect Kendo UI Value-Binding Errors

From Dev

Kendo UI Scheduler not binding resources properly

From Dev

Binding XML data to Kendo ui menu dynamically

From Dev

Kendo UI Grid - Binding to navigation properties

From Dev

Kendo ui custom popup binding issue

From Dev

Kendo UI TreeList - Datasource Binding issue

From Dev

Binding to a Date to a Kendo UI for Angular DatePicker Component

From Dev

Backbone UI Model binding with Handlebars

From Dev

Counting 3 Level Model