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,
sideBar: 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 */
onToggleSidebar = (event) => {
this.setState({sideBar: 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 (
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 Side Bar: Let your users Pivot, Group and Aggregate using the Side Bar
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
Utilise Grid Features Programmatically Using the APIs Available
Grid API Column APIFilter with Quick Filters, Floating Filters, Built In Filters or Using the Filter API
Quick Filter Floating Filters Built in Filters Filter APIPinned Columns, Checkbox Selection, Customer Renderers, Data Updates
React with ag-Grid Pinned Column Checkbox Selection Cell Renderers Updating Data