aggregate

An array of dictionaries, describing the aggregate functions to perform on the resulting data set.
Each dictionary must contain the following properties:
- field - the path to the property of each item, which to include in the calculation
- aggregate - the type of aggregate function to apply. Possible string values are: count, min, max, average, sum. A custom function(data, aggregate) can also be specified, which will be executed to perform custom processing - it will receive the following two params: a list containing the resulting data and a dictionary describing the aggregate
- type - an optional type of the property being aggregated.

After the DataSource is read, the aggregation results will be available in its aggregates property. It will contain a list of dictionaries, having the same format as the aggregate setting, with a value property added to each one, which will hold the result of the specific aggregation.

Aggregation is applied after filering and grouping.
If grouping is enabled, the aggregate functions are applied on all of the items in all of the bottom-level groups.

var dataSource = new shield.DataSource({
    data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    aggregate: [
        { field: "", aggregate: "count" },
        { field: "", aggregate: "min" },
        { field: "", aggregate: "max" },
        { field: "", aggregate: "average" },
        { field: "", aggregate: "sum" },
        { field: "", aggregate: function(data, aggregate) { return 100; } }
    ]
});

dataSource.read().then(function() {
    console.log(dataSource.aggregates[0].value);
    // prints 10

    console.log(dataSource.aggregates[1].value);
    // prints 1

    console.log(dataSource.aggregates[2].value);
    // prints 10

    console.log(dataSource.aggregates[3].value);
    // prints 5.5

    console.log(dataSource.aggregates[4].value);
    // prints 55

    console.log(dataSource.aggregates[5].value);
    // prints 100
});

Live example of DataSource aggregates you can find here: Aggregates