import React from "react"; import {AgGridReact} from "ag-grid-react"; import RowDataFactory from "./RowDataFactory"; import ColDefFactory from "./ColDefFactory.jsx"; import MyReactDateComponent from "./MyReactDateComponent.jsx"; import MyReactHeaderComponent from "./MyReactHeaderComponent.jsx"; import "./myApp.css"; // take this line out if you do not want to use ag-Grid-Enterprise import "ag-grid-enterprise"; export default class MyApp extends React.Component { constructor() { super(); this.state = { quickFilterText: null, showGrid: true, showToolPanel: false, columnDefs: new ColDefFactory().createColDefs(), rowData: new RowDataFactory().createRowData(), icons: { columnRemoveFromGroup: '', filter: '', sortAscending: '', sortDescending: '', groupExpanded: '', groupContracted: '', columnGroupOpened: '', columnGroupClosed: '' } }; // the grid options are optional, because you can provide every property // to the grid via standard React properties. however, the react interface // doesn't block you from using the standard JavaScript interface if you // wish. Maybe you have the gridOptions stored as JSON on your server? If // you do, the providing the gridOptions as a standalone object is just // what you want! this.gridOptions = { //We register the react date component that ag-grid will use to render dateComponentFramework: MyReactDateComponent, // this is how you listen for events using gridOptions onModelUpdated: function () { console.log('event onModelUpdated received'); }, defaultColDef: { headerComponentFramework: MyReactHeaderComponent, headerComponentParams: { menuIcon: 'fa-bars' } }, // this is a simple property rowBuffer: 10 // no need to set this, the default is fine for almost all scenarios }; this.onGridReady = this.onGridReady.bind(this); this.onRowSelected = this.onRowSelected.bind(this); this.onCellClicked = this.onCellClicked.bind(this); } onShowGrid(show) { this.setState({ showGrid: show }); } onToggleToolPanel(event) { this.setState({showToolPanel: event.target.checked}); } onGridReady(params) { this.api = params.api; this.columnApi = params.columnApi; } selectAll() { this.api.selectAll(); } deselectAll() { this.api.deselectAll(); } setCountryVisible(visible) { this.columnApi.setColumnVisible('country', visible); } onQuickFilterText(event) { this.setState({quickFilterText: event.target.value}); } onCellClicked(event) { console.log('onCellClicked: ' + event.data.name + ', col ' + event.colIndex); } onRowSelected(event) { console.log('onRowSelected: ' + event.node.data.name); } onRefreshData() { var newRowData = new RowDataFactory().createRowData(); this.setState({ rowData: newRowData }); } invokeSkillsFilterMethod() { var skillsFilter = this.api.getFilterInstance('skills'); var componentInstance = skillsFilter.getFrameworkComponentInstance(); componentInstance.helloFromSkillsFilter(); } dobFilter() { let dateFilterComponent = this.gridOptions.api.getFilterInstance('dob'); dateFilterComponent.setFilterType('equals'); dateFilterComponent.setDateFrom('2000-01-01'); this.gridOptions.api.onFilterChanged(); } render() { var gridTemplate; var bottomHeaderTemplate; var topHeaderTemplate; topHeaderTemplate = (
Employees Skills and Contact Details
); // showing the bottom header and grid is optional, so we put in a switch if (this.state.showGrid) { bottomHeaderTemplate = (
Grid API: Column API:
Filter API:
); gridTemplate = (
); } return
{topHeaderTemplate} {bottomHeaderTemplate} {gridTemplate}
; } }