Aggregate function returns empty object after query

5 posts, 0 answers
  1. Sam
    Sam avatar
    34 posts
    Member since:
    Dec 2016

    Posted 24 Apr Link to this post

    Aggregate function returns empty object after query

    http://jsbin.com/lahaficupu/1/edit?html,output

  2. Sam
    Sam avatar
    34 posts
    Member since:
    Dec 2016

    Posted 24 Apr in reply to Sam Link to this post

    Please see the browser console output.
  3. Sam
    Sam avatar
    34 posts
    Member since:
    Dec 2016

    Posted 24 Apr in reply to Sam Link to this post

    Please see the browser console output.
  4. Sam
    Sam avatar
    34 posts
    Member since:
    Dec 2016

    Posted 24 Apr Link to this post

    var ds = new kendo.data.DataSource({
        data: [
          {"foo": {"bar": 10}},
          {"foo": {"bar": 10}},
          {"foo": {"bar": 10}},
          {"foo": {"bar": 20}}
        ],
         
        aggregate: [
          {field: "foo.bar", aggregate: "sum"}
        ]
    })
    ds.read();
    console.log('results', ds.view().length);
    console.log('aggregates', ds.aggregates());
    console.log('run filter')
    ds.query({filter:{field: "foo.bar", operator: "eq", value: 20}})
    console.log('results', ds.view().length);
    console.log('aggregates', ds.aggregates());
  5. Dimitar
    Admin
    Dimitar avatar
    459 posts

    Posted 26 Apr Link to this post

    Hello Sam,

    The dataSource's query() method resets the aggregate configuration by default. Therefore, to maintain it in the query result you can pass it as follows:
    <script>
      ds.query({filter:{field: "foo", operator: "eq", value: 20}, aggregate: ds.aggregate()}).then(function() {   
        console.log('results', ds.view().length);
        console.log('aggregates', ds.aggregates());
      })
    </script>

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top