Skip to main content

api.exec()

Description​

Allows triggering the inner events

Usage​

api.exec(
event: string,
config: object
): Promise<any>;

Parameters​

  • event - (required) an event to be fired
  • config - (required) the config object with parameters (see the event to be fired)

Actions​

info

The full list of Pivot events can be found here

Example​

In the example below, the delete-field event is triggered via the api.exec()method. The last field is removed from the values area. The api.getState() method here is used to get the current state of the Pivot config. The event will be triggered with the button click.

// 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"
}
]
}
});

//calling methods of API: remove a specific value from values in config
function removeLastField() {
if (table.api) {
const state = table.api.getState();
const config = state.config;

const count = config.values.length;

if (count) {
const lastValue = config.values[count - 1];

table.api.exec("delete-field", {
area: "values",
id: lastValue.id, // auto-generated ID of an item added to config.values
});
}
}
}

const button = document.createElement("button");

button.addEventListener("click", removeLastField);
button.textContent = "Remove";

document.body.appendChild(button);