import React, {Component} from "react"; import {AgGridColumn, AgGridReact} from "ag-grid-react"; import RowDataFactory from "./RowDataFactory"; import DateComponent from "./DateComponent.jsx"; import SkillsCellRenderer from './SkillsCellRenderer.jsx'; import NameCellEditor from './NameCellEditor.jsx'; import ProficiencyCellRenderer from './ProficiencyCellRenderer.jsx'; import RefData from './RefData'; import SkillsFilter from './SkillsFilter.jsx'; import ProficiencyFilter from './ProficiencyFilter.jsx'; import HeaderGroupComponent from './HeaderGroupComponent.jsx'; import SortableHeaderComponent from './SortableHeaderComponent.jsx'; import "./RichGridDeclarativeExample.css"; // take this line out if you do not want to use ag-Grid-Enterprise import "ag-grid-enterprise"; export default class RichGridDeclarativeExample extends Component { constructor() { super(); this.state = { quickFilterText: null, showToolPanel: false, rowData: new RowDataFactory().createRowData(), icons: { columnRemoveFromGroup: '', filter: '', sortAscending: '', sortDescending: '', groupExpanded: '', groupContracted: '' } }; } /* 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.setModel({ type: 'equals', dateFrom: '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) }; static countryCellRenderer(params) { if (params.value) { return ` ${params.value}`; } else { return null; } } static dateCellRenderer(params) { return RichGridDeclarativeExample.pad(params.value.getDate(), 2) + '/' + RichGridDeclarativeExample.pad(params.value.getMonth() + 1, 2) + '/' + params.value.getFullYear(); } static pad(num, totalStringSize) { let asString = num + ""; while (asString.length < totalStringSize) asString = "0" + asString; return asString; } 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 floatingFilter groupHeaders // setting grid wide date component dateComponentFramework={DateComponent} // setting default column properties defaultColDef={{ headerComponentFramework: SortableHeaderComponent, headerComponentParams: { menuIcon: 'fa-bars' } }} >

Rich Grid with Declarative Markup Example

This example demonstrates many features of ag-Grid, with Grid and Column Definition defined declaratively (i.e. with markup).

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