2013-12-23 65 views
1

我在mvc 4中创建了一个kendo层次结构网格。在执行网格时,层次结构网格会自动扩展到第一行,但是当我展开另一行时,新层次结构网格出现空白,而较早层次结构网格(默认出现)的数据已更改。层次结构Kendo Grid在Mvc中无法正常工作4

1.我如何才能让它显示 特定行的层次结构网格中的数据,而不仅仅是默认打开的网格中?

2.另外我怎样才能防止行的默认扩展。

查看:

@(Html.Kendo().Grid<KendoUI.Models.EmployeeViewModel>() 
      .Name("grid") 
      .Columns(columns => 
      { 
       columns.Bound(p => p.name).Title("Name"); 
       columns.Bound(p => p.gender).Title("Gender"); 
       columns.Bound(p => p.designation).Title("Designation").Width("300px"); 
       columns.Bound(p => p.department).Title("Department").Width("300px"); 
      }) 
      .ClientDetailTemplateId("template") 
      .HtmlAttributes(new { style = "height:430px;" }) 
      .Pageable() 
      .Navigatable() 
      .Sortable() 
      .Scrollable() 
      .DataSource(dataSource => dataSource // Configure the grid data source 
      .Ajax() 
      .Model(model => 
      { 
       model.Id(x => x.id); 
      }) 
      .Read(read => read.Action("Employee_Read", "Home")) // Set the action method which will return the data in JSON format 
      ) 
      .Events(events => events.DataBound("dataBound")) 
     ) 

<script id="template" type="text/kendo-tmpl"> 
    @(Html.Kendo().Grid<KendoUI.Models.EmployeeViewModel>() 
      .Name("grid_#id#") 
      .Columns(columns => 
      { 
       columns.Bound(p => p.id).Width(70); 
       columns.Bound(p => p.name).Width(110); 
       columns.Bound(p => p.gender).Width(110); 
      }) 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .PageSize(5) 
       .Read(read => read.Action("Department_Read", "Home", new { employeeID = "#=id#" })) 
      ) 
      .Pageable() 
      .Sortable() 
      .ToClientTemplate() 
    ) 
    </script> 
    <script> 
     function dataBound() { 
      this.expandRow(this.tbody.find("tr.k-master-row").first()); 
     } 
    </script> 

控制器:

public ActionResult Employee_Read([DataSourceRequest]DataSourceRequest request) 
     { 
      //code for grid 
      return Json(result, JsonRequestBehavior.AllowGet); 
     } 

public ActionResult Department_Read(Int32 employeeID, [DataSourceRequest]DataSourceRequest request) 
     { 
      // Code for hierarchy grid detail 
      return Json(result, JsonRequestBehavior.AllowGet); 
     } 
+0

你有什么成功? – Steve

回答

0
  1. 你在你的细节模板 犯了一个错误,你应该使用的.Name("grid_#=id#")代替.Name("grid_#id#")的 '=' 事项使用所有层次结构网格共享相同的ID所以每次只刷新第一个网格。
  2. 您的数据绑定()函数导致第一的默认扩展功能(每次网格绑定到数据源它。)
相关问题