我和Kendo UI一起工作已经有一段时间了,我无意中发现了我无法解释的行为
当您访问网格上的http://demos.telerik.com/kendo-ui/grid/remote-data-binding时,您可以看到总共830个元素。
当你去控制台运行
$("#grid").data("kendoGrid").dataSource.view()您将收到20个元素的数组(如预期的那样)。当你跑的时候
$("#grid").data("kendoGrid").dataSource.data()您将接收相同20个元素的数组。我试着使用过滤器,根据我的经验,.data()的行为与view()完全一样,这很奇怪。据我所知,在使用view()时,我应该接收20个元素,但在使用data()时,我应该接收所有830个元素。
我做错什么了吗?数据过滤元素(和分页)在后端吗?这是我的后端方法,它为我的网格返回数据。
public ActionResult IndexDataSource([DataSourceRequest] DataSourceRequest request)
{
var customers = this.GetViewModel();
return this.Json(customers.ToDataSourceResult(request));
}发布于 2014-10-19 20:15:12
在MVC语法中明确设置.ServerOperation(false)解决了问题。我想感谢j4ro为我指出了这个选项。
@(Html.Kendo().Grid<Model>()
.Name("Grid")
.Columns(columns =>
{
...
})
.Sortable()
.Filterable()
.Resizable(r => r.Columns(true))
.Events(e => e.DataBound("CustomerGridDataBound"))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new[] { 5, 50, 200, 99999 })
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.ServerOperation(false) // you need to add this to be able to use .data()
.Read(read => read.Action("ActionDataSource", "Controller"))
))发布于 2014-10-18 06:09:18
注意,在这个示例中,serverFiltering属性被设置为true ( serverPaging,serverSorting也是)。因此,在javaScript方面,无论您使用的是view()方法还是data()方法,都会有相同的数据。控制器的acton返回给显示的是同一个数组:一个,选中的页面。要使view()像文档一样工作,您必须关闭我说过的所有属性,并在一堆中读取整个数据。
https://stackoverflow.com/questions/26435860
复制相似问题