I have a kendo grid with an ajax data source. Before the read operation fires, I would like to apply filters dynamically to the data source. I tried to make this work with the RequestStart event of the data source. Specifically, I used e.sender._filter = filters; here to avoid multiple requests. The problem is that on the server, request.Filters is empty. I assume the reason is that_filter is read-only.
@(Html.Kendo().Grid<DataModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.Name);
})
.DataSource(dataSource => dataSource
.Ajax()
.Events(o => o.RequestStart("addFilters"))
.Read(read => read.Url("/data?handler=ReadData")
)
)
function addFilters(e) {
var filters = getGridFilters();
e.sender._filter = filters; //e.sender.filter(filters) works, but would result in an additional request and an infinite loop
}
function getGridFilters() {
var filters = { logic: "and", filters: [{ field: "Name", operator: "contains", value: "xyz"}]};
return filters;
}
public JsonResult OnPostReadData([DataSourceRequest] DataSourceRequest request) //request.Filters is empty
{}