Get Free Trial
  1. API reference
Connecting to Data Source
Configuring the component
  • Documentation for older versions
  • Table of contents

    Slice

    A slice is a definition of the subset of data from your data source that will be shown in your report when you open it. By using slices in a report you can easily switch between different sets of values. To see different examples of slice configuration, visit our Examples page.

    Read more in the following sections:

    Slice properties

    You can define fields that go to rows, go to columns, go to measures, add filtering, sorting, report filtering, expands, and drills. Here is a list of all available properties for a slice:

    • columns – Array of objects. A list of fields selected in the report slice for columns. Each object can have the following properties:
      • uniqueName – String. The field’s unique name.
      • caption optional – String. The field’s caption.
      • dimensionName optional – String. The dimension name.
      • filter optionalFilterObject. Contains filtering information.
      • levelName optional – String. If the field is a multilevel hierarchy, the levelName allows setting a specific hierarchy level to be shown on the grid or chart (see live demo).
      • showTotals optional — Boolean. Defines whether totals are shown or hidden for the field. When set to true, totals are shown. Only for the classic view.
        If showTotals is not specified, totals’ visibility is defined by the options.showTotals property. Learn more about options.showTotals.
        To show and hide totals via UI, use a context menu. Open it by right-clicking the field header.
      • sort optional – String. The sorting type for members ("asc", "desc" or "unsorted").
      • sortOrder optional – Array of strings. Set custom ordering for field members. Only for "csv" and "json" data source types. sortOrder can be specified like this: ["member_1", "member_2", etc.].
    • drills optional – Object. Stores information about drilled down multilevel hierarchies:
      • drillAll optional – Boolean. Set this property to true to drill down all multilevel hierarchies. Works for the grid and the charts.
      • drillAllColumns optional – Boolean. Set this property to true to drill down all multilevel hierarchies in columns. Works for the grid and the charts.
      • drillAllRows optional – Boolean. Set this property to true to drill down all multilevel hierarchies in rows. Works for the grid and the charts.
      • columns optional – Array of objects. Used to save and restore drilled down columns.
      • rows optional – Array of objects. Used to save and restore drilled down rows.
    • drillThrough optional – Array of strings. Allows pre-defining the slice for the drill-through view. Only for "csv", "json", and "api" data source types. drillThrough can be specified like this: ["Field name 1", "Field name 2", etc.] (see live demo).
    • expands optional – Object. Stores information about expanded fields:
      • expandAll optional – Boolean. Set this property to true to expand all fields. Works for the grid and the charts.
      • expandAllColumns optional – Boolean. Set this property to true to expand all fields in columns. Works for the grid and the charts.
      • expandAllRows optional – Boolean. Set this property to true to expand all fields in rows. Works for the grid and the charts.
      • columns optional – Array of objects. Used to save and restore expanded columns.
      • rows optional – Array of objects. Used to save and restore expanded rows.
    • flatSort – Array of objects. Defines sorting for columns in the flat view. Only for "json", "csv", and "api" data source types.
      Each object in the array has the following properties:
      • uniqueName – String. The unique name of the column being sorted.
      • sort – String. The sorting type ("asc", "desc", or "undefined").
      Note: columns are sorted in the order they were specified (i.e., the first column is sorted first, and so on). Therefore, take the columns’ order into account when sorting multiple columns. See an example on JSFiddle.
      To sort multiple columns via UI, press Ctrl and click a sorting arrow on each column to be sorted.
    • measures – Array of objects. A list of the selected measures and those which have non-default properties. Each object has these properties:
      • uniqueName – String. The measure’s unique name.
      • active optional – Boolean. Indicates whether the measure will be selected for the report (true) or not (false). active: false can be useful if the measure has non-default properties, but should not be selected for the grid or the chart.
      • aggregation optional — String. The name of the aggregation that will be applied to the measure. To see the list of supported aggregation functions for each data source type, refer to Flexmonster’s technical specifications. If the measure is calculated, skip the aggregation property.
      • availableAggregations optional — Array of strings. Note that starting from version 2.8, the availableAggregations property is considered deprecated. Use the Mapping’s aggregations property instead.
        availableAggregations represents the list of aggregation functions that can be applied to the current measure. If the measure is calculated, availableAggregations will be set to [].
      • caption optional – String. The measure’s caption.
      • formula optional – String. Represents the formula. Refers to the calculated measure. It can contain:
        • Operators and functions. Check out the full list.
        • Numbers. Negative numbers can be used as well (see an example).
        • Measures. A measure can be addressed using its unique name and an aggregation function. For example, sum("Price") or max("Order"). See a list of supported aggregations in Flexmonster’s technical specifications.
        • Calculated measures. To address another calculated measure, specify its unique name. For example, "Formula #1".
      • individual optional – Boolean. Refers to the calculated measure. Defines whether the formula is calculated using raw values (true) or using aggregated values (false). Only for "json" and "csv" data source types. Default value: false.
      • calculateNaN optional – Boolean. Refers to the calculated measure. Defines whether the formula is calculated using NaN values (true) or using null values (false). Default value: true.
      • format optional – String. The name of the number formatting that will be applied to the measure. Measure values can be formatted according to the number formatting defined in the report. All available number formattings are stored in the formats array in the report. More information about the number formatting part of the report can be found in the number formatting article.
      • grandTotalCaption optional – String. The measure’s grand total caption.
    • flatOrder – Array of strings. Defines the order of the fields for the "flat" grid type. flatOrder can be specified like this: ["Field name 1", "Field name 2", etc.] (see live demo). Only for "json", "csv", and "api" data source types.
    • memberProperties – Array of objects. Only for the "microsoft analysis services" data source type. Each object in the array has the following properties:
      • levelName – String. The hierarchy’s unique name.
      • properties – Array of strings. Represents the properties to be shown on the grid. Other available member properties can be accessed through the context menu.
    • reportFilters – Array of objects. A list of fields selected in the report slice for report filters. Each object has the following properties:
      • uniqueName – String. The field’s unique name.
      • caption optional – String. The field’s caption.
      • dimensionName optional – String. The dimension name.
      • filter optionalFilterObject. Contains filtering information.
      • sort optional – String. The sorting type for members ("asc", "desc" or "unsorted").
      • sortOrder optional – Array of strings. Set custom ordering for field members. Only for "csv" and "json" data source types. sortOrder can be specified like this: ["member_1", "member_2", etc.].
    • rows – Array of objects. A list of fields selected in the report slice for rows. Each object can have the following properties:
      • uniqueName – String. The field’s unique name.
      • caption optional – String. The field’s caption.
      • dimensionName optional – String. The dimension name.
      • filter optionalFilterObject. Contains filtering information.
      • levelName optional – String. If the field is a multilevel hierarchy, the levelName allows setting a specific hierarchy level to be shown on the grid or chart (see live demo).
      • showTotals optional — Boolean. Defines whether totals are shown or hidden for the field. When set to true, totals are shown. Only for the classic view.
        If showTotals is not specified, totals’ visibility is defined by the options.showTotals property. Learn more about options.showTotals.
        To show and hide totals via UI, use a context menu. Open it by right-clicking the field header.
      • sort optional – String. The sorting type for members ("asc", "desc" or "unsorted").
      • sortOrder optional – Array of strings. Set custom ordering for field members. Only for "csv" and "json" data source types. sortOrder can be specified like this: ["member_1", "member_2", etc.].
    • sorting optional – Object. Defines the sorting for numbers in a specific row and/or column in the pivot table. To clear the sorting, use the sortValues API call.
      The sorting object has the following properties:
      • column – Object. Defines the sorting for numbers in a specific column. The object has the following properties:
        • tuple – Array of strings. Consists of unique names that identify the column in the table based on the column’s data.
        • measure – Object. Identifies the measure on which sorting will be applied. Has the following properties:
          • uniqueName – String. The measure’s unique name.
          • aggregation optional – String. The measure’s aggregation type.
            If the measure is calculated, skip the aggregation or set it to "none".
        • type – String. The sorting type ("asc" or "desc").
      • row – Object. Defines the sorting for numbers in a specific row. The object has the following properties:
        • tuple – Array of strings. Consists of unique names that identify the row in the table based on the row’s data.
        • measure – Object. Identifies the measure on which sorting will be applied. Has the following properties:
          • uniqueName – String. The measure’s unique name.
          • aggregation optional – String. The measure’s aggregation type.
            If the measure is calculated, skip the aggregation or set it to "none".
        • type – String. The sorting type ("asc" or "desc").

    Default slice

    If a slice was not defined, Flexmonster will select a default slice for the report, where the first field from the data goes to rows and the first measure goes to columns. The automatic default slice selection is available for JSON and CSV data sources (it is not available for OLAP). You can turn off the default slice by setting showDefaultSlice in options to false. For example, take a look at the JSON data below:

    let jsonData =  [
        {
            "Category": "Accessories",
            "Price": 125,
            "Quantity": 100
        },
        {
            "Category": "Accessories",
            "Price": 74,
            "Quantity": 235
        },
        {
            "Category": "Bikes",
            "Price": 233,
            "Quantity": 184
        }
    ] 

    "Category" is the first field, so it goes to rows. "Price" is the first measure, so it goes to columns. For this dataset, the default slice will look like this:

    report: {
        dataSource: {
            data: jsonData
        },
        slice: {
            rows: [
                {
                    uniqueName: "Category"
                }
            ],
            columns: [
                {
                    uniqueName: "[Measures]"
                }
            ],
            measures: [
                {
                    uniqueName: "Price"
                }
            ]
        }
    } 

    See the same example with a default slice on JSFiddle.

    Rows, columns, and measures

    A slice can be defined with only measures:

    report: {
        dataSource: {
            filename: "https://cdn.flexmonster.com/data/data.csv" 
        },
        slice: {
            measures: [
                {
                    uniqueName: "Price",
                    aggregation: "sum",
                    active: true
                }
            ]
        }
    } 

    Open on JSFiddle.

    "uniqueName": "[Measures]" allows you to define where the measures will be displayed (in rows or in columns). By default they go to columns. Here is an example of a slice with rows, columns, and measures:

    report: {
        dataSource: {
            filename: "https://cdn.flexmonster.com/data/data.csv"
        },
        slice: {
            rows: [
                {
                    uniqueName: "Category",
                    filter: {
                        members: [
                            "category.[cars]",
                            "category.[bikes]"
                        ]
                    },
                    sort: "desc"
                }
            ],
            columns: [
                {
                    uniqueName: "[Measures]"
                },
                {
                    uniqueName: "Color",
                    filter: {
                        members: [ "color.[blue]" ]
                    }
                 }
            ],
            measures: [
                {
                    uniqueName: "Price",
                    aggregation: "sum",
                    active: true
                },
                {
                    uniqueName: "Discount",
                    aggregation: "min",
                    active: true
                }
            ]
        }
    } 

    See the same example on JSFiddle.

    Report filter

    A report filter allows you to display different data subsets in the report. In Flexmonster Pivot the reportFilters property is used for defining the report filters as follows:

    report: {
        dataSource: {
            filename: "https://cdn.flexmonster.com/data/data.csv"
        },
        slice: {
            reportFilters: [
                {
                    uniqueName: "Color",
                    filter: {
                        members: [
                            "color.[yellow]",
                            "color.[white]"
                        ]
                    }
                }
            ],
            rows: [
                {
                    uniqueName: "Category"
                }
            ],
            columns: [
                {
                    uniqueName: "[Measures]"
                }
            ],
            measures: [
                {
                    uniqueName: "Price"
                }
            ]
        }
    } 

    See an example with a report filter on JSFiddle.

    Sorting

    The sorting object defines the sorting for numbers in a specific row and/or column in the pivot table. Sorting is usually configured on the grid and then saved within the report. It looks like this:

    sorting: {
        column: {
            type: "desc",
            tuple: [],
            measure: "Price"
        }
    } 

    To clear the sorting in rows or columns, use the sortValues API call:

    flexmonster.sortValues("columns", "unsorted");

    See an example on JSFiddle.

    Sorting for members of columns and rows should be defined in the rows.sort or columns.sort property:

    rows: [
        {
            uniqueName: "Category",
            filter: {
                members: [
                    "category.[cars]",
                    "category.[bikes]"
                ]
            },
            sort: "desc"
        }
    ] 

    Expands

    Information about expands and collapses is stored within the slice. When a user performs one of these operations, all the changes can be saved within the report. Use the expandAll property to apply the operation to all levels of data detail at once. This is how an expands object looks:

    expands: {
        expandAll: false,
        rows: [
            {
                tuple: [
                    "category.[accessories]"
                ]
            },
            { 
                tuple: [
                    "category.[cars]"
                ]
            }
        ]
    } 

    Drills

    The drills object is used to store information about drill-downs in multilevel hierarchies. Here is an example of a drills object:

    drills: {
        drillAll: false,
        rows: [
            {
                tuple: [
                    "category.[accessories]"
                ]
            },
            {
                tuple: [
                    "category.[accessories].[bike racks]"
                ]
            },
            { 
                tuple: [
                    "category.[accessories].[bottles and cages]"
                ]
            }
        ]
    } 

    Calculated values

    You can create as many calculated measures for one report as you need. When you save the report all the calculated measures will be saved as well and loaded when the report is retrieved. Note that you can add calculated measures only for reports that are based on a "csv", "json", or "api" data source type. Below is an example of a calculated measure:

    measures: [
        {
            uniqueName: "Avg",
            formula: "sum('Price') / count('Category') ",
            caption: "Avg",
            active: true
        }
    ] 

    Change a slice using the Field List and controls on the grid

    Use the Field List to define report filters, rows, columns, and values at run time.

    fieldslist

    Sorting, filtering, drill-ups, drill-downs, and expand/collapse operations are available directly on the grid and on built-in pivot charts.

    Slice via API

    You can change the slice along with other report parts using the API call setReport(). To change only the slice use the runQuery() call.