api.on()
Description
Allows attaching a handler to the inner events
Usage
api.on(
event: string,
handler: function
): void;
Parameters
event
- (required) an event to be firedhandler
- (required) a handler to be attached (the handler arguments will depend on the event to be fired)
Events
info
The full list of the Pivot internal events can be found here.
Use the api.on()
method if you want to listen to the actions without modifying them. To make changes to the actions, apply the api.intercept()
method.
Example
The example below shows how to output the label of a field for which the filter was activated:
// create Pivot
const table = new pivot.Pivot("#root", {
fields,
data: dataset,
config: {
rows: ["studio", "genre"],
columns: [],
values: [
{
field: "title",
method: "count"
},
{
field: "score",
method: "max"
}
]
}
});
table.api.on("open-filter", (ev) => {
const fieldObj = ev.field;
const field = fieldObj.base || fieldObj.field;
if (field) {
console.log("The field for which filter was activated:", ev.field.label);
}
});