diff --git a/package.json b/package.json index 6cc1d38..df452f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ag-grid-react-example", - "version": "20.0.0", + "version": "20.1.0", "description": "Example Reach applicaiton using ag-Grid.", "main": "dist/ag-grid-react-example.js", "scripts": { @@ -37,35 +37,35 @@ }, "homepage": "http://www.ag-grid.com/", "devDependencies": { - "@babel/core": "7.2.2", - "babel-loader": "8.0.4", - "@babel/preset-env": "7.2.3", + "@babel/core": "7.3.3", + "babel-loader": "8.0.5", + "@babel/preset-env": "7.3.1", "@babel/preset-react": "7.0.0", - "@babel/plugin-proposal-class-properties": "7.2.3", + "@babel/plugin-proposal-class-properties": "7.3.3", "@babel/plugin-proposal-function-bind": "7.2.0", "css-loader": "2.1.0", "file-loader": "3.0.1", "gulp": "3.9.1", - "merge2": "^1.2.3", + "merge2": "1.2.3", "mkdirp": "0.5.1", "ncp": "2.0.0", - "prop-types": "15.6.2", - "rimraf": "~2.6.2", - "style-loader": "~0.23.0", - "webpack": "4.28.3", - "webpack-cli": "3.2.0", - "webpack-dev-server": "3.1.14" + "prop-types": "15.7.2", + "rimraf": "2.6.3", + "style-loader": "0.23.1", + "webpack": "4.29.5", + "webpack-cli": "3.2.3", + "webpack-dev-server": "3.2.0" }, "dependencies": { - "ag-grid-community": "^20.0.0", - "ag-grid-enterprise": "^20.0.0", - "ag-grid-react": "^20.0.0", - "bootstrap": "4.1.3", + "ag-grid-community": "^20.1.0", + "ag-grid-enterprise": "^20.1.0", + "ag-grid-react": "^20.1.0", + "bootstrap": "4.3.1", "d3": "4.9.1", - "lodash": "^4.17.11", - "react": "16.7.0", - "react-dom": "16.7.0", - "react-redux": "6.0.0", + "lodash": "4.17.11", + "react": "16.8.2", + "react-dom": "16.8.2", + "react-redux": "6.0.1", "react-router-dom": "4.3.1", "redux": "4.0.1" } diff --git a/src-examples/App.jsx b/src-examples/App.jsx index c6cc744..812c66d 100644 --- a/src-examples/App.jsx +++ b/src-examples/App.jsx @@ -5,12 +5,14 @@ import NavItem from "./NavItem"; import RichGridDeclarativeExample from "./richGridDeclarativeExample/RichGridDeclarativeExample"; import SimpleReduxDynamicExample from "./simpleReduxDynamicComponentExample/SimpleReduxExample"; +import SimpleReduxHookExample from "./simpleReduxHooksExample/SimpleReduxHookExample"; const SideBar = () => (
); @@ -25,6 +27,7 @@ class App extends Component { + diff --git a/src-examples/richGridDeclarativeExample/RichGridDeclarativeExample.jsx b/src-examples/richGridDeclarativeExample/RichGridDeclarativeExample.jsx index ff581a4..8b011f2 100644 --- a/src-examples/richGridDeclarativeExample/RichGridDeclarativeExample.jsx +++ b/src-examples/richGridDeclarativeExample/RichGridDeclarativeExample.jsx @@ -141,17 +141,8 @@ export default class RichGridDeclarativeExample extends Component {
- -
-
-
- -
Filter API:
+
+
+ +
+
+ +
+
{ + params.api.sizeColumnsToFit(); + }; + + // row data will be provided via redux on this.props.rowData + return ( +
+ + +
+ ) +} diff --git a/src-examples/simpleReduxHooksExample/PriceRenderer.jsx b/src-examples/simpleReduxHooksExample/PriceRenderer.jsx new file mode 100644 index 0000000..8e60e1c --- /dev/null +++ b/src-examples/simpleReduxHooksExample/PriceRenderer.jsx @@ -0,0 +1,13 @@ +import React, {Component} from "react"; + +export default class PriceRenderer extends Component { + constructor(props) { + super(props); + } + + render() { + return ( + {this.props.value} + ); + } +} diff --git a/src-examples/simpleReduxHooksExample/SimpleReduxHookExample.jsx b/src-examples/simpleReduxHooksExample/SimpleReduxHookExample.jsx new file mode 100644 index 0000000..45d157d --- /dev/null +++ b/src-examples/simpleReduxHooksExample/SimpleReduxHookExample.jsx @@ -0,0 +1,18 @@ +import React, {useReducer} from "react"; +import GridComponent from "./GridComponent"; + +import {Context, initialState, reducer} from "./store"; + +export default function SimpleReduxHookExample() { + const [store, dispatch] = useReducer(reducer, initialState); + + return ( + +
+

Simple Example using Hooks (with useContext and useReducer)

+ + +
+
+ ) +} diff --git a/src-examples/simpleReduxHooksExample/gridDataActions.jsx b/src-examples/simpleReduxHooksExample/gridDataActions.jsx new file mode 100644 index 0000000..c955838 --- /dev/null +++ b/src-examples/simpleReduxHooksExample/gridDataActions.jsx @@ -0,0 +1,14 @@ +export function updateRowData(rowData) { + return { + type: 'ROW_DATA_CHANGED', + rowData + } +} + +export function setCurrency(currencySymbol, exchangeRate) { + return { + type: 'CURRENCY_CHANGED', + currencySymbol, + exchangeRate + } +} \ No newline at end of file diff --git a/src-examples/simpleReduxHooksExample/store.js b/src-examples/simpleReduxHooksExample/store.js new file mode 100644 index 0000000..da862a6 --- /dev/null +++ b/src-examples/simpleReduxHooksExample/store.js @@ -0,0 +1,75 @@ +import React from "react"; +import PriceRenderer from "./PriceRenderer"; + +export const initialState = { + rowData: [], + columnDefs: [ + { + field: 'symbol' + }, + { + field: 'price', + cellClass: 'align-right', + cellRendererFramework: PriceRenderer + } + ] +}; + +export const reducer = (state = {rowData: []}, action) => { + switch (action.type) { + case 'SET_ROW_DATA': + return { + ...state, + rowData: createRowData() + }; + default: + return state; + } +}; + +export const Context = React.createContext(); + + +// for test data +// the following methods are for creating dummy row data +const createRowData = () => { + let rowData = []; + + for (let i = 0; i < 14; i++) { + let newItem = createItem(rowData); + rowData.push(newItem); + } + + return rowData; +}; + +const createItem = (rowData) => { + return { + symbol: createUniqueRandomSymbol(rowData), + price: Math.floor(Math.random() * 100) + }; +}; + +// creates a unique symbol, eg 'ADG' or 'ZJD' +const createUniqueRandomSymbol = (rowData) => { + 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; + rowData.forEach(function (oldItem) { + if (oldItem.symbol === symbol) { + isUnique = false; + } + }); + } + + return symbol; +};