update-config
Description
Fires when modifying rows, columns, or aggregation functions via the Pivot UI
The action is useful for saving a user's aggregation configuration so that it can be applied the next time the widget is used allowing a user to continue where they left off.
Usage
"update-config": ({
rows: string[],
columns: string[],
values: [],
filters: {}
}) => boolean | void;
Parameters
The callback of the action takes an object with the processed config
parameters:
rows
- rows of the Pivot table. An object with the field ID and a method for data extraction; the object parameters are the following:field
- the ID of a fieldmethod
- a method for data extraction (for time-based data fields)
columns
- defines columns for the Pivot table. It's an object with the field ID and a method for data extraction; the object parameters are the following:field
- the ID of a fieldmethod
- defines a method for data extraction (for time-based data fields). By default, methods are available for the time-based fields (the date type) with the next values: "year", "quarter", "month", "week", "day", "hour", "minute"
values
- defines the data aggregation for the cells of the Pivot table. It's an object containing the field ID and the method for data aggregation. The object parameters are the following:field
- the ID of a fieldmethod
- defines a method for data extraction; about methods and possible options refer to Applying methods
filters
- (optional) defines how data is filtered in the table; it's an object with field IDs and data aggregation method. The description of thefilter
object you can see here:config
info
For handling the inner events you can use the Event Bus methods
Returns
The callback may return boolean or void.
If the event handler function returns false, the operation that triggered the event is blocked and the update-config
operation is halted.
Example
const table = new pivot.Pivot("#root", {
fields,
data: dataset,
config: {
rows: ["studio", "genre"],
columns: [],
values: [
{
id: "title",
method: "count"
},
{
id: "score",
method: "max"
}
]
}
});
//output the config object to console
table.api.on("update-config", (config) => {
console.log("Config has changed", config);
});
Related articles: api.intercept()