Hello.
I am trying to use the Kendo UI Grid with the DataSourceRequest object, in an MVC3 web application.
When I use the MVC helpers to define the grid with razor notation, it works correctly, with paging, filtering, sorting, etc.
But, because of our architecture, we have to use the attribute-driven notation, like so:
The controller's action code is exactly the same in both situations:
That's probably why the option parameters are not being sent to the action, but what do I have to do to format the options correctly?
This is the script I'm using to define the transport read function for the datasource:
What do I have to do to send the options data correctly?
Thanks!
I am trying to use the Kendo UI Grid with the DataSourceRequest object, in an MVC3 web application.
When I use the MVC helpers to define the grid with razor notation, it works correctly, with paging, filtering, sorting, etc.
But, because of our architecture, we have to use the attribute-driven notation, like so:
<div id="userGrid" data-role="grid" data-columns='[{ "field": "Name", "title": "Users"}]' data-filterable='true' data-navigatable="false" data-pageable='true' data-selectable="row" data-sortable='{"mode": "single", "allowUnsort": true}' data-bind="source: userDataSource"></div>
The controller's action code is exactly the same in both situations:
public ActionResult ListUsers([DataSourceRequest] DataSourceRequest request) { return Json(GetUsers().ToDataSourceResult(request)); } When using attribute-driven, the grid works fine listing the records and the paging also works. But not the filter and sorting. Debugging the controller, I found out that the "request" parameter only has the Page and PageSize values, while the Filter and Sort properties are null. Looking at the POST request sent by each version of the grid, I found some differences. This is the request sent by the Grid created with the MVC helper: sort:
page:1
pageSize:10
group:
filter:Name~contains~'aaa' And this is the request sent by the attribute-driven: take:30
skip:0
page:1
pageSize:30
sort[0][field]:Name
sort[0][dir]:asc
filter[filters][0][field]:Name
filter[filters][0][operator]:contains
filter[filters][0][value]:25
filter[logic]:and
That's probably why the option parameters are not being sent to the action, but what do I have to do to format the options correctly?
This is the script I'm using to define the transport read function for the datasource:
read: function (options) { $.ajax({ url: '/home/ListUsers', type: 'POST', data: options.data, success: function (data, textStatus, jqXHR) { options.success(data); }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); } }); }
What do I have to do to send the options data correctly?
Thanks!