Need a special offer?Find out if your project fits.
+
All documentation
  • Introduction
  • Connecting to Data Source
  • Browser compatibility
  • Documentation for older versions
  • 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.

    Slice properties

    You can define fields that go to rows, go to columns, go to measures, add filtering, sorting, report filtering, expands, and drills. See the full list of available SliceObject properties.

    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", 
      ["category.[bikes]", "color.[red]"], 
      {"uniqueName": "Price"}
    );

    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"
        }
    ] 

    Learn more about sorting members.

    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.