diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7294cd --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ + +ag-Grid React Example +============== + +Example of running ag-Grid inside React application. + +See the [www.ag-grid.com](http://www.ag-grid.com). + + +Building +============== + +To build: +- `npm install` +- `npm install webpack -g` +- `webpack` + +Contributing +============== + +If you notice anything wrong with this example or have ideas on how it can be improved, +please raise a Github task. diff --git a/index.html b/index.html index c27a671..a8ef2f9 100644 --- a/index.html +++ b/index.html @@ -1,12 +1,14 @@ -
- - - - - + + + + + + - + + + \ No newline at end of file diff --git a/package.json b/package.json index 06df2ec..d5b49bc 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,6 @@ "homepage": "http://www.ag-grid.com/", "devDependencies": { "webpack": "1.12.11", - "react": "0.14.6", - "react-dom": "0.14.6", "css-loader": "0.23.1", "style-loader": "0.13.0", "babel-loader": "6.2.1", @@ -33,6 +31,9 @@ "babel-preset-es2015": "6.3.13" }, "dependencies": { - "ag-grid": "latest" + "react": "0.14.6", + "react-dom": "0.14.6", + "ag-grid": "latest", + "ag-grid-react-component": "latest" } } diff --git a/src/AgGridReact.jsx b/src/AgGridReact.jsx deleted file mode 100644 index 8bc715d..0000000 --- a/src/AgGridReact.jsx +++ /dev/null @@ -1,98 +0,0 @@ -import ReactDOM from 'react-dom'; -import React from 'react'; -import AgGrid from 'ag-grid'; -import ComponentUtil from './ComponentUtil'; - -export default class AgGridReact extends React.Component { - - componentDidMount() { - var domNode = ReactDOM.findDOMNode(this); - this.gridOptions = ComponentUtil.copyAttributesToGridOptions(this.props.gridOptions, this.props); - AgGrid(domNode, this.gridOptions); - - this.api = this.gridOptions.api; - this.columnApi = this.gridOptions.columnApi; - this.api.addGlobalListener(this.globalEventListener.bind(this)); - } - - // this method is duplicated, taken from gridOptionsWrapper - getCallbackForEvent(eventName) { - if (!eventName || eventName.length < 2) { - return eventName; - } else { - return 'on' + eventName[0].toUpperCase() + eventName.substr(1); - } - } - - // duplicated, taken from gridOptionsWrapper - globalEventListener(eventName, event) { - var callbackMethodName = this.getCallbackForEvent(eventName); - var callbackFromProps = this.props[callbackMethodName]; - if (callbackFromProps) { - callbackFromProps(event); - } - } - - shouldComponentUpdate () { - // we want full control of the dom, as ag-Grid doesn't use React internally, - // so for performance reasons we tell React we don't need render called after - // property changes. - return false; - } - - componentWillReceiveProps(nextProps) { - // keeping consistent with web components, put changing - // values in currentValue and previousValue pairs and - // not include items that have not changed. - var changes = {}; - ComponentUtil.ALL_PROPERTIES.forEach( (propKey)=> { - if (this.props[propKey]!==nextProps[propKey]) { - changes[propKey] = { - previousValue: this.props[propKey], - currentValue: nextProps[propKey] - }; - } - }); - ComponentUtil.processOnChange(changes, this.gridOptions, this.api, this.columnApi); - } - - componentWillUnmount() { - this.api.destroy(); - } - - render() { - return ; - } -} - -AgGridReact.propTypes = { - style: React.PropTypes.object, - className: React.PropTypes.string, - gridOptions: React.PropTypes.object - - // we should iterate through all the properties and add them here - //onRowSelected: React.PropTypes.func, - //showToolPanel: React.PropTypes.bool -}; - -ComponentUtil.SIMPLE_BOOLEAN_PROPERTIES - .concat(ComponentUtil.WITH_IMPACT_BOOLEAN_PROPERTIES) - .forEach( (propKey)=> { - AgGridReact.propTypes[propKey] = React.PropTypes.bool; - }); - -//ComponentUtil.SIMPLE_PROPERTIES -// .concat(ComponentUtil.WITH_IMPACT_STRING_PROPERTIES) -// .forEach( (propKey)=> { -// AgGridReact.propTypes[propKey] = React.PropTypes.bool; -// }); - - //.concat(ComponentUtil.) - //.concat(ComponentUtil.SIMPLE_NUMBER_PROPERTIES) - //.concat(ComponentUtil.WITH_IMPACT_OTHER_PROPERTIES) - //.concat(ComponentUtil.WITH_IMPACT_NUMBER_PROPERTIES) - //.concat(ComponentUtil.CALLBACKS), - - -var i = new AgGridReact(); -console.log(i); diff --git a/src/ColDefFactory.jsx b/src/ColDefFactory.jsx new file mode 100644 index 0000000..41d049a --- /dev/null +++ b/src/ColDefFactory.jsx @@ -0,0 +1,208 @@ +import SkillsCellRenderer from './SkillsCellRenderer.jsx'; +import ProficiencyCellRenderer from './ProficiencyCellRenderer.jsx'; +import RefData from './RefData'; +import ReactDOM from 'react-dom'; +import React from 'react'; +import AgGrid from 'ag-grid-react-component'; +import {reactCellRendererFactory} from 'ag-grid-react-component'; +import {reactFilterFactory} from 'ag-grid-react-component'; +import SkillsFilter from './SkillsFilter.jsx'; +import ProficiencyFilter from './ProficiencyFilter.jsx'; + +export default class ColDefFactory { + + createColDefs() { + + var columnDefs = [ + {headerName: '', width: 30, checkboxSelection: true, suppressSorting: true, + suppressMenu: true, pinned: true}, + { + headerName: 'Employee', + children: [ + {headerName: "Name", field: "name", + width: 150, pinned: true}, + {headerName: "Country", field: "country", width: 150, + cellRenderer: countryCellRenderer, pinned: true, + filterParams: {cellRenderer: countryCellRenderer, cellHeight: 20}}, + ] + }, + { + headerName: 'IT Skills', + children: [ + {headerName: "Skills", width: 125, suppressSorting: true, field: 'skills', + cellRenderer: reactCellRendererFactory(SkillsCellRenderer), + filter: reactFilterFactory(SkillsFilter) + }, + {headerName: "Proficiency", field: "proficiency", filter: 'number', width: 120, + cellRenderer: reactCellRendererFactory(ProficiencyCellRenderer), + filter: reactFilterFactory(ProficiencyFilter)} + ] + }, + { + headerName: 'Contact', + children: [ + {headerName: "Mobile", field: "mobile", width: 150, filter: 'text'}, + {headerName: "Land-line", field: "landline", width: 150, filter: 'text'}, + {headerName: "Address", field: "address", width: 500, filter: 'text'} + ] + } + ]; + return columnDefs; + } +} + +// this is a simple cell renderer, putting together static html, no +// need to use React for it. +function countryCellRenderer(params) { + var flag = "
');
- }
- });
- return skills.join(' ');
- }
-
- function countryCellRenderer(params) {
- var flag = "