import React, {Component} from "react"; import {AgGridReact} from "ag-grid-react"; import RowDataFactory from "./RowDataFactory"; import ColDefFactory from "./ColDefFactory.jsx"; import DateComponent from "./DateComponent.jsx"; import SortableHeaderComponent from "./SortableHeaderComponent"; import "./RichGridExample.css"; // take this line out if you do not want to use ag-Grid-Enterprise import "ag-grid-enterprise"; export default class RichGridExample extends Component { constructor() { super(); this.state = { quickFilterText: null, 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: DateComponent, // this is how you listen for events using gridOptions onModelUpdated: function () { console.log('event onModelUpdated received'); }, defaultColDef: { headerComponentFramework: SortableHeaderComponent, headerComponentParams: { menuIcon: 'fa-bars' } }, // this is a simple property rowBuffer: 10, // no need to set this, the default is fine for almost all scenarios, floatingFilter: true }; } /* Grid Events we're listening to */ onGridReady = (params) => { this.api = params.api; this.columnApi = params.columnApi; }; onCellClicked = (event) => { console.log('onCellClicked: ' + event.data.name + ', col ' + event.colIndex); }; onRowSelected = (event) => { console.log('onRowSelected: ' + event.node.data.name); }; /* Demo related methods */ onToggleToolPanel = (event) => { this.setState({showToolPanel: event.target.checked}); }; deselectAll() { this.api.deselectAll(); } onQuickFilterText = (event) => { this.setState({quickFilterText: event.target.value}); }; onRefreshData = () => { this.setState({ rowData: new RowDataFactory().createRowData() }); }; invokeSkillsFilterMethod = () => { let skillsFilter = this.api.getFilterInstance('skills'); let componentInstance = skillsFilter.getFrameworkComponentInstance(); componentInstance.helloFromSkillsFilter(); }; dobFilter = () => { let dateFilterComponent = this.api.getFilterInstance('dob'); dateFilterComponent.setFilterType('equals'); dateFilterComponent.setDateFrom('2000-01-01'); // as the date filter is a React component, and its using setState internally, we need // to allow time for the state to be set (as setState is an async operation) // simply wait for the next tick setTimeout(() => { this.api.onFilterChanged(); }, 0) }; render() { return (

Rich Grid with Declarative Markup Example

Employees Skills and Contact Details
Grid API: Column API:
Filter API:
enableColResize="true") suppressRowClickSelection rowSelection="multiple" enableColResize enableSorting enableFilter groupHeaders rowHeight="22"/>

Rich Grid Example

This example demonstrates many features of ag-Grid.

Select All/Clear Selection: Select or Deselect All Rows

Hide/Show Country Column: Select or Deselect All Rows (expand the Employee column to show the Country column first)

Toggle The Tool Panel: Let your users Pivot, Group and Aggregate using the Tool Panel

Refresh Data: Dynamically Update Grid Data

Quick Filter: Perform Quick Grid Wide Filtering with the Quick Filter

DOB Filter: Set the DOB filter to 01/01/2000 using the Filter API (expand the Employee column to show the DOB column)

Custom Headers: Sort, Filter and Render Headers using Header Components

Grid & Column API

Utilise Grid Features Programmatically Using the APIs Available

Grid API Column API

Header Components

Customer the Header with React Components

Header Component Header Group Component

Filters

Filter with Quick Filters, Floating Filters, Built In Filters or Using the Filter API

Quick Filter Floating Filters Built in Filters Filter API

Tool Panel

Let your users Pivot, Group and Aggregate using the Tool Panel

Tool Panel

The Rest

Pinned Columns, Checkbox Selection, Customer Renderers, Data Updates

React with ag-Grid Pinned Column Checkbox Selection Cell Renderers Updating Data
); } }