а

Pivot grid is undefined


#1

I have been working with dhx.pivot so a few days at my new work.

Guides tell me that I could/should add an event listener to grid items like so:

pivot.grid.events.on(‘someEvent’, () => { // Handle event });

But when I try to do that, it says grid is undefined, which I can see at the pivot object itself.

There is a “private” _grid field on the object, but using it to set an event listener doesn’t work.

        this.pivot = new dhx.Pivot(this.el, {
        data: [],
        fields: {
            rows: pivotRows,
            columns: pivotColumns,
            values: pivotValues,
        },
        layout: {
            footer: true,
            gridOnly: true,
            columnsWidth: 'auto',
            rowsHeadersWidth: 'auto',
        },
        fieldList
    });
    this.pivot.addMathMethod('avg', 'Avg', (cellData: any[]) => {
        let sum = 0;
        let count = 0;
        cellData.forEach(cd => {
            if (cd && cd.isComplex) {
                const [s, c] = cd.data;
                sum += parseFloat(s);
                count += parseFloat(c);
            }
        });
        const avg = count > 0 ? sum / count : null;
        return {
            isComplex: true,
            data: [sum, count],
            calculated: avg
        };
    });

I’m setting the data later:
this.pivot.setData(tableData);

Version is 1.3.3.


#2

Please, note, that the grid-related API is available since the 1.4 version:
https://docs.dhtmlx.com/pivot/whatsnew.html#version14