Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 2.11 KB

File metadata and controls

71 lines (57 loc) · 2.11 KB
sidebar_label api.on()
title on Method
description You can learn about the on method in the documentation of the DHTMLX JavaScript Pivot library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Pivot.

api.on()

Description

@short: Allows attaching a handler to the inner events

Usage

api.on(
    event: string,
    handler: function,
    config?: { intercept?: boolean, tag?: number | string | symbol }
): void;

Parameters

  • event - (required) an event to be fired
  • handler - (required) a handler to be attached (the handler arguments will depend on the event to be fired)
  • config - (optional) an object that stores the following parameters:
    • intercept - (optional) if you set intercept: true during event listener creation, this event listener will run before all others
    • tag - (optional) an action tag. You can use the tag name to remove an action handler via the detach method

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);
    }
}, {tag: "open-filter-tag"});