Skip to content

Instantly share code, notes, and snippets.

@petyosi
Created February 9, 2018 12:48
Show Gist options
  • Save petyosi/562b82ae62f46f1b97c96e030becdbfb to your computer and use it in GitHub Desktop.
Save petyosi/562b82ae62f46f1b97c96e030becdbfb to your computer and use it in GitHub Desktop.
import React, {Component} from "react";
import {AgGridReact} from "ag-grid-react";
import {connect} from "react-redux";
class SimpleGridExample extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: this.createColumnDefs()
}
}
onGridReady(params) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
this.gridApi.sizeColumnsToFit();
}
createColumnDefs() {
return [
{headerName: "Company", field: "name"},
{headerName: "Price", field: "price", cellFormatter: (params) => params.value.toFixed(2)}
];
}
render() {
let containerStyle = {
height: 115,
width: 500
};
return (
<div style={containerStyle} className="ag-theme-fresh">
<h1>Simple ag-Grid React Example</h1>
<AgGridReact
// properties
columnDefs={this.state.columnDefs}
rowData={this.props.rowData}
// events
onGridReady={this.onGridReady}>
</AgGridReact>
</div>
)
}
}
// pull off row data changes
export default connect(
(state) => {
return {
rowData: state.rowData
}
}
)(SimpleGridExample);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment