I'm not sure if this isn't supported or if I just haven't figured this out yet with Ag-Grid-React.
My problem: I need a button component to be rendered in each cell under a Delete Row column that has onClick
and label
as props. Upon the button being clicked, I need to dispatch a Redux action that deletes the current row from my table's data.
Column Defs:
import Button from '../button';
import { deleteRow } from './actions';
import { reactCellRendererFactory } from 'ag-grid-react';
const columnDefs = [
{
headerName: 'Delete Row',
width: 100,
cellRenderer: reactCellRendererFactory(Button),
cellRendererParams: {
onClick: (row) => deleteRow(row.data.id),
backgroundColor: 'red',
label: 'Delete',
},
}, ...
Button Component:
import React, { PropTypes, PureComponent } from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
class Button extends PureComponent {
static propTypes = {
backgroundColor: PropTypes.string,
label: PropTypes.string,
labelColor: PropTypes.string,
onClick: PropTypes.func,
};
static defaultProps = {
backgroundColor: 'green',
label: 'Save',
labelColor: 'white',
};
render() {
return (
<MuiThemeProvider>
<RaisedButton
backgroundColor={this.props.backgroundColor}
label={this.props.label}
labelColor={this.props.labelColor}
onClick={this.props.onClick}
/>
</MuiThemeProvider>
);
}
}
export default Button;
The Button
component does not respond to clicking despite having assigned onClick
in cellRendererParams
, though it does have access to this.props.label
and this.props.onClick
.
row
appears to be undefined
, so what is the best way to get the selected row data in this case for the onClick
handler?
What is the best way to do this? Thanks for any help you can lend :)