我在MVC项目中用jquery实现了kendo UI Grid。我想进行服务器过滤,但是我的控制器中没有得到过滤对象。我尝试了以下代码。
JS代码。
$("#AccountLedgerReport").kendoGrid({
toolbar: ["excel", "pdf"],
excel: {
allPages: true,
filterable: true
},
pdf: {
filterable: true
},
dataSource: {
type: "aspnetmvc-ajax",
serverSorting: true,
serverPaging: true,
serverFiltering: true,
transport: {
read: getActionURL() + "url?site....,
type: "POST",
dataType: "json"
},
pageSize: 50,
schema: {
return data;
},
data: 'data',
total: 'total',
model: {
fields: {
PnrNumber: { type: "string" }
, TransactionId: { type: "number" }
, CreatedByName: { type: "string" }
...
}
},
},
aggregate: [
{ field: "xxx", aggregate: "max" }
]
},
dataBound: onDataBound,
sortable: true,
filterable: true,
columnMenu: true,
filterable: {
mode: "row"
},
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5,
serverFiltering: true,
pageSizes: 50
},
columns: [
{
field: "x",
title: "x",
format: x,
width: 145,
footerTemplate: 'Total :',
filterable: {
cell: {
showOperators: true
}
},
},...
]
});
然后我的控制器端我想获取数据的地方是 。
public JsonResult actionname(int site..., IDictionary<string, string>[] sort, .., IDictionary<string, Tuple<string, string, string>[]> filter)
这里我面临的挑战是过滤器参数。Sorting的数据在需要的时候会出现,但是filter的数据却没有出现。
请求的URL如下。
https://localhost/...?site..&sort[0][field]=xx&sort[0][dir]=asc
这是排序完成的时候
https://localhost/..?site...&filter[logic]=and&filter[filters][0][operator]=eq&filter[filters][0][value]=held&filter[filters][0][field]=xxx
这是在过滤过程中的时候。
我不明白我哪里做错了。
根据官方文档的详细说明,Action方法中剩下的参数很少,所以请用下面的内容更新你的控制器动作。不幸的是,我之前也遇到过这个问题,我这边已经解决了。这样的话,排序和过滤就可以完美的工作了。请尝试这种方法。
JS代码
$("#AccountLedgerReport").kendoGrid({
toolbar: ["excel", "pdf"],
excel: {
allPages: true,
filterable: true
},
pdf: {
filterable: true
},
dataSource: {
type: "aspnetmvc-ajax",
serverSorting: true,
serverPaging: true,
serverFiltering: true,
transport: {
read: getActionURL() + "url?site....,
type: "POST",
dataType: "json"
},
pageSize: 50,
schema: {
return data;
},
data: 'data',
total: 'total',
model: {
fields: {
PnrNumber: { type: "string" }
, TransactionId: { type: "number" }
, CreatedByName: { type: "string" }
...
}
},
},
aggregate: [
{ field: "xxx", aggregate: "max" }
]
},
dataBound: onDataBound,
sortable: true,
filterable: true,
columnMenu: true,
filterable: {
mode: "row"
},
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5,
serverFiltering: true,
pageSizes: 50
},
columns: [
{
field: "x",
title: "x",
format: x,
width: 145,
footerTemplate: 'Total :',
filterable: {
cell: {
showOperators: true
}
},
},...
]
});
动作控制器
public JsonResult YourActionName(int id, DateTime startDate, DateTime endDate, int take, int skip, int page, IDictionary<string, string>[] sort, int dateFilterOn, string number)