Sort On Child Node

6 posts, 0 answers
  1. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 22 Oct 2015 Link to this post

    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"
            }
        });

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 26 Oct 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 26 Oct 2015 in reply to Boyan Dimitrov Link to this post

    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.
  5. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 26 Oct 2015 in reply to Ashleigh L Link to this post

    To be clear, everything about my datasource works correctly w/ the provided data, except the sorting on the nested nodes.
  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 28 Oct 2015 Link to this post

    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!
     
  7. Ashleigh L
    Ashleigh L avatar
    113 posts
    Member since:
    Jun 2012

    Posted 28 Oct 2015 in reply to Boyan Dimitrov Link to this post

    That's what I assumed, thanks for the confirmation.
Back to Top
Kendo UI is VS 2017 Ready