AG 网格回调自定义



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

现在我想开始保存这些网格的状态,所以一直在研究回调,例如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并将标准函数更改为箭头函数。

最新更新