This is a migrated thread and some comments may be shown as answers.

Accessing serverSorting/Grouping/Filtering/Paging in MVC Controller

3 Answers 80 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Grant asked on 13 Sep 2016, 10:32 AM

Hi, 

Im using Spring to create a webapp and would like to implement serverSorting (as the first server option) in my kendoGrid.
The problem Im having is being able to read the "sort/group/filter/etc" data that is sent from the dataSource to by REST controller method.

This the URL being called by the browser:

http://localhost:8080/itd-boot-thymeleaf-demo/users?{%22sort%22:[{%22field%22:%22lastName%22,%22dir%22:%22asc%22}]}

This is my dataSource read atribute:

read: {
  url: "/itd-boot-thymeleaf-demo/users",
  contentType: "application/json",
  dataType: "json"
},

Here is my controller method:

@RequestMapping(method=RequestMethod.GET, produces="application/json")
@ResponseBody
public String getUsers() {
  System.out.println("### Getting users JSON");
  List<User> users = userService.getList();
  return User.toJsonArray(users);
}

What parameters should I add to "getUsers()" to map the request data so my method can read it?
I've tried to find examples of the serverSorting being used with MVC but haven't had any luck.

Please advise.

Thanks, 
Grant

3 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 15 Sep 2016, 07:32 AM

Hello Grant,

As you probably know, when remote requests are used, DataSource by default will use jQuery ajax to make those requests. Having this in mind the controller method should be configured in the same way (to parse the request) as when sending jQuery ajax requests from the client-side. 

Please note that there are some options sent to the server when serverPaging option is enabled: 


  • page - the page of data item to return (1 means the first page).

  • pageSize - the number of items to return.

  • skip - how many data items to skip.

  • take - the number of data items to return (the same as pageSize).

Use the parameterMap option to send the paging options in a different format.

Regards,
Boyan Dimitrov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 16 Sep 2016, 12:14 PM

Thanks for the response Dimitrov,

Thanks for highlighting the use of the ParameterMap, I feel that thats going to be the help I need. I'll have to use it to change to format of the server* options before sending the request.

Quick questions then, What is the purpose of the skip and take attributes? I know what skip means, but under what circumstances would such a feature be used? Same for take, why is it the same as pageSize?

Thanks, 
Grant

0
Boyan Dimitrov
Telerik team
answered on 20 Sep 2016, 07:17 AM

Hello Grant,

Skip and take are therms used languages for accessing data bases. Both terms are used in the paging functionality: 

    - skip - skips specific amount of items. For example user wants to get the items for 3rd page (let's say there are 10 items per page). In this case 20 items should be skipped.

    - take - it is the pageSize number (how many items to be requested and returned).  

Regards,
Boyan Dimitrov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Data Source
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Boyan Dimitrov
Telerik team
Grant
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or