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

How to use as the datasource a property (field) of the result (Kendo Grid)

3 Answers 443 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ALEXIS
Top achievements
Rank 1
ALEXIS asked on 15 May 2014, 12:54 PM
Hi All,

I am creating the grid via javascript. The datasource is connected directly to the webservice. An example of the webservice result is the following:
[ { col1: "",
col2: "",
Items: [ { ....} }
}]

Instead of using the main result like col1 and col2 I need to use the Items. How can I specify that using the example below?

var locationItems = $("#grid").kendoGrid({
    columns: lockedGridColumns(),
    height: 500,
    scrollable: true,
    sortable: true,
    filterable: true,
    pageable: true,
    //reorderable: true,
    //resizable: true,
    autoBind: false
}).data("kendoGrid");

function getItems(locationId) {
    if (locationId == null) {
        locationId = 0;
    }   

var dataSource = new kendo.data.DataSource(locationId != 0 ?
            {
                transport: {
                    read: {
                        dataType: "json",
                        url: "api/items/getlocationitems?locationID=" + locationId
                    }
                },
                pageSize: 25
            } :
            {
                data: [],
                pageSize: 25
            });   

locationItems.setDataSource(dataSource);
    locationItems.dataSource.read();
}

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 19 May 2014, 08:40 AM
Hello Alexis,

schema.data in DataSource configuration defines where the actual data is in the response.

Regards,
Nikolay Rusev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ALEXIS
Top achievements
Rank 1
answered on 22 May 2014, 03:18 PM
Hi,

If I use the transport to setup the datasource the properties total() or view doesnt work. How can I identify if the datasource returned something using transport. If I get the data outside and asign it to the datasource the previously mentioned properties work. I would like to use the transport because the progress of the grid shows automatically.
0
Nikolay Rusev
Telerik team
answered on 23 May 2014, 11:40 AM
Hello Alexis,

I'm not sure whether I understand your question correctly. Usually when DataSource is configured for remote operation it must know from which field of the response to read the actual data and total information. All this settings can be defined in the schema configuration section.

schema.data for the actual data
schema.total for the total count of all items 

` If I get the data outside and asign it to the datasource the previously mentioned properties work.` - I assume that you are setting data of the DataSource via data field in the configuration or via data method. In this case DataSource will assume that this is all the data it have and use it to calculate the total etc.

Regards,
Nikolay Rusev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
ALEXIS
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
ALEXIS
Top achievements
Rank 1
Share this question
or