Telerik UI for Windows 8 HTML

You can perform grouping of dataset rows and get aggregates for these groups using a combination of the group(propertyName) and fields(fieldsObj) methods.

The group(propertyName) method accepts a single string argument that is the name of the field which will be used for group evaluation.

To be able to access the aggregates of the resulting groups, you should list the required fields and aggregate functions using the fields(fieldsObj) method.

The example below groups by salesQuota field and then counts the number of people having the same quota. Finally, the execute() method is called to trigger the actual grouping.

Define Single Group Field Copy imageCopy
db = Telerik.Data.Database.open("SalesDB");
db.get("Sales")
    .group("salesQuota")
    .fields({
        salesQuota: "salesQuota",
        name: "name",
        count: "count(name)"
    })
    .execute().then(querySuccess);

This snippet is equivalent to a query with the following syntax:

SQL Copy imageCopy
SELECT salesQuota, name, COUNT(name) AS count FROM Sales GROUP BY salesQuota

If you want to group by more than one field, use the group(propertyName) method multiple times. You can see this done in the following code snippet where the query defines two group-by fields - bonus and salesQuota.

Define Multiple Group Fields Copy imageCopy
db = Telerik.Data.Database.open("SalesDB");
db.get("Sales")
    .group("bonus")
    .group("salesQuota")
    .fields({
        name: "name",
        bonus: "bonus",
        salesQuota: "salesQuota",
        count: "count(name)"
    }).execute().then(querySuccess);

The corresponding SQL query would look like this:

SQL Copy imageCopy
SELECT name, bonus, salesQuota, COUNT(name) AS count FROM Sales GROUP BY bonus, salesQuota

See Also