Why Is `data(“kendogrid”)` Undefined?

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

I'm a starter in kendo.ui, I've written this code to create kendo.ui.grid

@(Html.Kendo().Grid<BrandViewModel>(Model)     .Name("Grid")     .Columns(columns =>     {         columns.Bound(p => p.BrandName);         columns.Bound(p => p.BrandAbbr);         columns.Bound(p => p.SrcImage);          columns.Command(command => command.Custom("Edit").Click("editItem"));      })      .DataSource(dataSource => dataSource         .Ajax()         .Read(read => read.Action("CustomCommand_Read", "Brand"))         .Model(model => model.Id(p => p.Id))     ) ) 

When the user clicks the edit button in grid it will show Edit view in kendo.ui.window and the user can edit data.

@(Html.Kendo().Window().Name("Details")     .Title("Customer Details")     .Visible(false)     .Modal(true)     .Height(400)     .Draggable(true)     .Width(300)     .Events(events => events.Close("onClose")) )  <script type="text/x-kendo-template" id="template">     <div id="details-container">         <!-- this will be the content of the popup -->         BrandName: <input type='text' value='#= BrandName #' />     </div> </script>   <script type="text/javascript">     var detailsTemplate = kendo.template($("#template").html());     var windowObject;      $(document).ready(function () {         windowObject = $("#Details").data("kendoWindow");     });      function editItem(e) {         e.preventDefault();          var dataItem = this.dataItem($(e.currentTarget).closest("tr"));          windowObject.refresh({             url: "/Brand/Edit/" + dataItem.Id         });         windowObject.center().open();     }      function onClose(e) {         var grid = $("#Grid").data("kendoGrid").dataSource.read();      }  </script> 

but in onClose method $("#Grid").data("kendoGrid") is Undefined, please help me, thanks all

回答1:

try Window load event

$(window).load(function () { var grid = $("#grid").data("kendoGrid"); 

this work for me.



回答2:

var grid = $("#Grid").data("kendoGrid"); //call grid by Name of Grid you used in razor



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!