在使用ds.query的过滤器中使用CustomField(Name())时出现问题,以便对网格的寻呼机进行过滤,排序和重新初始化,我创建了一个简化的示例,清楚地说明了问题:https://jsfiddle.net/juliemontreuil/4Ls4fb19/32/
var PageSize = 5; var data1 = [...]; var $grid = $("#BTGrid"); var sort = [{ field: "company", dir: "asc" }]; var dataSource = new kendo.data.DataSource({ data: data1, schema: { model: { id: "Id", fields: { Id: {}, Firstname: {}, LastName: {}, company: {}, email: {} }, Name: function() { return this.get("Firstname") + " " + this.get("LastName"); } } }, sort: sort, pageSize: PageSize //page size }); $grid.kendoGrid({ dataSource: dataSource, columns: [{ field: "Name()", title: "Name", }, { field: "company", title: "Company" }, { field: "email", title: "Email" }], scrollable: false, pageable: true, //enable paging resizable: true, sortable: { allowUnsort: false } }); $('.grid-filter').off('keyup').on('keyup', function() { var ds = $("#BTGrid").data("kendoGrid").dataSource; // debugger; var filterText = $(this).val(); var $filter = { logic: "or", filters: [{ field: "company", operator: "contains", value: filterText }, { field: "email", operator: "contains", value: filterText }, { field: "Name()", operator: "contains", value: filterText }] }; ds.query({ filter: $filter, sort: [{ field: "company", dir: "asc" }], page: 1, pageSize: PageSize }); });
,如果修改var PageSize = 5;到var PageSize = 25;过滤器将正常运行,因为数据数组只包含24个项目,请告知。
答案 0 :(得分:1)
我一直在测试你的代码,我注意到Name函数是失败的。
所以我为你做了这个: Solution whitout Name()
请注意,现在kendogrid使用模板:
$grid.kendoGrid({
dataSource: dataSource,
columns: [{
title: "Name",
template: '#= Firstname# #= LastName#',
}, {
field: "company",
title: "Company"
}, {
field: "email",
title: "Email"
}],
scrollable: false,
pageable: true, //enable paging
resizable: true,
sortable: {
allowUnsort: false
}
});
..是的,..当然,..现在你要说:“怎么不能用全名(名字+姓氏)过滤?”。
好吧,为了解决这种情况,您可以在“data1”中声明一个属性(FulName),然后在网格中和过滤器内部使用该属性。 希望这个想法适合你。 :)