Compare commits

..

29 Commits

Author SHA1 Message Date
Alberto
2228a8d0c9 Merge branch 'master' into latest 2017-09-08 09:40:53 +01:00
Sean Landsman
9528d5a5bc Move per col icons to grid based 2017-09-04 10:39:17 +01:00
Alberto
3b5eaac21a Merge branch 'latest' into 13.1.0
# Conflicts:
#	aot/dist/agGridColumn.ngfactory.ts
#	aot/dist/agGridColumn.ngsummary.json
#	aot/dist/agGridNg2.ngfactory.ts
#	aot/dist/agGridNg2.ngsummary.json
#	aot/dist/aggrid.module.ngfactory.ts
#	aot/dist/aggrid.module.ngsummary.json
#	aot/dist/baseComponentFactory.ngsummary.json
#	aot/dist/interfaces.ngsummary.json
#	aot/dist/ng2ComponentFactory.ngsummary.json
#	aot/dist/ng2FrameworkComponentWrapper.ngsummary.json
#	aot/dist/ng2FrameworkFactory.ngsummary.json
#	aot/main.ngsummary.json
#	aot/src/agGridColumn.ngfactory.ts
#	aot/src/agGridColumn.ngsummary.json
#	aot/src/agGridNg2.ngfactory.ts
#	aot/src/agGridNg2.ngsummary.json
#	aot/src/aggrid.module.ngfactory.ts
#	aot/src/aggrid.module.ngsummary.json
#	aot/src/baseComponentFactory.ngsummary.json
#	aot/src/interfaces.ngsummary.json
#	aot/src/ng2ComponentFactory.ngsummary.json
#	aot/src/ng2FrameworkComponentWrapper.ngsummary.json
#	aot/src/ng2FrameworkFactory.ngsummary.json
2017-09-01 14:02:24 +01:00
Sean Landsman
73cc989512 AG-730 New example for redux 2017-08-31 17:17:26 +01:00
Alberto
5a45846cb7 Release 13.0.1 2017-08-29 15:27:33 +02:00
Petyo Ivanov
2d8d5b125e Removed legacy padding 2017-08-29 13:34:18 +03:00
Alberto
818b7798ee Merge branch 'latest' into 13.0.0
# Conflicts:
#	package.json
2017-08-25 16:59:25 +02:00
Sean Landsman
15ba8d7e60 Rename cellFormatter to valueFormatter 2017-08-23 14:04:13 +01:00
Alberto
eab958c3e9 Releasing 13.0.0 2017-08-23 11:35:39 +01:00
Sean Landsman
3a17b7f638 AG-668 Update all README.md to point to appropriate plunker/seed 2017-08-21 11:45:09 +01:00
Sean Landsman
734d39e2d7 AG-676 Move framework examples into parent folder for easier exclusion 2017-08-17 11:04:12 +01:00
Sean Landsman
0d7cace354 Add example for keypress in editors
https://github.com/ag-grid/ag-grid-react/issues/60
2017-08-10 16:02:03 +01:00
Sean Landsman
fa0881bfcf Merge remote-tracking branch 'origin/latest' into latest 2017-08-10 15:51:05 +01:00
Sean Landsman
62b9e3582a Add example for keypress in editors
https://github.com/ag-grid/ag-grid-react/issues/60
2017-08-10 15:50:54 +01:00
Petyo Ivanov
949797d4be rename repo from ceolter to ag-grid 2017-08-04 12:23:47 +01:00
Sean Landsman
a869fe3819 CI Work 2017-08-02 13:48:39 +01:00
Sean Landsman
c611af4f39 CI Work 2017-08-02 13:15:55 +01:00
Sean Landsman
7cab3190ae CI Work 2017-08-02 12:19:07 +01:00
Sean Landsman
71fe653fcb CI Work 2017-08-02 11:55:18 +01:00
Sean Landsman
ba1c213ce0 Change selectAll to use refs to expand on example 2017-07-27 08:17:15 +01:00
Sean Landsman
46217c9ad7 Fix sorting issue 2017-07-26 12:10:12 +01:00
Sean Landsman
017642e4d7 AG-643 Tidy React examples 2017-07-25 12:47:47 +01:00
Sean Landsman
79b0eda61b AG-643 Tidy React examples 2017-07-25 12:47:07 +01:00
Sean Landsman
a70f248af5 AG-642 Remove deprecation warning in preparation for 16.x 2017-07-25 12:46:21 +01:00
Alberto
32142b435b v12 Hot fixes 2017-07-21 12:10:00 +02:00
Alberto
d71781899d AG-618 Fixing floating filter issue. Also allowing for gulp watch of Angular and React 2017-07-20 13:59:16 +02:00
Sean Landsman
9560f86bf5 Updated readme 2017-07-19 10:30:28 +01:00
Alberto
9f4b270884 New release branch, everything compiles 2017-07-13 11:25:34 +01:00
John Masterson
e5627d8b9f Added links to ReadMe 2017-07-11 17:07:57 +01:00
23 changed files with 545 additions and 78 deletions

View File

@@ -4,7 +4,14 @@ ag-Grid React Example
Examples of running ag-Grid inside React application. Examples of running ag-Grid inside React application.
See the [www.ag-grid.com](http://www.ag-grid.com). See [www.ag-grid.com](http://www.ag-grid.com) for an overview and full documentation.
Frameworks Supported
====================
Framework specific Getting Started guides:
[Angular 1](https://www.ag-grid.com/best-angularjs-data-grid/) | [Angular 2](https://www.ag-grid.com/best-angular-2-data-grid/) | [Aurelia](https://www.ag-grid.com/best-aurelia-data-grid/)
[Javascript](https://www.ag-grid.com/best-javascript-data-grid/) | [React](https://www.ag-grid.com/best-react-data-grid/) | [TypeScript](https://www.ag-grid.com/ag-grid-typescript-webpack-2/)
[VueJS](https://www.ag-grid.com/best-vuejs-data-grid/) | [Web Components](https://www.ag-grid.com/best-web-component-data-grid/)
There are two examples: There are two examples:
@@ -18,5 +25,5 @@ Building
To build: To build:
- `npm install` - `npm install`
- `npm install webpack -g` - `npm install webpack -g`
- `npm run standard` or `npm run large` - `npm run example`, `npm run large` or `npm run trader`
- navigate to localhost:8080 - navigate to localhost:8080

26
gulpfile.js Normal file
View File

@@ -0,0 +1,26 @@
const gulp = require('gulp');
const gulpTypescript = require('gulp-typescript');
const merge = require('merge2');
gulp.task('watch', watchTask);
gulp.task('rebuild-ag-grid-react', rebuildAgGridReact);
const tsConfig = '../ag-grid-react/tsconfig.json';
const tsProject = gulpTypescript.createProject(tsConfig);
function rebuildAgGridReact() {
const tsResult = gulp
.src('../ag-grid-react/src/**/*.ts')
.pipe(tsProject());
return merge([
tsResult.dts
.pipe(gulp.dest('node_modules/ag-grid-react/lib')),
tsResult.js
.pipe(gulp.dest('node_modules/ag-grid-react/lib'))
]);
}
function watchTask() {
gulp.watch(['../ag-grid-react/src/**/*'], rebuildAgGridReact);
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "ag-grid-react-example", "name": "ag-grid-react-example",
"version": "11.0.0", "version": "13.1.0",
"description": "Example Reach applicaiton using ag-Grid.", "description": "Example Reach applicaiton using ag-Grid.",
"main": "dist/ag-grid-react-example.js", "main": "dist/ag-grid-react-example.js",
"scripts": { "scripts": {
@@ -12,17 +12,18 @@
"copy-examples": "ncp images dist/examples/images && ncp src/index.html dist/examples/index.html && ncp dist/react-examples.js dist/examples/dist/react-examples.js && ncp src dist/examples/src", "copy-examples": "ncp images dist/examples/images && ncp src/index.html dist/examples/index.html && ncp dist/react-examples.js dist/examples/dist/react-examples.js && ncp src dist/examples/src",
"copy-trader": "ncp src-trader-dashboard/index.html dist/trader/index.html && ncp dist/react-trader.js dist/trader/dist/react-trader.js", "copy-trader": "ncp src-trader-dashboard/index.html dist/trader/index.html && ncp dist/react-trader.js dist/trader/dist/react-trader.js",
"copy": "npm run copy-examples && npm run copy-trader", "copy": "npm run copy-examples && npm run copy-trader",
"build-large": "webpack --config webpack.config.large.js --progress --profile --bail",
"build-examples": "webpack --config webpack.config.examples.js --progress --profile --bail", "build-examples": "webpack --config webpack.config.examples.js --progress --profile --bail",
"build-dashboard": "webpack --config webpack.config.trader.js --progress --profile --bail", "build-dashboard": "webpack --config webpack.config.trader.js --progress --profile --bail",
"build-all": "npm run build-examples && npm run build-dashboard", "build-all": "npm run build-examples && npm run build-dashboard",
"build": "npm run clean && npm run mkdirs && npm run build-all && npm run copy", "build": "npm run clean && npm run mkdirs && npm run build-all && npm run copy",
"copy-to-docs": "ncp dist/examples ../ag-grid-docs/src/react-examples/examples && ncp dist/trader ../ag-grid-docs/src/react-examples/trader", "copy-to-docs": "ncp dist/examples ../ag-grid-docs/src/framework-examples/react-examples/examples && ncp dist/trader ../ag-grid-docs/src/framework-examples/react-examples/trader",
"build-to-docs": "npm run build && npm run copy-to-docs", "build-to-docs": "npm run build && npm run copy-to-docs",
"start": "npm run examples" "start": "npm run examples"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/ceolter/ag-grid-react-example.git" "url": "https://github.com/ag-grid/ag-grid-react-example.git"
}, },
"keywords": [ "keywords": [
"react", "react",
@@ -33,7 +34,7 @@
"author": "Niall Crosby <niall.crosby@gmail.com>", "author": "Niall Crosby <niall.crosby@gmail.com>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/ceolter/ag-grid-react-example/issues" "url": "https://github.com/ag-grid/ag-grid-react-example/issues"
}, },
"homepage": "http://www.ag-grid.com/", "homepage": "http://www.ag-grid.com/",
"devDependencies": { "devDependencies": {
@@ -43,29 +44,32 @@
"babel-preset-react": "6.24.x", "babel-preset-react": "6.24.x",
"babel-preset-stage-0": "6.24.x", "babel-preset-stage-0": "6.24.x",
"babel-preset-stage-1": "6.24.x", "babel-preset-stage-1": "6.24.x",
"prop-types": "15.5.x",
"css-loader": "0.23.x", "css-loader": "0.23.x",
"mkdirp": "0.5.1", "mkdirp": "0.5.1",
"ncp": "2.0.0", "ncp": "2.0.0",
"prop-types": "15.5.x",
"rimraf": "2.5.x", "rimraf": "2.5.x",
"style-loader": "0.13.x", "style-loader": "0.13.x",
"webpack": "1.12.x", "webpack": "1.12.x",
"webpack-dev-server": "1.14.x" "webpack-dev-server": "1.14.x",
"gulp": "3.9.x",
"gulp-typescript": "3.1.x",
"merge2": "1.0.x",
"typescript": "2.3.x"
}, },
"dependencies": { "dependencies": {
"bootstrap": "3.3.7", "bootstrap": "3.3.7",
"d3": "4.9.1", "d3": "4.9.1",
"file-loader": "0.11.1", "file-loader": "0.11.1",
"lodash": "4.17.4", "lodash": "4.17.4",
"react": "15.5.x", "react": "15.6.x",
"react-dom": "15.5.x", "react-dom": "15.6.x",
"react-dom-factories": "1.0.0",
"react-redux": "5.0.x", "react-redux": "5.0.x",
"redux": "3.6.x", "redux": "3.6.x",
"url-search-params-polyfill": "1.2.0", "url-search-params-polyfill": "1.2.0",
"ag-grid": "11.0.x", "ag-grid": "13.1.x",
"ag-grid-enterprise": "11.0.x", "ag-grid-enterprise": "13.1.x",
"ag-grid-react": "11.0.x" "ag-grid-react": "13.1.x"
} }
} }

View File

@@ -23,21 +23,21 @@ export default class extends Component {
{ {
field: 'price', field: 'price',
headerName: 'Price', headerName: 'Price',
cellFormatter: this.numberFormatter, valueFormatter: this.numberFormatter,
cellRenderer: 'animateShowChange', cellRenderer: 'animateShowChange',
cellStyle: {'text-align': 'right'} cellStyle: {'text-align': 'right'}
}, },
{ {
field: 'bid', field: 'bid',
headerName: 'Bid', headerName: 'Bid',
cellFormatter: this.numberFormatter, valueFormatter: this.numberFormatter,
cellRenderer: 'animateShowChange', cellRenderer: 'animateShowChange',
cellStyle: {'text-align': 'right'} cellStyle: {'text-align': 'right'}
}, },
{ {
field: 'ask', field: 'ask',
headerName: 'Ask', headerName: 'Ask',
cellFormatter: this.numberFormatter, valueFormatter: this.numberFormatter,
cellRenderer: 'animateShowChange', cellRenderer: 'animateShowChange',
cellStyle: {'text-align': 'right'} cellStyle: {'text-align': 'right'}
} }

View File

@@ -6,12 +6,14 @@ import DynamicComponentsExample from "./dynamicComponentExample/DynamicComponent
import RichGridExample from "./richGridExample/RichGridExample"; import RichGridExample from "./richGridExample/RichGridExample";
import RichComponentsExample from "./richComponentExample/RichComponentsExample"; import RichComponentsExample from "./richComponentExample/RichComponentsExample";
import EditorComponentsExample from "./editorComponentExample/EditorComponentsExample"; import EditorComponentsExample from "./editorComponentExample/EditorComponentsExample";
import FloatingRowComponentExample from "./floatingRowExample/FloatingRowComponentExample"; import PinnedRowComponentExample from "./pinnedRowExample/PinnedRowComponentExample";
import FullWidthComponentExample from "./fullWidthExample/FullWidthComponentExample"; import FullWidthComponentExample from "./fullWidthExample/FullWidthComponentExample";
import GroupedRowInnerRendererComponentExample from "./groupedRowInnerRendererExample/GroupedRowInnerRendererComponentExample"; import GroupedRowInnerRendererComponentExample from "./groupedRowInnerRendererExample/GroupedRowInnerRendererComponentExample";
import FilterComponentExample from "./filterComponentExample/FilterComponentExample"; import FilterComponentExample from "./filterComponentExample/FilterComponentExample";
import MasterDetailExample from "./masterDetailExample/MasterDetailExample"; import MasterDetailExample from "./masterDetailExample/MasterDetailExample";
import SimpleReduxExample from "./simpleReduxExample/SimpleReduxExample"; import SimpleReduxExample from "./simpleReduxExample/SimpleReduxExample";
import FloatingFilterGridExample from "./floatingFilter/FloatingFilterGridExample";
import SimpleReduxDynamicExample from "./simpleReduxDynamicComponentExample/SimpleReduxExample";
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {
@@ -44,12 +46,14 @@ class App extends Component {
<li role="presentation" className={this.state.example === 'dynamic' ? 'active' : null} onClick={() => this.setExample("dynamic")}><a href="#">Dynamic React Component Example</a></li> <li role="presentation" className={this.state.example === 'dynamic' ? 'active' : null} onClick={() => this.setExample("dynamic")}><a href="#">Dynamic React Component Example</a></li>
<li role="presentation" className={this.state.example === 'rich-dynamic' ? 'active' : null} onClick={() => this.setExample("rich-dynamic")}><a href="#">Dynamic React Components - Richer Example</a></li> <li role="presentation" className={this.state.example === 'rich-dynamic' ? 'active' : null} onClick={() => this.setExample("rich-dynamic")}><a href="#">Dynamic React Components - Richer Example</a></li>
<li role="presentation" className={this.state.example === 'editor' ? 'active' : null} onClick={() => this.setExample("editor")}><a href="#">Cell Editor Component Example</a></li> <li role="presentation" className={this.state.example === 'editor' ? 'active' : null} onClick={() => this.setExample("editor")}><a href="#">Cell Editor Component Example</a></li>
<li role="presentation" className={this.state.example === 'floating-row' ? 'active' : null} onClick={() => this.setExample("floating-row")}><a href="#">Floating Row Renderer Example</a></li> <li role="presentation" className={this.state.example === 'pinned-row' ? 'active' : null} onClick={() => this.setExample("pinned-row")}><a href="#">Pinned Row Renderer Example</a></li>
<li role="presentation" className={this.state.example === 'full-width' ? 'active' : null} onClick={() => this.setExample("full-width")}><a href="#">Full Width Renderer Example</a></li> <li role="presentation" className={this.state.example === 'full-width' ? 'active' : null} onClick={() => this.setExample("full-width")}><a href="#">Full Width Renderer Example</a></li>
<li role="presentation" className={this.state.example === 'group-row' ? 'active' : null} onClick={() => this.setExample("group-row")}><a href="#">Grouped Row Inner Renderer Example</a></li> <li role="presentation" className={this.state.example === 'group-row' ? 'active' : null} onClick={() => this.setExample("group-row")}><a href="#">Grouped Row Inner Renderer Example</a></li>
<li role="presentation" className={this.state.example === 'filter' ? 'active' : null} onClick={() => this.setExample("filter")}><a href="#">Filters Component Example</a></li> <li role="presentation" className={this.state.example === 'filter' ? 'active' : null} onClick={() => this.setExample("filter")}><a href="#">Filters Component Example</a></li>
<li role="presentation" className={this.state.example === 'floating-filter' ? 'active' : null} onClick={() => this.setExample("floating-filter")}><a href="#">Floating Filters</a></li>
<li role="presentation" className={this.state.example === 'master-detail' ? 'active' : null} onClick={() => this.setExample("master-detail")}><a href="#">Master Detail Example</a></li> <li role="presentation" className={this.state.example === 'master-detail' ? 'active' : null} onClick={() => this.setExample("master-detail")}><a href="#">Master Detail Example</a></li>
<li role="presentation" className={this.state.example === 'simple-redux' ? 'active' : null} onClick={() => this.setExample("simple-redux")}><a href="#">Simple Redux Example</a></li> <li role="presentation" className={this.state.example === 'simple-redux' ? 'active' : null} onClick={() => this.setExample("simple-redux")}><a href="#">Simple Redux Example</a></li>
<li role="presentation" className={this.state.example === 'simple-redux-dynamic' ? 'active' : null} onClick={() => this.setExample("simple-redux-dynamic")}><a href="#">Simple Redux Dynamic Component Example</a></li>
</ul>) </ul>)
} }
@@ -64,8 +68,8 @@ class App extends Component {
case 'editor': case 'editor':
example = <EditorComponentsExample/>; example = <EditorComponentsExample/>;
break; break;
case 'floating-row': case 'pinned-row':
example = <FloatingRowComponentExample/>; example = <PinnedRowComponentExample/>;
break; break;
case 'full-width': case 'full-width':
example = <FullWidthComponentExample/>; example = <FullWidthComponentExample/>;
@@ -82,6 +86,12 @@ class App extends Component {
case 'simple-redux': case 'simple-redux':
example = <SimpleReduxExample/>; example = <SimpleReduxExample/>;
break; break;
case 'floating-filter':
example = <FloatingFilterGridExample/>;
break;
case 'simple-redux-dynamic':
example = <SimpleReduxDynamicExample/>;
break;
default: default:
example = <RichGridExample/>; example = <RichGridExample/>;
} }

View File

@@ -18,9 +18,21 @@ export default class MoodEditor extends Component {
} }
componentDidMount() { componentDidMount() {
this.refs.container.addEventListener('keydown', this.checkAndToggleMoodIfLeftRight);
this.focus(); this.focus();
} }
componentWillUnmount() {
this.refs.container.removeEventListener('keydown', this.checkAndToggleMoodIfLeftRight);
}
checkAndToggleMoodIfLeftRight = (event) => {
if ([37, 39].indexOf(event.keyCode) > -1) { // left and right
this.toggleMood();
event.stopPropagation();
}
}
componentDidUpdate() { componentDidUpdate() {
this.focus(); this.focus();
} }
@@ -75,12 +87,11 @@ export default class MoodEditor extends Component {
background: "#e6e6e6", background: "#e6e6e6",
padding: 15, padding: 15,
textAlign: "center", textAlign: "center",
display: "inline-block", display: "inline-block"
// outline: "none"
}; };
let unselected = { let unselected = {
paddingLleft: 10, paddingLeft: 10,
paddingRight: 10, paddingRight: 10,
border: "1px solid transparent", border: "1px solid transparent",
padding: 4 padding: 4
@@ -93,12 +104,14 @@ export default class MoodEditor extends Component {
padding: 4 padding: 4
}; };
let happyStyle = this.state.value === 'Happy' ? selected : unselected; let happyStyle = this.state.happy ? selected : unselected;
let sadStyle = this.state.value !== 'Happy' ? selected : unselected; let sadStyle = !this.state.happy ? selected : unselected;
return ( return (
<div ref="container" <div ref="container"
style={mood}> style={mood}
tabIndex={1} // important - without this the keypresses wont be caught
>
<img src="images/smiley.png" onClick={this.onHappyClick} style={happyStyle}/> <img src="images/smiley.png" onClick={this.onHappyClick} style={happyStyle}/>
<img src="images/smiley-sad.png" onClick={this.onSadClick} style={sadStyle}/> <img src="images/smiley-sad.png" onClick={this.onSadClick} style={sadStyle}/>
</div> </div>

View File

@@ -16,6 +16,7 @@ export default class MoodEditor extends Component {
} }
componentDidMount() { componentDidMount() {
this.refs.input.addEventListener('keydown', this.onKeyDown);
this.focus(); this.focus();
} }
@@ -23,6 +24,10 @@ export default class MoodEditor extends Component {
this.focus(); this.focus();
} }
componentWillUnmount() {
this.refs.input.removeEventListener('keydown', this.onKeyDown);
}
focus() { focus() {
setTimeout(() => { setTimeout(() => {
let container = ReactDOM.findDOMNode(this.refs.input); let container = ReactDOM.findDOMNode(this.refs.input);
@@ -47,11 +52,20 @@ export default class MoodEditor extends Component {
}; };
onKeyDown(event) { onKeyDown(event) {
if(this.isLeftOrRight(event)) {
event.stopPropagation();
return;
}
if (!this.isKeyPressedNumeric(event)) { if (!this.isKeyPressedNumeric(event)) {
if (event.preventDefault) event.preventDefault(); if (event.preventDefault) event.preventDefault();
} }
} }
isLeftOrRight(event) {
return [37, 39].indexOf(event.keyCode) > -1;
}
handleChange(event) { handleChange(event) {
this.setState({value: event.target.value}); this.setState({value: event.target.value});
} }
@@ -75,7 +89,6 @@ export default class MoodEditor extends Component {
return ( return (
<input ref="input" <input ref="input"
value={this.state.value} value={this.state.value}
onKeyDown={this.onKeyDown}
onChange={this.handleChange} onChange={this.handleChange}
/> />
); );

View File

@@ -0,0 +1,69 @@
import React, {Component} from "react";
import {AgGridReact} from "ag-grid-react";
import FloatingFilter from "./floatingFilter";
import overrideStyle from "./floatingFilter.css";
export default class FloatingFilterGridExample extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: this.createColumnDefs(),
rowData: this.createRowData()
}
}
onGridReady(params) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
this.gridApi.sizeColumnsToFit();
}
createColumnDefs() {
return [
{
headerName: "Make",
field: "make",
floatingFilterComponentFramework: FloatingFilter,
filter: 'set'
},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"}
];
}
createRowData() {
return [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
}
render() {
let divStyle = {
height: 400,
width: 945
};
// combine the styles
const style = Object.assign({}, divStyle, overrideStyle);
return (
<div style={style} className="ag-fresh">
<h1>Floating Filter Example</h1>
<AgGridReact
// properties
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}
floatingFilter={true}
// events
onGridReady={this.onGridReady}>
</AgGridReact>
</div>
)
}
};

View File

@@ -0,0 +1,3 @@
.ag-floating-filter-button button {
margin: 0
}

View File

@@ -0,0 +1,39 @@
import React, {Component} from "react";
export default class FloatingFilter extends Component {
constructor(props) {
super(props);
this.state = {
parentModel: null
}
}
// when does this get called? how to test this?
onParentModelChanged(parentModel) {
this.setState({
parentModel: parentModel
})
}
remove(item) {
this.props.onFloatingFilterChanged({
model: this.state.parentModel.filter(it => it !== item)
});
}
render() {
if (!this.state.parentModel) return null;
// as the backing filter is a set filter what we're doing here is rendering the list in the set
// and when the [x] removing the selected item, thereby effectively hiding it
let options = this.state.parentModel.map((item, i) => {
let removeMeListener = () => {
this.remove(item)
};
let removeMeElement = <a onClick={removeMeListener}>[x]</a>;
return <span key={i}>{item}{removeMeElement}</span>;
});
return <div>{options}</div>;
}
}

View File

@@ -17,35 +17,34 @@
margin-right: 4px; margin-right: 4px;
} }
.align-right {
text-align: right
}
.customHeaderMenuButton { .customHeaderMenuButton {
margin-top: 5px;
margin-left: 4px; margin-left: 4px;
float: left; float: left;
} }
.customHeaderLabel { .customHeaderLabel {
margin-left: 5px; margin-left: 5px;
margin-top: 3px;
float: left; float: left;
} }
.customSortDownLabel { .customSortDownLabel {
float: left; float: left;
margin-left: 10px; margin-left: 10px;
margin-top: 5px;
} }
.customSortUpLabel { .customSortUpLabel {
float: left; float: left;
margin-left: 3px; margin-left: 3px;
margin-top: 4px;
} }
.customSortRemoveLabel { .customSortRemoveLabel {
float: left; float: left;
font-size: 11px; font-size: 11px;
margin-left: 3px; margin-left: 3px;
margin-top: 6px;
} }
.active { .active {
@@ -58,13 +57,11 @@
.customHeaderLabel { .customHeaderLabel {
margin-left: 5px; margin-left: 5px;
margin-top: 3px;
float: left; float: left;
} }
.customExpandButton { .customExpandButton {
float: right; float: right;
margin-top: 5px;
margin-left: 3px; margin-left: 3px;
} }
@@ -120,4 +117,4 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
</body> </body>
</html> </html>

View File

@@ -9,6 +9,10 @@ import "../node_modules/bootstrap/dist/css/bootstrap.css";
import App from "./App"; import App from "./App";
// only required when using enterprise features
// import {LicenseManager} from "ag-grid-enterprise/main";
// LicenseManager.setLicenseKey("<your license key>");
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
render( render(
<App/>, <App/>,

View File

@@ -3,7 +3,7 @@ import React, {Component} from "react";
import {AgGridReact} from "ag-grid-react"; import {AgGridReact} from "ag-grid-react";
import StyledRenderer from "./StyledRenderer"; import StyledRenderer from "./StyledRenderer";
export default class FloatingRowComponentExample extends Component { export default class PinnedRowComponentExample extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -13,8 +13,8 @@ export default class FloatingRowComponentExample extends Component {
rowData: this.createRowData(), rowData: this.createRowData(),
columnDefs: this.createColumnDefs(), columnDefs: this.createColumnDefs(),
topFloatingRowData: [{row: "Top Row", number: "Top Number"}], pinnedTopRowData: [{row: "Top Row", number: "Top Number"}],
bottomFloatingRowData: [{row: "Bottom Row", number: "Bottom Number"}] pinnedBottomRowData: [{row: "Bottom Row", number: "Bottom Number"}]
}; };
this.onGridReady = this.onGridReady.bind(this); this.onGridReady = this.onGridReady.bind(this);
@@ -33,8 +33,8 @@ export default class FloatingRowComponentExample extends Component {
headerName: "Row", headerName: "Row",
field: "row", field: "row",
width: 400, width: 400,
floatingCellRendererFramework: StyledRenderer, pinnedRowCellRendererFramework: StyledRenderer,
floatingCellRendererParams: { pinnedRowCellRendererParams: {
style: {'fontWeight': 'bold'} style: {'fontWeight': 'bold'}
} }
}, },
@@ -42,8 +42,8 @@ export default class FloatingRowComponentExample extends Component {
headerName: "Number", headerName: "Number",
field: "number", field: "number",
width: 399, width: 399,
floatingCellRendererFramework: StyledRenderer, pinnedRowCellRendererFramework: StyledRenderer,
floatingCellRendererParams: { pinnedRowCellRendererParams: {
style: {'fontStyle': 'italic'} style: {'fontStyle': 'italic'}
} }
}, },
@@ -67,14 +67,14 @@ export default class FloatingRowComponentExample extends Component {
return ( return (
<div style={{height: 400, width: 945}} <div style={{height: 400, width: 945}}
className="ag-fresh"> className="ag-fresh">
<h1>Floating Row Renderer Example</h1> <h1>Pinned Row Renderer Example</h1>
<AgGridReact <AgGridReact
// properties // properties
columnDefs={this.state.columnDefs} columnDefs={this.state.columnDefs}
rowData={this.state.rowData} rowData={this.state.rowData}
floatingTopRowData={this.state.topFloatingRowData} pinnedTopRowData={this.state.pinnedTopRowData}
floatingBottomRowData={this.state.bottomFloatingRowData} pinnedBottomRowData={this.state.pinnedBottomRowData}
// events // events
onGridReady={this.onGridReady}> onGridReady={this.onGridReady}>

View File

@@ -9,46 +9,80 @@ import HeaderGroupComponent from './HeaderGroupComponent.jsx';
export default class ColDefFactory { export default class ColDefFactory {
createColDefs() { createColDefs() {
return [
var columnDefs = [ {
{headerName: '#', width: 30, checkboxSelection: true, suppressSorting: true, headerName: '#',
suppressMenu: true, pinned: true}, width: 30,
checkboxSelection: true,
suppressSorting: true,
suppressMenu: true,
pinned: true
},
{ {
headerName: 'Employee', headerName: 'Employee',
headerGroupComponentFramework: HeaderGroupComponent, headerGroupComponentFramework: HeaderGroupComponent,
children: [ children: [
{ {
headerName: "Name", field: "name", enableRowGroup: true, enablePivot: true, headerName: "Name",
width: 150, pinned: true, editable: true, field: "name",
enableRowGroup: true,
enablePivot: true,
width: 150,
pinned: true,
editable: true,
// use a React cellEditor // use a React cellEditor
cellEditorFramework: NameCellEditor cellEditorFramework: NameCellEditor
}, { }, {
headerName: "Country", field: "country", width: 150, enableRowGroup: true, enablePivot: true, headerName: "Country",
field: "country",
width: 150,
enableRowGroup: true,
enablePivot: true,
// an example of using a non-React cell renderer // an example of using a non-React cell renderer
cellRenderer: countryCellRenderer, pinned: true, cellRenderer: countryCellRenderer,
pinned: true,
filterParams: { filterParams: {
cellRenderer: countryCellRenderer, cellHeight: 20 cellRenderer: countryCellRenderer,
}, columnGroupShow: 'open' cellHeight: 20
},
columnGroupShow: 'open'
}, { }, {
headerName: "DOB", field: "dob", width: 110, enableRowGroup: true, enablePivot: true, filter:'date', headerName: "DOB",
pinned: true, cellRenderer: function(params) { field: "dob",
return pad(params.value.getDate(), 2) + '/' + width: 110,
pad(params.value.getMonth() + 1, 2)+ '/' + enableRowGroup: true,
params.value.getFullYear(); enablePivot: true,
}, columnGroupShow: 'open' filter: 'date',
pinned: true,
cellRenderer: function (params) {
return pad(params.value.getDate(), 2) + '/' +
pad(params.value.getMonth() + 1, 2) + '/' +
params.value.getFullYear();
},
columnGroupShow: 'open'
} }
] ]
}, },
{ {
headerName: 'IT Skills', headerName: 'IT Skills',
children: [ children: [
{headerName: "Skills", width: 125, suppressSorting: true, field: 'skills', enableRowGroup: true, enablePivot: true, {
headerName: "Skills",
width: 125,
suppressSorting: true,
field: 'skills',
enableRowGroup: true,
enablePivot: true,
// supply a React component // supply a React component
cellRendererFramework: SkillsCellRenderer, cellRendererFramework: SkillsCellRenderer,
// supply a React component // supply a React component
filterFramework: SkillsFilter filterFramework: SkillsFilter
}, },
{headerName: "Proficiency", field: "proficiency", width: 135, enableValue: true, {
headerName: "Proficiency",
field: "proficiency",
width: 135,
enableValue: true,
// supply a React component // supply a React component
cellRendererFramework: ProficiencyCellRenderer, cellRendererFramework: ProficiencyCellRenderer,
// supply a React component // supply a React component
@@ -65,7 +99,6 @@ export default class ColDefFactory {
] ]
} }
]; ];
return columnDefs;
} }
} }
@@ -73,7 +106,7 @@ export default class ColDefFactory {
// need to use React for it. // need to use React for it.
function countryCellRenderer(params) { function countryCellRenderer(params) {
if (params.value) { if (params.value) {
var flag = "<img border='0' width='15' height='10' " + const flag = "<img border='0' width='15' height='10' " +
"style='margin-bottom: 2px' src='http://flags.fmcdn.net/data/flags/mini/" "style='margin-bottom: 2px' src='http://flags.fmcdn.net/data/flags/mini/"
+ RefData.COUNTRY_CODES[params.value] + ".png'>"; + RefData.COUNTRY_CODES[params.value] + ".png'>";
return flag + " " + params.value; return flag + " " + params.value;

View File

@@ -6,7 +6,6 @@ import DateComponent from "./DateComponent.jsx";
import SortableHeaderComponent from "./SortableHeaderComponent"; import SortableHeaderComponent from "./SortableHeaderComponent";
import "./RichGridExample.css"; import "./RichGridExample.css";
// take this line out if you do not want to use ag-Grid-Enterprise // take this line out if you do not want to use ag-Grid-Enterprise
import "ag-grid-enterprise"; import "ag-grid-enterprise";
@@ -29,7 +28,10 @@ export default class RichGridExample extends Component {
groupExpanded: '<i class="fa fa-minus-square-o"/>', groupExpanded: '<i class="fa fa-minus-square-o"/>',
groupContracted: '<i class="fa fa-plus-square-o"/>', groupContracted: '<i class="fa fa-plus-square-o"/>',
columnGroupOpened: '<i class="fa fa-minus-square-o"/>', columnGroupOpened: '<i class="fa fa-minus-square-o"/>',
columnGroupClosed: '<i class="fa fa-plus-square-o"/>' columnGroupClosed: '<i class="fa fa-plus-square-o"/>',
checkboxChecked: '<i class="fa fa-arrow-left"/>',
checkboxUnchecked: '<i class="fa fa-arrow-right"/>',
checkboxIndeterminate: '<i class="fa fa-arrow-up"/>'
} }
}; };
@@ -76,10 +78,6 @@ export default class RichGridExample extends Component {
this.columnApi = params.columnApi; this.columnApi = params.columnApi;
} }
selectAll() {
this.api.selectAll();
}
deselectAll() { deselectAll() {
this.api.deselectAll(); this.api.deselectAll();
} }
@@ -123,7 +121,7 @@ export default class RichGridExample extends Component {
// simply wait for the next tick // simply wait for the next tick
setTimeout(() => { setTimeout(() => {
this.gridOptions.api.onFilterChanged(); this.gridOptions.api.onFilterChanged();
},0) }, 0)
} }
render() { render() {
@@ -156,7 +154,10 @@ export default class RichGridExample extends Component {
<div style={{padding: 4}} className={'toolbar'}> <div style={{padding: 4}} className={'toolbar'}>
<span> <span>
Grid API: Grid API:
<button onClick={this.selectAll.bind(this)}>Select All</button> {/* use ref to access the api in selectAll */}
<button onClick={() => {
this.refs.myGrid.api.selectAll()
}}>Select All</button>
<button onClick={this.deselectAll.bind(this)}>Clear Selection</button> <button onClick={this.deselectAll.bind(this)}>Clear Selection</button>
</span> </span>
<span style={{marginLeft: 20}}> <span style={{marginLeft: 20}}>
@@ -186,6 +187,7 @@ export default class RichGridExample extends Component {
gridTemplate = ( gridTemplate = (
<div style={{height: 400, width: 945}} className="ag-fresh"> <div style={{height: 400, width: 945}} className="ag-fresh">
<AgGridReact <AgGridReact
ref="myGrid"
// gridOptions is optional - it's possible to provide // gridOptions is optional - it's possible to provide
// all values as React props // all values as React props
gridOptions={this.gridOptions} gridOptions={this.gridOptions}

View File

@@ -7,7 +7,8 @@ export default class SortableHeaderComponent extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.props.column.addEventListener('sortChanged', this.onSortChanged.bind(this)); // this.sortChanged = this.onSortChanged.bind(this);
this.props.column.addEventListener('sortChanged', this.onSortChanged);
//The state of this component contains the current sort state of this column //The state of this component contains the current sort state of this column
//The possible values are: 'asc', 'desc' and '' //The possible values are: 'asc', 'desc' and ''
@@ -16,6 +17,9 @@ export default class SortableHeaderComponent extends React.Component {
} }
} }
componentWillUnmount() {
this.props.column.removeEventListener('sortChanged', this.onSortChanged);
}
render() { render() {
let sortElements = []; let sortElements = [];
@@ -51,7 +55,7 @@ export default class SortableHeaderComponent extends React.Component {
this.props.setSort(order, event.shiftKey); this.props.setSort(order, event.shiftKey);
}; };
onSortChanged() { onSortChanged = () => {
if (this.props.column.isSortAscending()) { if (this.props.column.isSortAscending()) {
this.setState({ this.setState({
sorted: 'asc' sorted: 'asc'

View File

@@ -0,0 +1,57 @@
import React, {Component} from "react";
import {AgGridReact} from "ag-grid-react";
import {connect} from "react-redux";
import PriceRenderer from "./PriceRenderer";
/*
* This component serves to display the row data (provided by redux)
*/
class GridComponent extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{headerName: 'Symbol', field: 'symbol'},
{headerName: 'Price', field: 'price', cellClass: 'align-right', cellRendererFramework: PriceRenderer}
]
};
this.onGridReady = this.onGridReady.bind(this);
}
onGridReady(params) {
this.gridApi = params.api;
this.columnApi = params.columnApi;
this.gridApi.sizeColumnsToFit();
}
// row data will be provided via redux on this.props.rowData
render() {
return (
<div style={{height: 400, width: 945, marginTop: 15}}
className="ag-fresh">
<AgGridReact
// properties
columnDefs={this.state.columnDefs}
rowData={this.props.rowData}
// events
onGridReady={this.onGridReady}>
</AgGridReact>
</div>
)
}
}
// pull off row data changes
export default connect(
(state) => {
return {
rowData: state.rowData
}
}
)(GridComponent);

View File

@@ -0,0 +1,85 @@
import React, {Component} from "react";
import {connect} from "react-redux";
// take this line out if you do not want to use ag-Grid-Enterprise
import "ag-grid-enterprise";
import {setCurrency, updateRowData} from "./gridDataActions";
/*
* This component serves both to host the demo controls, which in turn will drive row data state changes
*/
class HeaderComponent extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
// provide the initial data to the store (which in turn will populate the grid)
this.props.dispatch(updateRowData(this.createRowData()));
}
setCurrency(currencySymbol, exchangeRate) {
this.props.dispatch(setCurrency(currencySymbol, exchangeRate));
}
render() {
return (
<div style={{marginTop: 15}}>
<button onClick={this.setCurrency.bind(this, '£', 1)}>Set Currency to GBP</button>
<button onClick={this.setCurrency.bind(this, '$', 1.29)}>Set Currency to USD</button>
</div>
)
}
// the following methods are for creating dummy row data
createRowData() {
let rowData = [];
for (let i = 0; i < 14; i++) {
let newItem = this.createItem();
rowData.push(newItem);
}
return rowData;
}
createItem() {
return {
symbol: this.createUniqueRandomSymbol(),
price: Math.floor(Math.random() * 100)
};
}
// creates a unique symbol, eg 'ADG' or 'ZJD'
createUniqueRandomSymbol() {
let symbol;
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let isUnique = false;
while (!isUnique) {
symbol = '';
// create symbol
for (let i = 0; i < 3; i++) {
symbol += possible.charAt(Math.floor(Math.random() * possible.length));
}
// check uniqueness
isUnique = true;
this.props.rowData.forEach(function (oldItem) {
if (oldItem.symbol === symbol) {
isUnique = false;
}
});
}
return symbol;
}
}
// pull off row data
export default connect(
(state) => {
return {
rowData: state.rowData
}
}
)(HeaderComponent);

View File

@@ -0,0 +1,37 @@
import React, {Component} from "react";
import {connect} from "react-redux";
class PriceRenderer extends Component {
constructor(props) {
super(props);
this.state = {
convertedValue: this.applyExchangeRate(props.exchangeRate, props.value)
};
}
componentWillReceiveProps(nextProps) {
this.setState({
convertedValue: this.applyExchangeRate(nextProps.exchangeRate, nextProps.value)
})
}
render() {
return (
<span>{this.props.currencySymbol}{this.state.convertedValue}</span>
);
}
applyExchangeRate = (exchangeRate, value) => {
return parseFloat(value * exchangeRate).toFixed(2); // simplified/naive exchange rate implementation!
}
}
export default connect(
(state) => {
return {
currencySymbol: state.currencySymbol,
exchangeRate: state.exchangeRate
}
}
)(PriceRenderer);

View File

@@ -0,0 +1,34 @@
import React, {Component} from "react";
import {Provider} from "react-redux";
import {createStore} from "redux";
// take this line out if you do not want to use ag-Grid-Enterprise
import "ag-grid-enterprise";
import HeaderComponent from "./HeaderComponent";
import GridComponent from "./GridComponent";
import gridData from "./gridDataReducer";
let store = createStore(gridData);
/*
* This component serves as a container for both the header and grid components. It's primarily here to act as a container
* for the redux Provider
*/
export default class SimpleReduxExample extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Provider store={store}>
<div>
<h1>Simple Redux Example using Connected React Components</h1>
<HeaderComponent />
<GridComponent />
</div>
</Provider>
)
}
};

View File

@@ -0,0 +1,13 @@
export function updateRowData(rowData) {
return {
type: 'ROW_DATA_CHANGED',
rowData
}
}
export function setCurrency(currencySymbol, exchangeRate) {
return {
type: 'CURRENCY_CHANGED',
currencySymbol,
exchangeRate
}
}

View File

@@ -0,0 +1,17 @@
export default (state = {rowData: [], currencySymbol: '£', exchangeRate: 1}, action) => {
switch (action.type) {
case 'ROW_DATA_CHANGED':
return {
...state,
rowData: action.rowData,
};
case 'CURRENCY_CHANGED':
return {
...state,
currencySymbol: action.currencySymbol,
exchangeRate: action.exchangeRate
};
default:
return state;
}
};