asp.net-mvc – Kendo UI Grid一次只扩展一行

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – Kendo UI Grid一次只扩展一行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个Kendo Grid,我希望一次只能扩展一行进行细节编辑.最简单的方法是什么?
  1. @(Html.Kendo().Grid<MyModel>()
  2. .Name("MyGrid")
  3. .ClientDetailTemplateId("MyTemplate")
  4. .Columns(columns =>
  5. {
  6. columns.Bound(b => b.Code);
  7. columns.Bound(b => b.Name);
  8. columns.Bound(b => b.Description);
  9. ...
  10. columns.Command(cmd => { cmd.Edit(); cmd.Destroy(); });
  11. })
  12. .ToolBar(toolbar => toolbar.Create())
  13. .Editable(editable => editable.Mode(GridEditMode.InLine))
  14. .DataSource(dataSource => dataSource
  15. .Ajax()
  16. .Model(model => model.Id(a => a.Id))
  17. .Create(create => create.Action("Create","SysMaint",new { id = Model.ProjectId }))
  18. .Read(read => read.Action("Read",new { projectId = Model.ProjectId }))
  19. .Update(update => update.Action("Update","SysMaint"))
  20. .Destroy(destroy => destroy.Action("Destroy","SysMaint"))
  21. )
  22. )
  23.  
  24. <script id="MyTemplate" type="text/kendo-tmpl">
  25. @(Html.Kendo().TabStrip()
  26. .Name("TabStrip_#=Id#")
  27. .SelectedIndex(0)
  28. .Items(items =>
  29. {
  30. items.Add().Text("A").LoadContentFrom("MyPartialA",new { id = "#=Id#" });
  31. items.Add().Text("B").LoadContentFrom("MyPartialB",new { id = "#=Id#" });
  32. })
  33. .ToClientTemplate()
  34. )
  35. </script>

解决方法

结束这很简单.只需添加这几行.
  1. ...
  2. .Update(update => update.Action("Update","SysMaint"))
  3. )
  4. .Events(events => events.DetailExpand("detailExpand"))
  5. )
  6.  
  7. <script type="text/javascript">
  8. var expandedRow;
  9. function detailExpand(e) {
  10. // Only one open at a time
  11. if (expandedRow != null && expandedRow[0] != e.masterRow[0]) {
  12. var grid = $('#MyGrid').data('kendoGrid');
  13. grid.collapseRow(expandedRow);
  14. }
  15. expandedRow = e.masterRow;
  16. }
  17. </script>

我希望这有助于某人.

猜你在找的asp.Net相关文章