We have changed our pricing. Flexmonster Software License Agreement was also updated (list of changes)
All documentation
  • Introduction
  • Connecting to data source
    1. Supported data sources
    2. Connecting to other data sources
  • Browser compatibility
  • Documentation for older versions
  • Configuring aggregation functions

    To use aggregations in the custom data source API, you need to do the following:

    1. Define which aggregations you want to support on the server.
    2. Handle the aggregations on the server.

    This guide covers both steps and provides additional information about aggregations in the custom data source API.

    Supported aggregations

    The aggregations supported by Flexmonster for the custom data source API are the following:

    You must implement all necessary aggregations manually.

    Note For the fields of the "number" type, built-in front-end aggregations are available. You do not need to implement them on the server.

    Defining available aggregations

    Available aggregations are defined in the response to the /fields request. You can define aggregations for all fields, for fields of a certain type, or for a specific field.

    Aggregations for all fields

    Specify an array of the necessary aggregations in the aggregations property:

    {
    "aggregations": ["count", "distinctcount"],
    }

    Aggregations for fields of a certain type

    Aggregations for the "string", "number", and "date" field types can be configured using the aggregations.string, aggregations.number, and aggregations.date properties respectively. These configurations override the ones set for all fields in aggregations.

    We will showcase the configuration on an example of the "number" field type:

    "aggregations": {
    "number": ["count", "distinctcount", "min", "max"],
    }

    Aggregations for the "string" and "date" field types can be defined in the same way.

    Note You can use aggregations.any to configure available aggregations for multiple field types:

    "aggregations": {
    "any": ["count", "distinctcount"],
    "date": ["min", "max"],
    }

    As a result, the aggregations specified in aggregations.any can be applied to both "number" and "string" field types, while fields of the "date" type will have "min" and "max" aggregations available.

    Aggregations for a specific field

    To configure aggregations for a specific field, specify the aggregations property for the necessary field in the response to the /fields request. Aggregation configurations for a specific field override configurations set for all fields and for fields of a certain type.

    Here is an example of how to configure aggregations for the "Price" field:

    {
    "fields": [
    {
    "uniqueName": "Price",
    "aggregations": ["min", "max"],
    // Other properties
    },
    // Other fields
    ],
    "aggregations": ["sum", "average"],
    // Other properties
    }

    As a result, the "Price" field can be aggregated only with "min", "max", and built-in front-end aggregations.

    Handling aggregations

    After you configure the aggregations on your server, they can be applied to fields in Flexmonster Pivot.

    When an aggregation is applied to a specific field, the aggregation is sent in the func property of the query.aggs.values array in the /select requests for the pivot table and the flat table. Ensure that the server aggregates the data according to the given function.

    Implementing a custom aggregation

    Besides aggregations supported by Flexmonster, you can implement a custom aggregation on your server:

    Step 1. Define the custom aggregation (e.g., "squareroot") in the response to the /fields request. The custom aggregation can be defined for all fields, for fields of a certain type, or for a specific field.

    See an example:

    {
    "aggregations": {
    "number": ["sum", "average", "squareroot"],
    // ...
    }
    }

    Step 2. Implement a function that aggregates data according to your aggregation.

    Now the custom aggregation can be used on the client side. In the component, a measure with the custom aggregation will look similar to the following: Price (squareroot).

    Built-in front-end aggregations

    For the custom data source API, Flexmonster supports the following built-in front-end aggregations for the fields of the "number" type:

    Built-in front-end aggregations will appear in Flexmonster Pivot automatically if the "sum" aggregation is implemented on the back end.

    Limiting the list of available aggregations in Flexmonster

    On the client side, you can configure aggregations available for a specific field using the mapping. The list of aggregations can contain both the aggregations supported on the back end (including custom ones) and the built-in front-end aggregations.

    See also