在MVC中重新绑定Kendo Grid

时间:2012-07-12 12:55:32

标签: kendo-ui kendo-grid kendo-asp.net-mvc

我试图在使用下面的JavaScript过滤数据后按下按钮重新绑定Kendo Grid,但它无法正常工作。我该怎么办?

我的HTML代码使用Kendo.Mvc.Dll:

Html.Kendo().Grid<EquityStreet.Data.ESData.Proc_GetESManagersListAndFilterResult>().Name("GridESManager").BindTo(Model.ESManagersList).Columns(columns =>
 {
     columns.Bound(m => m.pkESManagerId).Template(@<input type="checkbox" id="@item.pkESManagerId" />).Title("").Width("2%");
     columns.Bound(m => m.pkESManagerId).Template(@<text> @item.FirstName @item.LastName</text>).Title("Name");
     columns.Bound(m => m.CompanyName).Title("Company");
     columns.Bound(m => m.MobileNo).Title("Phone Number");
     columns.Bound(m => m.ESManagerStatus).Template(@<text>@(item.ESManagerStatus == 1 ? "Active" : "Inactive")</text>).Title("Status");
     columns.Bound(m => m.pkESManagerId).Template(@<text> <a href="../Utilities/NewESManager?EId=@item.pkESManagerId" class="access_btn">
     </a><a href="../Utilities/NewESManager?EId=@item.pkESManagerId" class="notes_btn"></a><a href="../Utilities/NewESManager?EId=@item.pkESManagerId" class="edit_btn">
     </a><a href="../Utilities/NewESManager?EId=@item.pkESManagerId" class="delete_btn"></a>
            </text>).Title("Actions");
 }).ToolBar(tb =>
 {
     tb.Template("<div class='GridSearchHeader'><div style='float:left'><input type='button' value='Reset Pwd'><input type='button' value='Delete'></div><label>Filter: </label><input type='search' style='width: 230px' id='txtSearch'><select id='Status'><option value=-1>Select</option><option value=1>Active</option><option value=0>Inactive</option></select><input type='button' onclick='FilterList()' value='Go'><input type='button' value='Reset'></div>");
 }).Pageable()
                              )

JavaScript的:

 $.post('@Url.Action("FilterESManagerList", "../../Utilities")', { Keyword: Search, UserStatus: status }, function (result) {
            var grid = $("#GridESManager").data("kendoGrid");
            grid.dataSource.data(result);
            grid.refresh();
            alert(grid);
        });

3 个答案:

答案 0 :(得分:2)

调用grid.dataSource.data(result)应重新绑定网格,除非result不符合预期格式。

答案 1 :(得分:0)

看起来当使用ajax绑定时,调用grid.dataSource.fetch()将触发数据源中定义的read方法并自动重新绑定。

答案 2 :(得分:0)

试试这个:

$("#gridName").data("kendoGrid").dataSource.sync();