orion_kid
orion_kid

Reputation: 455

ag-grid callback customizations

I have a page with multiple grids which can be created and customized by users. Each time the user creates a grid I assign it an identifier and store it in my internal state (Map of identifier -> state)

Now I want to start saving the state of these grids so have been looking into the callbacks such as for example onColumnVisible.

This much is working (pseudocode)

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
}

My question is how can I pass the extra parameter - identifier - which I need in saveColEvent to index into the map.

Thanks !

Edit: More accurate iteration-

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>
            });

Upvotes: 0

Views: 215

Answers (1)

new Q Open Wid
new Q Open Wid

Reputation: 2283

I got it.

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();
}

I think this might be what you want. Note: This is untested. If it doesn't work, tell me.

So what I'm doing is adding a identifier and changing the standard function into a arrow function.

Upvotes: 1

Related Questions