4

Fairly new to it and trying to use paging with kendo datagrid (2.2015) Had it working without paging but paging requires the total record count be returned in the data so I changed the json result from the web service to look like this:

{
  "total":98,
  "data":[
    {"ID":164,"Name":"ABRAHAM, ALBERTA","Phone":"(111) 222-7240","Row":1},
    {"ID":173,"Name":"ABRAHAM, SERENA","Phone":"(111) 222-4067","Row":2},
    {"ID":213,"Name":"ADAMS, RONNIE","Phone":"(111) 222-0273","Row":3},
    {"ID":151,"Name":"ADDISON, RAYMOND \u0026 SUE","Phone":"111-222-6252","Row":4},
    {"ID":175,"Name":"ALEXANDER, FRANKLIN","Phone":"(111) 222-6839","Row":5}
  ]
}

page size is 5 and defined in the datasource which is here:

Search.clientDataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: myUrl,
            dataType: "json",
            type: "get"
        }
    },
    pageSize: 5,
    serverPaging: "true",
    schema: {
        total: "total",
        data: "data"
    }
});

The above as far as I can tell is 'by the book' and matches all I've read on the subject.

(The comments below may be red herring) When I had it working without paging the data was returned in an unnamed array and in the schema I used this:

schema: {
        data: function (response) {
            var obj = JSON.parse(response);
            return obj;
        }
    }

which worked but I have never seen any examples of it being done this way, I assumed it was because the array returned was unnamed, all examples showed the schema using the data: "data" where data is the name of the array. If I used this on my unnamed array I got the slice error, again I assumed this was because there was no data array to slice up.

So now that I've cleaned up all that why is my paging supported data throwing this error?

kpg
  • 589
  • 6
  • 28
  • 1
    I got some success by changing the schema to schema: { total: function (response) { return (JSON.parse(response).total); }, data: function (response) { return (JSON.parse(response).data); } }. My theory is that my web service returns a string not a json object (am I correct in that?). Now however page 1 displays fine, page 2..n are blank even though valid data is being returned as confirmed by a console.log(response) in the schema function. Probably a totally different problem due to the grid not being refreshed – kpg Dec 17 '16 at 23:56
  • Blank page 2..n was due to the the quotes around serverPaging causing the datasource to think it should do client paging, so on page 2 it was trying to display records 6..10 of a record set with only 5 items...4 hours later it all makes sense! – kpg Dec 18 '16 at 06:01

0 Answers0