Accessing serverSorting/Grouping/Filtering/Paging in MVC Controller

4 posts, 1 answers
  1. Grant
    Grant avatar
    42 posts
    Member since:
    Jul 2016

    Posted 13 Sep Link to this post

    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

  2. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 15 Sep Link to this post

    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.
     
  3. Kendo UI is VS 2017 Ready
  4. Grant
    Grant avatar
    42 posts
    Member since:
    Jul 2016

    Posted 16 Sep in reply to Boyan Dimitrov Link to this post

    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

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Sep Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready