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

Grid Paging intializing problem with json datasource

3 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syl'
Top achievements
Rank 1
Syl' asked on 13 Jun 2014, 03:57 PM
Hi

I have an issue with the paging block at the bottom of the grid (where pages numbers buttons and items number are located). At the first rendering of the page, this paging block is not initialized. My grid contains 2 pages of 5 items each but the paging block only displays 1 page button, with the number "0" and the text "No items to display".

If I sort the data (by clicking on a column header), the paging block is properly initialized.

I have no clue of what I'm doing wrong.

Here is my cshtml code :

$("#grid").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: "/Countries/AllCountries",
        },
        schema: {
            data: "data"
        },
        pageSize: 5
    },
    groupable: false,
    sortable: true,
    pageable: true,
    filterable: true,
});

Here is the result of my json request /Countries/AllCountries :

 
{"data":[
   {"Id":1,"Name":"Japan"},
   {"Id":2,"Name":"South Africa"},
   {"Id":3,"Name":"United States"},
   {"Id":4,"Name":"Albania"},
   {"Id":5,"Name":"Germany"},
   {"Id":6,"Name":"France"},
   {"Id":7,"Name":"Sweden"},
   {"Id":8,"Name":"UK"},
   {"Id":9,"Name":"Marocco"},
   {"Id":10,"Name":"Argentina"}]}


Thanks for helping

3 Answers, 1 is accepted

Sort by
0
Accepted
CS
Top achievements
Rank 2
answered on 16 Jun 2014, 05:31 AM
I think you have to use the "schema.parse" because an array is expected and not an object that contains an array.

Working Example
0
CS
Top achievements
Rank 2
answered on 16 Jun 2014, 05:32 AM
0
Syl'
Top achievements
Rank 1
answered on 16 Jun 2014, 08:40 AM
Actually I started with a standard json format :

[{"Id":1,"Name":"Japan"},
  {"Id":2,"Name":"South Africa"}]

...and wasn't able to populate my grid. I saw everywhere on the web that the format required by the grid for remote json source was this format :

{"d": [{"Id":1,"Name":"Japan"},
         {"Id":2,"Name":"South Africa"}]}

And I had to use the object "d" in the schema data property. So I changed it and was able to fill my grid... with the paging problem.

Since your post I changed it again to the standard json format. And now it works! And I don't even need the schema property anymore.
I don't know what I missed at my very first try. I would have preferred to really understand but at least, my problem seems to be solved.

Thanks.

Here is my final code:
$("#grid").kendoGrid({
    dataSource: {
        transport: {
            read: "/Countries/AllCountries",
            dataType: 'json'
        },
        pageSize: 5
    },
    groupable: false,
    pageable: true,
    filterable: true,
    sortable: true
});








Tags
Grid
Asked by
Syl'
Top achievements
Rank 1
Answers by
CS
Top achievements
Rank 2
Syl'
Top achievements
Rank 1
Share this question
or