2017-01-15 18 views
1

我是kendo ui和mvc的新手。Kendo UI 2013 Grid實現親子(展開崩潰)

是否有人知道如何在具有展開/摺疊行爲的Kendo網格中實現父子結果?

+0

劍道的TreeList控件可能是沿着你以後的線條更:http://demos.telerik.com/kendo-ui/treelist/index –

+0

@Dinglemeyer 樹形列表是最新版本的劍道:(客戶機使用 當前版本是2013 –

回答

2

你可以找到一個例子here

基本上,您的主網格需要使用ClientDetailTemplateId()指向網格模板。然後你創建一個模板,這將是你的子網格。

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.EmployeeViewModel>() 
     .Name("grid") 
     .Columns(columns => 
     { 
      columns.Bound(e => e.FirstName).Width(110); 
      columns.Bound(e => e.LastName).Width(110); 
      columns.Bound(e => e.Country).Width(110); 
      columns.Bound(e => e.City).Width(110); 
      columns.Bound(e => e.Title); 

     })    
     .Sortable() 
     .Pageable() 
     .Scrollable() 
     .ClientDetailTemplateId("template") 
     .HtmlAttributes(new { style = "height:600px;" }) 
     .DataSource(dataSource => dataSource 
      .Ajax() 
      .PageSize(6) 
      .Read(read => read.Action("HierarchyBinding_Employees", "Grid"))    
     )   
     .Events(events => events.DataBound("dataBound")) 
) 

<script id="template" type="text/kendo-tmpl"> 
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>() 
      .Name("grid_#=EmployeeID#") // template expression, to be evaluated in the master context 
      .Columns(columns => 
      { 
       columns.Bound(o => o.OrderID).Width(110); 
       columns.Bound(o => o.ShipCountry).Width(110); 
       columns.Bound(o => o.ShipAddress).ClientTemplate("\\#= ShipAddress \\#"); // escaped template expression, to be evaluated in the child/detail context 
       columns.Bound(o => o.ShipName).Width(300); 
      }) 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .PageSize(10) 
       .Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" })) 
      ) 
      .Pageable() 
      .Sortable() 
      .ToClientTemplate() 
    ) 
</script> 
<script> 
    function dataBound() { 
     this.expandRow(this.tbody.find("tr.k-master-row").first()); 
    } 
</script> 
+0

謝謝你的努力,先生 。我會嘗試是一個,並希望它也支持多個親子(樹狀行爲) –

+0

嗨,尼古拉斯爵士。 我如何實現展開所有底層元素,包括子記錄與另一個孩子信息? 我試圖從一個簡單的網格過程模擬 –

+0

如果你想擴大父/子多個級別,你可能會更好使用TreeList的劍道部件,而不是網格? telerik鏈接:http://demos.telerik.com/kendo-ui/treelist/index –

0

這裏是樣本簡單的網格(親子沒有工作) $(函數(){

 var employee = [ 
      { empID: 1, lastName: "Sarsonas", firstName: "Christine", ReportingTo: 0, Subordinate: {} }, 
      { empID: 2, lastName: "Sarsonas", firstName: "Alyssa", ReportingTo: 0, Subordinate: {} }, 
      { empID: 3, lastName: "Sarsonas", firstName: "Avril", ReportingTo: 0, Subordinate: {} }, 
      { 
       empID: 10, lastName: "Uchiha", firstName: "Sasuke", ReportingTo: 1, 
       Subordinate: { empID: 100, lastName: "Uzumaki", firstName: "Naruto", ReportingTo: 10 } 
      } 
     ]; 


     $("#TestGrid").kendoGrid({ 
      columns: [ 
       { title: "EmpID", field: "empID" }, 
       { title: "LastName", field: "lastName"}, 
       { title: "FirstName", field: "firstName" }, 
       { title: "ReportingTo", field: "ReportingTo" } 
      ], 
      dataSource: { 
       data: employee 
      } 
    }); 
}); 
</script>