我已经与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));
}
答案 0 :(得分:2)
请注意,在此示例中,serverFiltering属性设置为true(还有serverPaging,serverSorting)。因此,在javaScript方面,无论您使用view()还是data()方法,都将拥有相同的数据。它将是控制器的acton返回显示的相同数组:一个,选定的页面。 要使view()作为文档说你必须关闭我说的所有属性并在一堆中读取整个数据。
答案 1 :(得分:1)
在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"))
))