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

Sort On Child Node

5 Answers 61 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ashleigh L
Top achievements
Rank 1
Ashleigh L asked on 22 Oct 2015, 08:28 PM

I've got data being passed to a datasource in the following format:

{"Data":{"Met":0,"Warning":0,"Total":3,"Chapters":[{"Name":"Chapter 1","SortOrder":3,"ID":7855,"Tasks":[{"Name":"Task 1","SortOrder":1,"ID":8334}]},{"Name":"Chapter 2","SortOrder":2,"ID":7856,"Tasks":[{"Name":"Task 2","SortOrder":1,"ID":8334}]},{"Name":"Chapter 3","SortOrder":1,"ID":7857,"Tasks":[{"Name":"Task 3","SortOrder":1,"ID":8334}, {"Name":"Task 4","SortOrder":2,"ID":8334}]}],"NotMet":3}}

And I was hoping to use the datasource to sort it, based on the returned sort order, but it's not working. I'm assuming it's because of the nested nodes, is there any way to accomplish this from inside the datasource?

var datasource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "/Controllers/Controller.cfc?method=getData",
                type: "get",
                dataType: "json",
                data: {
                    ID: id
                }
            }          
        },
        schema : {
            type: "json",
            data: "Data",
            model: {
                fields: {
                    Total: { field: "Total", type: "number" },
                    Met: { field: "Met", type: "number" },
                    Warning: { field: "Warning", type: "number" },
                    NotMet: { field: "NotMet", type: "number" }
                }  
            }
        },
        sort: {
            field: "SortOrder",
            dir: "desc"
        }
    });

5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 26 Oct 2015, 03:38 PM

Hello,

 

I noticed that you have defined the schema.data to "Data". Please note that schema.data is the field from the server response which contains the data items. It expects an array of objects and not a single object. Based on the provided response the "Data" field is a single object. In order the current configuration of the DataSource to work properly the response should look like: 

{
    "Data": [{
        "ProductID": 1,
        "ProductName": "aaa",
        "SupplierID": null,
        "CategoryID": null,
        "QuantityPerUnit": null,
        "UnitPrice": null,
        "UnitsInStock": 32,
        "UnitsOnOrder": null,
        "ReorderLevel": null,
        "Discontinued": false
    }, {
        "ProductID": 2,
        "ProductName": "Chang",
        "SupplierID": null,
        "CategoryID": null,
        "QuantityPerUnit": null,
        "UnitPrice": null,
        "UnitsInStock": 16,
        "UnitsOnOrder": null,
        "ReorderLevel": null,
        "Discontinued": false
    }]
....

 

 

 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ashleigh L
Top achievements
Rank 1
answered on 26 Oct 2015, 03:47 PM
I'm not sure what you're saying. "Data" isn't the root node in my actual data, it's a substitution for this example. I've also worked w/ nested return data in a datasource before, it's only the sorting that's a problem in this instance.
0
Ashleigh L
Top achievements
Rank 1
answered on 26 Oct 2015, 03:50 PM
To be clear, everything about my datasource works correctly w/ the provided data, except the sorting on the nested nodes.
0
Boyan Dimitrov
Telerik team
answered on 28 Oct 2015, 01:38 PM

Hello shimmoril,

 

By design the DataSource does not support nested data structures. 

It is possible to display the nested fields through templates like in the provided example, but the other functionality such as grouping, filtering and sorting will not work.

 

Please accept my apology for the inconvenience.

 

 

Regards,

Boyan Dimitrov

Telerik

 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ashleigh L
Top achievements
Rank 1
answered on 28 Oct 2015, 03:04 PM
That's what I assumed, thanks for the confirmation.
Tags
Data Source
Asked by
Ashleigh L
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Ashleigh L
Top achievements
Rank 1
Share this question
or