Reputation: 683
I have implemented kendo UI Grid in my MVC project with jquery. I want to perform server filtering, but I am not getting filter object into my controller. I have tried below code.
JS Code:
$("#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
}
},
},...
]
});
Then my controller side where i want to get data is :
public JsonResult actionname(int site..., IDictionary<string, string>[] sort, .., IDictionary<string, Tuple<string, string, string>[]> filter)
Here the challenge i am facing is filter parameter. Sorting's data is coming when they are needed but filter's is not coming.
The Requesting URL Being is as below:
https://localhost/...?site..&sort[0][field]=xx&sort[0][dir]=asc
This is when sorting is done.
https://localhost/..?site...&filter[logic]=and&filter[filters][0][operator]=eq&filter[filters][0][value]=held&filter[filters][0][field]=xxx
This is when the filter is in process.
I am not getting where i am doing wrong.
Upvotes: 2
Views: 1647
Reputation: 3122
There are few parameters left in the Action method as per official document detail, so please update your controller action with the following. Unfortunately, I had this issue before and resolved on my end. In this way sorting and filter will work perfectly. Please try this approach.
JS Code
$("#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
}
},
},...
]
});
Action Controller
public JsonResult YourActionName(int id, DateTime startDate, DateTime endDate, int take, int skip, int page, IDictionary<string, string>[] sort, int dateFilterOn, string number)
Upvotes: 2