ag-grid 回调自定义

ag-grid callback customizations

我有一个包含多个网格的页面,用户可以创建和自定义这些网格。每次用户创建网格时,我都会为其分配一个标识符并将其存储在我的内部状态中(标识符映射 -> 状态)

现在我想开始保存这些网格的状态,所以一直在研究回调,例如 onColumnVisible

这是有效的(伪代码)

render() {
    for each 'identifier' {
        <DataGrid 
            // lots of other stuff
            onColumnVisible={this.saveColEvent}
        />
    }
}

@boundMethod
private saveColEvent(event: ColumnVisibleEvent) {
    const colState: any = event.columnApi.getColumnState();
    // TODO: set the colstate based on the identifier
}

我的问题是如何传递额外参数 - 标识符 - 我需要在 saveColEvent 中为地图编制索引。

谢谢!

编辑:更准确的迭代-

const stateMap: Map<string, MyState> = this.props.stateMapping;
stateMap.forEach(
            (value: MyState, identifier: string) => {
            <div key={identifier}
                <DataGrid 
                    // lots of other stuff
                    onColumnVisible={this.saveColEvent}
                />
            </div>
            });

我知道了。

const stateMap: Map<string, MyState> = this.props.stateMapping;
stateMap.forEach(
            (value: MyState, identifier: string) => {
            <div key={identifier}
                <DataGrid 
                    // lots of other stuff
                    onColumnVisible={() => this.saveColEvent(identifier)}
                />
            </div>
            });


@boundMethod
private saveColEvent(identifier) {
    // this is free, you can mention identifier at any time
    const colState: any = event.columnApi.getColumnState();
}

我想这可能就是您想要的。注意:这是未经测试的。如果它不起作用,请告诉我。

所以我正在做的是添加一个 identifier 并将标准函数更改为箭头函数。