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

Examples on how to format json for Grid

6 Answers 1062 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jolle
Top achievements
Rank 1
Jolle asked on 27 Sep 2011, 02:50 AM
Started experimenting with Kendo to see how it could fit into our present work flow. Lot of stuff looks really promising. And the efforts put into documentation is also very commendable.
One thing I can't find is how to format json objects when using remote datasource in grid.
I have successfully managed to get a grid displaying the first set of records. But I can't get it to honor the fact that there are 491 records in total. Somehow the grid seems satisfied with displaying the first 20 records and stops there. The online demos I've found does not provide json examples, only odata, and in fact I can't get any of them to display what's returned from server using firebug. I have tried using labels like total, totalItems, totalFound etc to no avail.
Here's how the configuration is setup:
    $("#grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    // the remote service url
                    url: "ajax.lasso",
                    dataType: "json",
                    // additional parameters sent to the remote service
                    data: {
                        ajax_action: "getaccessreqlist"
                    }
                }
            },
            // describe the result format
            schema: {
                // the data which the data source will be bound to is in the "results" field
                data: "results"
            },
            pageSize: 20,
            serverPaging: true,
            serverSorting: true
        },
        height: 450,
        scrollable: true,
        sortable: true,
        pageable: true,
        columns: [
            {
                field: "name",
                title: "Requirement Name",
                template: ' + `'<a href="./?edit/<#= recid #>/"><#= name #></a>'` + '
            },
            {
                field: "descr",
                title: "Description"
            },
            {
                field: "location_name",
                title: "Location / Site"
            },
            {
                field: "restriction",
                title: "Restriction"
            }
        ]
    });

/Jolle

6 Answers, 1 is accepted

Sort by
0
Jolle
Top achievements
Rank 1
answered on 27 Sep 2011, 03:05 AM
Never mind!
Found it.
Needed a setting in the schema section:
schema: {
    data: "results",
    total: "total"
},
Now I also have virtualization running. Nice indeed!!

/Jolle
0
Brad
Top achievements
Rank 1
answered on 09 Nov 2011, 02:50 AM
I'm still having a tough time getting this working. I added:

schema: {
    data: "results",
    total: "total"
},

As suggested and my results are working fine. But, the control doesn't register the total records. This is how I have the JSON formatted right now:

{"total": "91","results":[{"ContactId"....

I've tried various other ways, but am only getting one page and one pager link. Right now the server is returning 10 per request.

0
Rosen
Telerik team
answered on 09 Nov 2011, 08:48 AM
Hello Brad,

Could you verify that you have set serverPaging to true as it seems that you are using server paging? If this does not help, please provide both grid and dataSource declarations.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brad
Top achievements
Rank 1
answered on 09 Nov 2011, 06:07 PM
Thanks for the reply Rosen. I do have server paging set to true. But, maybe the configuration is wrong.

Here's my code:

$("#newstudentsgrid").kendoGrid({
     columns:[
         {
             field: "thing1",
             title: "thing1"
         },
         {
             field: "thing2",
             title: "thing2"
         },
         {
             field: "thing3",
             title: "thing3"
         },                   
         {
             field: "thing4",
             title: "thing4"
         }],
     dataSource: {
         transport: {
             read: {
                 url: "http://localhost/getPages",                       
                 pageSize: 10,
                 dataType: "json",
                 serverPaging: true
             }
         },
         schema: {
             data: "results",
             total: "total"
         }
     },
      scrollable: {
          virtual: true
      },
     selectable: true,
     pageable: true
 });
0
Rosen
Telerik team
answered on 10 Nov 2011, 05:45 PM
Hello Brad,

Looking at the code you have pasted, it seems that the pageSize is set to the transport instead to the DataSource. Correcting this should fix the problem you have described.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brad
Top achievements
Rank 1
answered on 10 Nov 2011, 06:14 PM
Thanks Rosen! Woks perfectly now!

BTW, Kendo is awesome!
Tags
Grid
Asked by
Jolle
Top achievements
Rank 1
Answers by
Jolle
Top achievements
Rank 1
Brad
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or