A slice specifies which subset of data from your data source should be shown in the pivot table and charts. To see different examples of slice configuration, visit our Examples page.
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.
Note You can get the current slice configuration in the saved report.
If a slice is 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 only for JSON and CSV data sources. 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:
slice: {
rows: [
{
uniqueName: "Category"
}
],
columns: [
{
uniqueName: "[Measures]"
}
],
measures: [
{
uniqueName: "Price"
}
]
}
Any field can be selected for rows
, columns
, or measures
:
report: {
dataSource: {
filename: "https://cdn.flexmonster.com/data/data.csv"
},
slice: {
rows: [
{
uniqueName: "Category"
}
],
columns: [
{
uniqueName: "[Measures]"
},
{
uniqueName: "Color"
}
],
measures: [
{
uniqueName: "Price",
aggregation: "sum"
},
{
uniqueName: "Discount",
aggregation: "min"
}
]
}
}
"uniqueName": "[Measures]"
allows you to define where the measures will be displayed (in rows
or in columns
). By default, they go to columns
.
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"
}
]
}
}
The sorting
object defines the sorting for values in a specific row or column. Sorting is usually configured via UI and then saved within the report. It looks like this:
sorting: {
column: {
type: "asc",
tuple: [
"category.[bikes]",
"color.[red]"
],
measure: {
"uniqueName": "Price",
"aggregation": "sum"
}
}
}
To clear the sorting in rows or columns at runtime, use the UI controls or the sortValues API call:
pivot.sortValues(
"columns",
"unsorted",
["category.[bikes]", "color.[red]"],
{"uniqueName": "Price"}
);
Sorting for field members should be specified in the sort
property in rows or columns:
rows: [
{
uniqueName: "Category",
filter: {
members: [
"category.[cars]",
"category.[bikes]"
]
},
sort: "desc"
}
]
Learn more about sorting members.
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. This is how an expands
object looks:
expands: {
expandAll: false,
rows: [
{
tuple: [
"category.[accessories]"
]
},
{
tuple: [
"category.[cars]"
]
}
]
}
Use the expands.expandAll property to apply the operation to all levels of data detail at once.
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]"
]
}
]
}
Using calculated values, you can create a measure that is calculated based on a custom formula. The formula can contain other measures and supported operators and functions. You can create as many calculated values for your report as you need. When you save the report, all the calculated values will be saved as well and loaded when the report is retrieved. Note that you can add calculated values only for reports that are based on "json"
, "csv"
, or "api"
data source type. Below is an example of a calculated value:
measures: [
{
uniqueName: "Avg",
formula: "sum('Price') / count('Category')",
caption: "Avg",
active: true
}
]
You can predefine a slice for the drill-through view. This feature is supported for JSON, CSV, Elasticsearch, and custom data source API.
To configure which fields will be present in the drill-through view, specify the fields in the slice.drillThrough array:
report: {
dataSource: {
"filename": "https://cdn.flexmonster.com/data/data.csv"
},
slice: {
drillThrough: [
"Country",
"Category",
"Color",
"Price"
]
}
}
Use the Field List to define report filters, rows, columns, and values at runtime:
Note that you can resize the Field List using its window borders.
Sorting, filtering, drill-ups, drill-downs, and expand/collapse operations are available directly on the grid and on built-in pivot charts.
You can change the slice along with other report parts using the API call setReport(). To change only the slice use the runQuery() call.