Search code examples
javascriptkendo-uidatasourcekendo-treelist

kendoTreeList - aggregate not working properly


Please help me, I am stuck with aggregates for kendoTreeList - I create kendoTreeList, but failed to calculate sum for groups.

$(document).ready(function () {
            var _jsondata = [
                      { ID: 1, Name: "Parent 1", Amount: "200", parentId: null },
                      { ID: 2, Name: "Parent 2", Amount: "500", parentId: null },
                      { ID: 11, Name: "Child 11", Amount: "50", parentId: 1 },
                      { ID: 12, Name: "Child 12", Amount: "150", parentId: 1 },
                      { ID: 21, Name: "Child 21", Amount: "100", parentId: 2 },
                      { ID: 22, Name: "Child 22", Amount: "200", parentId: 2 },
                      { ID: 23, Name: "Child 23", Amount: "200", parentId: 2 }                          
                    ];
            var dataSource = new kendo.data.TreeListDataSource({
                data    : _jsondata,
                schema  : { model: { id: "ID", expanded: true }},
                aggregate   : [
                    { field: "Amount", aggregate: "sum"}
                ]
            });
            $("#treelist").kendoTreeList({
                dataSource  : dataSource,                    
                columns     : [
                    { field: "Name" , nullable: false },
                    { field: "Amount",  footerTemplate: "#= sum #"}
                ]
            });
        });

this give result as -

enter image description here


Solution

  • Since Amount represented in _jsondata as string, you need to define it in schema.model as number

    schema: {
        model: { 
            id: "ID",
            expanded: true,
            fields: {
                Amount: { type: 'number' }
            }
        }
    },