Is it possible to use the DataSourceRequest object as an action method parameter? What I've got currently is a grid that loads data, but then won't filter or sort. The paging seems to work.
I'm using Kendo UI verison 2015.3.930.
Thanks!
8 Answers, 1 is accepted
Hello Aaron,
Could you please verify that you have correctly included kendo.aspnetmvc.min.js file.
If you continue to experience difficulties please provide a detail information about the implementation you are using, such as Grid and DataSource declaration as well as server-side action method.
Regards,Rosen
Telerik
Yes, I have included kendo.aspnetmvc.min.js.
One strange thing that's happening is that when I add type: 'aspnetmvc-ajax' into the DataSource configuration the data source doesn't load any data and just doesn't work. If I take it out, then the grid loads data and acts normally, but the filter post to the server never fires.
This give you some more information about the issue I'm trying to solve. The following post I think explains the problem. In my case the problem is happening when trying to filter a grid column on a date value. We're using the date picker on the column to select a date to filter on, but I believe the timezone is different and so the filter doesn't work.
http://www.telerik.com/forums/kendo-grid-automatically-converting-timezone#kOFCrmYG0Em8FKn1B-EV9Q
Example:
On the column header I select 11/7/2015 to filter on. I can see that the value of "2015-11-07T07:00:00.000Z" is being passed in the request to the server in the grid filter.
The request on the server side is then showing that the server is receiving the value as "11/06/2015 23:00:00". I'm assuming this change in date value for the filter is happening because of a timezone difference.
So I wanted to try and solve the problem using the following code.
http://www.crowbarsolutions.com/ignoring-time-when-filtering-dates-in-telerik-kendo-grids/​
Hello Aaron,
Using the DataSourceRequest/DataSourceResult classes from Kendo.MVC assembly requires use of the aspnetmvc-ajax transport type on the client-side. This is needed as the transport uses specific parameterMap which format the request parameters for sorting, filtering, etc. in the appropriate way in which the DataSourceRequest ModelBinder will be able to populate the DataSourceRequest instance. The paging information will be OK without the aspnetmvc-ajax transport as page and pageSize are primitive values and will be bound directly.
Thus, in order to be able to tell what is causing filter and sort to not be populated, I would ask you to provide a small runnable sample in which the issue can be observed locally.
Rosen
Telerik
I've done some more testing and have found that I'm getting an exception when the grid first tries to load data. This is when I set the option type: 'aspnetmvc-ajax'.
System.ArgumentException: Invalid JSON primitive: sort.
var
dataSource =
new
kendo.data.DataSource({
pageSize: 50,
serverPaging:
true
,
serverFiltering:
true
,
serverSorting:
true
,
batch:
true
,
type: 'aspnetmvc-ajax',
transport: {
read: {
url: controller +
"/read"
,
contentType:
"application/json; charset=utf-8"
,
type:
"POST"
},
[HttpPost]
[Route(
"read"
)]
public
ActionResult Read([DataSourceRequest] Kendo.Mvc.UI.DataSourceRequest request)
{
var results = context.boks_recon_report.AsQueryable().OrderBy(e => e.ServerName).ToDataSourceResult(request);
return
Json(results);
}
Hello Aaron,
I suspect that the error is most probably cause by incorrect content type. You should remove the content type setting from read settings:
read: {
url: controller +
"/read"
,
// contentType: "application/json; charset=utf-8",
type:
"POST"
}
Rosen
Telerik