javascript – How do I pass the pageSize parameter to the server?

Question:

There is a kend grid with the following parameters:

pageSize: 10,
    serverFiltering: true,
    serverSorting: true,
    serverPaging: true,

In the method on the server that the grid refers to, the parameter is set

public JsonResult AwardListsGrid(int pageSize){...}

If the method parameter is removed, then it will twitch when the grid is formed and the data will come to the UI, if not, then the method is not called and the grid is empty.

what is missing to pass the pageSize?

The DataSource looks like this:

dataSourceAwardListsGrid = new kendo.data.DataSource({
    transport: {
            read: {
                url: "Controller/AwardListsGrid",
                dateType: "json",
                type: "POST",
                complete: function (e) {

                }
            },
            parameterMap: function (options, operation) {
                if (operation === "read") {
                    return kendo.stringify(options);
                }
            }
    },
    schema:
     {
         data: function (data) {
             return data.AwardLists || [];
         },
         total: "Count",
         model: {
             fields: {
                 "field1": { editable: false, type: "int" },
                 "field2": { editable: false, type: "int" },
                 "field3": { editable: false, type: "string" },
                 "field4": { editable: false, type: "string" },
                 "field5": { editable: false, type: "string" }
             }
         }
     },
    pageSize: 10,
    serverFiltering: true,
    serverSorting: true,
    serverPaging: true,
    sortable: true
});

Just in case, I wrote pageSize: 10 and serverPaging: true in the kendo grid itself.

When the grid is empty, there are no extras. Neither on the server nor in the browser console.

Answer:

Your method is not called because routing is not configured on the server. With serverPaging: true, the request specifies:

  1. PageSize
  2. How many items to omit: (skip);
  3. How much to take. Same as pageSize;
  4. Current page number.

Therefore, your method is not called, it expects one parameter. On the server, you can change the action method:

public JsonResult AwardListsGrid(int pageSize, int skip){...}

Or if on the server you need to process only pageSize, then try to specify in parameterMap so that only information about pageSize is sent to the server:

parameterMap: function (options, operation) {
if (operation === "read") {
   return kendo.stringify({
       pageSize: options.pageSize
   });
}

But since if you still have server filtering and sorting enabled, it is better to use an object that contains all the parameters that came with the request. Use DataSourceRequest from Kendo.DynamicLinq:

public DataSourceResult Read([DataSourceRequest] DataSourceRequest request)
{
     /*Можете получить доступ к: 
        request.Taker,
        request.Skip
        request.Sort, 
        request.Filter*/
}

PS I didn’t work with telerik, therefore, perhaps, I didn’t say something exactly.

Scroll to Top