|
1 | 1 | import React, { Component } from 'react';
|
2 |
| -import Tree from './Tree'; |
3 |
| -import './App.css'; |
| 2 | +import { AgGridReact } from 'ag-grid-react'; |
| 3 | +import 'ag-grid/dist/styles/ag-grid.css'; |
| 4 | +import 'ag-grid/dist/styles/ag-theme-material.css'; |
| 5 | +import 'ag-grid-enterprise'; |
| 6 | + |
| 7 | +import {LicenseManager} from "ag-grid-enterprise/main"; |
| 8 | +// The tree view from ag-Grid requires an enterprise license and a product key |
| 9 | +// Pricing: https://www.ag-grid.com/license-pricing.php |
| 10 | +// Trial: https://www.ag-grid.com/start-trial.php |
| 11 | +LicenseManager.setLicenseKey("your license key"); |
| 12 | + |
| 13 | +const data = [ |
| 14 | + { |
| 15 | + orgHierarchy: ['Erica Rogers'], |
| 16 | + jobTitle: 'CEO', |
| 17 | + employmentType: 'Permanent', |
| 18 | + |
| 19 | + }, |
| 20 | + { |
| 21 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett'], |
| 22 | + jobTitle: 'Exec. Vice President', |
| 23 | + employmentType: 'Permanent', |
| 24 | + |
| 25 | + }, |
| 26 | + { |
| 27 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Esther Baker'], |
| 28 | + jobTitle: 'Director of Operations', |
| 29 | + employmentType: 'Permanent', |
| 30 | + |
| 31 | + }, |
| 32 | + { |
| 33 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Esther Baker', 'Brittany Hanson'], |
| 34 | + jobTitle: 'Fleet Coordinator', |
| 35 | + employmentType: 'Permanent', |
| 36 | + |
| 37 | + }, |
| 38 | + { |
| 39 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Esther Baker', 'Brittany Hanson', 'Leah Flowers'], |
| 40 | + jobTitle: 'Parts Technician', |
| 41 | + employmentType: 'Contract', |
| 42 | + |
| 43 | + }, |
| 44 | + { |
| 45 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Esther Baker', 'Brittany Hanson', 'Tammy Sutton'], |
| 46 | + jobTitle: 'Service Technician', |
| 47 | + employmentType: 'Contract', |
| 48 | + |
| 49 | + }, |
| 50 | + { |
| 51 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Esther Baker', 'Derek Paul'], |
| 52 | + jobTitle: 'Inventory Control', |
| 53 | + employmentType: 'Permanent', |
| 54 | + |
| 55 | + }, |
| 56 | + { |
| 57 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Francis Strickland'], |
| 58 | + jobTitle: 'VP Sales', |
| 59 | + employmentType: 'Permanent', |
| 60 | + |
| 61 | + }, |
| 62 | + { |
| 63 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Francis Strickland', 'Morris Hanson'], |
| 64 | + jobTitle: 'Sales Manager', |
| 65 | + employmentType: 'Permanent', |
| 66 | + |
| 67 | + }, |
| 68 | + { |
| 69 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Francis Strickland', 'Todd Tyler'], |
| 70 | + jobTitle: 'Sales Executive', |
| 71 | + employmentType: 'Contract', |
| 72 | + |
| 73 | + }, |
| 74 | + { |
| 75 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Francis Strickland', 'Bennie Wise'], |
| 76 | + jobTitle: 'Sales Executive', |
| 77 | + employmentType: 'Contract', |
| 78 | + |
| 79 | + }, |
| 80 | + { |
| 81 | + orgHierarchy: ['Erica Rogers', 'Malcolm Barrett', 'Francis Strickland', 'Joel Cooper'], |
| 82 | + jobTitle: 'Sales Executive', |
| 83 | + employmentType: 'Permanent', |
| 84 | + |
| 85 | + } |
| 86 | +]; |
4 | 87 |
|
5 | 88 | class App extends Component {
|
6 |
| - render() { |
| 89 | + columns = [ |
| 90 | + { |
| 91 | + field: 'jobTitle' |
| 92 | + }, |
| 93 | + { |
| 94 | + field: 'employmentType' |
| 95 | + } |
| 96 | + ] |
| 97 | + |
| 98 | + getDataPath = (data) => { |
| 99 | + return data.orgHierarchy; |
| 100 | + } |
| 101 | + |
| 102 | + autoGroupColumnDef = { |
| 103 | + headerName: 'Organisation Hierarchy', |
| 104 | + width: 300, |
| 105 | + cellRendererParams: { |
| 106 | + suppressCount: true |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + render () { |
7 | 111 | return (
|
8 |
| - <Tree/> |
| 112 | + <div className="ag-theme-material"> |
| 113 | + <AgGridReact |
| 114 | + containerStyle={{height: '400px'}} |
| 115 | + columnDefs={this.columns} |
| 116 | + rowData={data} |
| 117 | + treeData={true} |
| 118 | + getDataPath={this.getDataPath} |
| 119 | + autoGroupColumnDef={this.autoGroupColumnDef} |
| 120 | + /> |
| 121 | + </div> |
9 | 122 | );
|
10 | 123 | }
|
11 | 124 | }
|
|
0 commit comments