Compare commits

...

25 Commits
7.3.0 ... 9.1.0

Author SHA1 Message Date
Alberto
575edb5b85 Release 9.1.0 2017-04-27 15:18:12 +02:00
Alberto
042dfc62a6 Merge branch '9.0.0' 2017-03-29 17:13:06 +01:00
Alberto
d59b5e8071 Version 9.0.0 2017-03-29 17:11:37 +01:00
Alberto
afa03227e4 Full width renderer with react 2017-03-09 11:03:20 +01:00
Alberto
a2952230d0 Starting work of full width Renderer with React 2017-03-08 16:46:50 +01:00
Alberto
7f8d1bb3a7 Starting work of full width Renderer with React 2017-03-08 16:36:05 +01:00
Alberto
801bf16339 Merge branch '8.2.0' 2017-03-08 15:12:51 +01:00
Alberto
cf1be920ee Release 8.2.0 2017-03-08 14:43:47 +01:00
Sean Landsman
f8ad31c2e0 more docs work 2017-02-24 15:09:48 +00:00
Alberto
e026fb65e3 Merge branch '8.1.0' 2017-02-20 13:11:50 +00:00
Alberto
05a7371467 8.1.0 2017-02-20 12:49:05 +00:00
Alberto
4ea0b7f8b2 Merge branch '8.0.0' 2017-02-09 15:48:33 +00:00
Alberto
5904f47d55 8.0.0 2017-02-09 14:14:07 +00:00
Alberto
25b416b71d Getting ready for releasing 8.0.0 2017-02-09 13:59:26 +00:00
Alberto
abb7828921 Getting ready for releasing 8.0.0 2017-02-09 13:58:19 +00:00
Alberto
ad5fd2d1ce ag-49 Ng2 Header component 2017-02-07 10:00:52 +00:00
Alberto
6d686f1c02 ag-49 Custom Group Header example completed 2017-02-03 11:16:17 +00:00
Alberto
6376a24e3a ag-49 Custom Header example completed 2017-02-03 10:14:20 +00:00
Sean Landsman
9c8cf08d2a AG-195 Create react example using grouped data 2017-01-26 11:40:46 +00:00
Alberto
a8c70c0ae8 Adding the cellRenderer so the example and updating the docs to reflect the example changes 2017-01-23 14:58:26 +00:00
Alberto
3390411e8a React date component, polishing the UI and adding documentation 2017-01-23 12:30:15 +00:00
Alberto
a280e97763 Creating React component to manage the dates in the DateFilter 2017-01-20 15:58:01 +00:00
Alberto
5451b02acd Creating the scaffolding for the ag-grid-react DateComponent 2017-01-20 15:29:42 +00:00
Alberto
3613a26f48 Creating the scaffolding for the ag-grid-react DateComponent 2017-01-20 14:47:11 +00:00
Sean Landsman
4acdee4b72 AG-24 Add getFilterInstance to React Examples Project 2017-01-19 10:58:32 +00:00
20 changed files with 9724 additions and 25 deletions

View File

@@ -16,6 +16,105 @@
margin-left: 4px;
margin-right: 4px;
}
.customHeaderMenuButton{
margin-top: 5px;
margin-left: 4px;
float: left;
}
.customHeaderLabel{
margin-left: 5px;
margin-top: 3px;
float: left;
}
.customSortDownLabel{
float: left;
margin-left: 10px;
margin-top: 5px;
}
.customSortUpLabel{
float: left;
margin-left: 3px;
margin-top: 4px;
}
.customSortRemoveLabel{
float: left;
font-size: 11px;
margin-left: 3px;
margin-top: 6px;
}
.active {
color: cornflowerblue;
}
.hidden { display:none; }
.customHeaderLabel{
margin-left: 5px;
margin-top: 3px;
float: left;
}
.customExpandButton{
float:right;
margin-top: 5px;
margin-left: 3px;
}
.expanded {
animation-name: toExpanded;
animation-duration: 1s;
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
.collapsed {
color: cornflowerblue;
animation-name: toCollapsed;
animation-duration: 1s;
-ms-transform: rotate(0deg); /* IE 9 */
-webkit-transform: rotate(0deg); /* Chrome, Safari, Opera */
transform: rotate(0deg);
}
@keyframes toExpanded{
from {
color: cornflowerblue;
-ms-transform: rotate(0deg); /* IE 9 */
-webkit-transform: rotate(0deg); /* Chrome, Safari, Opera */
transform: rotate(0deg);
}
to {
color: black;
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
}
@keyframes toCollapsed{
from {
color: black;
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
to {
color: cornflowerblue;
-ms-transform: rotate(0deg); /* IE 9 */
-webkit-transform: rotate(0deg); /* Chrome, Safari, Opera */
transform: rotate(0deg);
}
}
</style>
<body>

8618
olympicWinners.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,15 @@
{
"name": "ag-grid-react-example",
"version": "7.2.0",
"version": "9.1.0",
"description": "Example Reach applicaiton using ag-Grid.",
"main": "dist/ag-grid-react-example.js",
"scripts": {
"full-width": "webpack-dev-server --config webpack.config.full-width.js --progress --colors --hot --inline",
"standard": "webpack-dev-server --config webpack.config.standard.js --progress --colors --hot --inline",
"large": "webpack-dev-server --config webpack.config.large.js --progress --colors --hot --inline"
"grouped": "webpack-dev-server --config webpack.config.grouped.js --progress --colors --hot --inline",
"large": "webpack-dev-server --config webpack.config.large.js --progress --colors --hot --inline",
"clean": "rimraf dist",
"build-standard": "npm run clean && webpack --config webpack.config.standard.js --progress --profile --bail"
},
"repository": {
"type": "git",
@@ -34,10 +38,13 @@
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"rimraf": "2.5.x",
"react": "0.14.6",
"react-dom": "0.14.6",
"ag-grid": "7.2.x",
"ag-grid-enterprise": "7.2.x",
"ag-grid-react": "7.2.x"
"ag-grid": "9.1.x",
"ag-grid-enterprise": "9.1.x",
"ag-grid-react": "9.1.x"
}
}

18
src-full-width/index.js Normal file
View File

@@ -0,0 +1,18 @@
'use strict';
import ReactDOM from 'react-dom';
import React from 'react';
import MyApp from './myApp.jsx';
// is there a better way of doing this?
import 'ag-grid-root/dist/styles/ag-grid.css';
import 'ag-grid-root/dist/styles/theme-fresh.css';
// waiting for dom to load before booting react. we could alternatively
// put the index.js reference at the end fo the index.html, but i prefer this way.
document.addEventListener('DOMContentLoaded', ()=> {
var container = document.getElementById('myAppContainer');
ReactDOM.render(
React.createElement(MyApp),
container
);
});

28
src-full-width/myApp.css Normal file
View File

@@ -0,0 +1,28 @@
.ag-cell {
padding-top: 2px !important;
padding-bottom: 2px !important;
}
label {
font-weight: normal !important;
}
.div-percent-bar {
display: inline-block;
height: 20px;
position: relative;
}
.div-percent-value {
position: absolute;
padding-left: 4px;
font-weight: bold;
font-size: 13px;
}
.div-outer-div {
display: inline-block;
height: 100%;
width: 100%;
}

356
src-full-width/myApp.jsx Normal file
View File

@@ -0,0 +1,356 @@
import React from "react";
import {AgGridReact} from "ag-grid-react";
import "./myApp.css";
import "ag-grid-enterprise";
export class DetailPanelCellRenderer extends React.Component{
render (){
return <div><div class="full-width-panel">
<div class="full-width-details">
<div class="full-width-detail"><b>Name: </b>+parentRecord.name+</div>
<div class="full-width-detail"><b>Account: </b>+parentRecord.account+</div>
</div>
<div class="full-width-grid"></div>
<div class="full-width-grid-toolbar">
<img class="full-width-phone-icon" src="https://www.ag-grid.com/images/phone.png"/>
<button><img src="https://www.ag-grid.com/images/fire.png"/></button>
<button><img src="https://www.ag-grid.com/images/frost.png"/></button>
<button><img src="https://www.ag-grid.com/images/sun.png"/></button>
<input class="full-width-search" placeholder="Search..."/>
</div>
</div></div>;
}
}
// take this line out if you do not want to use ag-Grid-Enterprise
// a list of names we pick from when generating data
var firstnames = ['Sophia','Emma','Olivia','Isabella','Mia','Ava','Lily','Zoe','Emily','Chloe','Layla','Madison','Madelyn','Abigail','Aubrey','Charlotte','Amelia','Ella','Kaylee','Avery','Aaliyah','Hailey','Hannah','Addison','Riley','Harper','Aria','Arianna','Mackenzie','Lila','Evelyn','Adalyn','Grace','Brooklyn','Ellie','Anna','Kaitlyn','Isabelle','Sophie','Scarlett','Natalie','Leah','Sarah','Nora','Mila','Elizabeth','Lillian','Kylie','Audrey','Lucy','Maya'];
var lastnames = ['Smith','Jones','Williams','Taylor','Brown','Davies','Evans','Wilson','Thomas','Johnson'];
var images = ['niall','sean','alberto','statue','horse'];
// each call gets a unique id, nothing to do with the grid, just help make the sample
// data more realistic
var callIdSequence = 555;
// method creates all the data, both the top level grid and the lower level grids
function createRowData() {
var rowData = [];
for (var i = 0; i < 20; i++) {
var firstName = firstnames[Math.floor(Math.random()*firstnames.length)];
var lastName = lastnames[Math.floor(Math.random()*lastnames.length)];
var image = images[i % images.length];
var totalDuration = 0;
var callRecords = [];
// call count is random number between 20 and 120
var callCount = Math.floor(Math.random() * 100) + 20;
for (var j = 0; j<callCount; j++) {
// duration is random number between 20 and 120
var callDuration = Math.floor(Math.random() * 100) + 20;
var callRecord = {
callId: callIdSequence++,
duration: callDuration,
switchCode: 'SW' + Math.floor(Math.random() * 10),
// 50% chance of in vs out
direction: (Math.random()>.5) ? 'In' : 'Out',
// made up number
number: '(0' + Math.floor(Math.random() * 10) + ') ' + Math.floor(Math.random() * 100000000)
};
callRecords.push(callRecord);
totalDuration += callDuration;
}
var record = {
name: firstName + ' ' + lastName,
account: i + 177000,
totalCalls: callCount,
image: image,
// convert from seconds to minutes
totalMinutes: totalDuration / 60,
callRecords: callRecords
};
rowData.push(record);
}
return rowData;
}
var minuteCellFormatter = function (params) {
return params.value.toLocaleString() + 'm';
};
var secondCellFormatter= function (params) {
return params.value.toLocaleString() + 's';
};
var masterColumnDefs = [
{headerName: 'Name', field: 'name',
// left column is going to act as group column, with the expand / contract controls
cellRenderer: 'group',
// we don't want the child count - it would be one each time anyway as each parent
// not has exactly one child node
cellRendererParams: { suppressCount: true }
},
{headerName: 'Account', field: 'account'},
{headerName: 'Calls', field: 'totalCalls'},
{headerName: 'Minutes', field: 'totalMinutes', cellFormatter: minuteCellFormatter}
];
var detailColumnDefs = [
{headerName: 'Call ID', field: 'callId', cellClass: 'call-record-cell'},
{headerName: 'Direction', field: 'direction', cellClass: 'call-record-cell'},
{headerName: 'Number', field: 'number', cellClass: 'call-record-cell'},
{headerName: 'Duration', field: 'duration', cellClass: 'call-record-cell', cellFormatter: secondCellFormatter},
{headerName: 'Switch', field: 'switchCode', cellClass: 'call-record-cell'}
];
var rowData = createRowData();
export default class MyApp extends React.Component {
constructor() {
super();
this.state = {
quickFilterText: null,
showGrid: true,
showToolPanel: false,
icons: {
columnRemoveFromGroup: '<i class="fa fa-remove"/>',
filter: '<i class="fa fa-filter"/>',
sortAscending: '<i class="fa fa-long-arrow-down"/>',
sortDescending: '<i class="fa fa-long-arrow-up"/>',
groupExpanded: '<i class="fa fa-minus-square-o"/>',
groupContracted: '<i class="fa fa-plus-square-o"/>',
columnGroupOpened: '<i class="fa fa-minus-square-o"/>',
columnGroupClosed: '<i class="fa fa-plus-square-o"/>'
}
};
// the grid options are optional, because you can provide every property
// to the grid via standard React properties. however, the react interface
// doesn't block you from using the standard JavaScript interface if you
// wish. Maybe you have the gridOptions stored as JSON on your server? If
// you do, the providing the gridOptions as a standalone object is just
// what you want!
this.gridOptions = {
columnDefs: masterColumnDefs,
rowData: rowData,
//We register the react date component that ag-grid will use to render
// this is how you listen for events using gridOptions
onModelUpdated: function () {
console.log('event onModelUpdated received');
},
defaultColDef : {
headerComponentParams : {
menuIcon: 'fa-bars'
}
},
// this is a simple property
rowBuffer: 10 // no need to set this, the default is fine for almost all scenarios
};
}
onShowGrid(show) {
this.setState({
showGrid: show
});
}
onToggleToolPanel(event) {
this.setState({showToolPanel: event.target.checked});
}
onGridReady(params) {
this.api = params.api;
this.columnApi = params.columnApi;
params.api.sizeColumnsToFit();
}
selectAll() {
this.api.selectAll();
}
deselectAll() {
this.api.deselectAll();
}
setCountryVisible(visible) {
this.columnApi.setColumnVisible('country', visible);
}
onQuickFilterText(event) {
this.setState({quickFilterText: event.target.value});
}
onCellClicked(event) {
console.log('onCellClicked: ' + event.data.name + ', col ' + event.colIndex);
}
onRowSelected(event) {
console.log('onRowSelected: ' + event.node.data.name);
}
onRefreshData() {
var newRowData = new RowDataFactory().createRowData();
this.setState({
rowData: newRowData
});
}
invokeSkillsFilterMethod() {
var skillsFilter = this.api.getFilterInstance('skills');
var componentInstance = skillsFilter.getFrameworkComponentInstance();
componentInstance.helloFromSkillsFilter();
}
dobFilter () {
let dateFilterComponent = this.gridOptions.api.getFilterInstance('dob');
dateFilterComponent.setFilterType('equals');
dateFilterComponent.setDateFrom('2000-01-01');
this.gridOptions.api.onFilterChanged();
}
onIsFullWidthCell (rowNode) {
return rowNode.level === 1;
}
onGetRowHeight (params) {
var rowIsDetailRow = params.node.level===1;
// return 100 when detail row, otherwise return 25
return rowIsDetailRow ? 75 : 25;
}
onGetNodeChildDetails (record) {
if (record.callRecords) {
return {
group: true,
// the key is used by the default group cellRenderer
key: record.name,
// provide ag-Grid with the children of this group
children: [record.callRecords],
// for demo, expand the third row by default
expanded: record.account === 177005
};
} else {
return null;
}
}
render() {
var gridTemplate;
var bottomHeaderTemplate;
var topHeaderTemplate;
topHeaderTemplate = (
<div>
<div style={{float: 'right'}}>
<input type="text" onChange={this.onQuickFilterText.bind(this)}
placeholder="Type text to filter..."/>
<button id="btDestroyGrid" disabled={!this.state.showGrid}
onClick={this.onShowGrid.bind(this, false)}>Destroy Grid
</button>
<button id="btCreateGrid" disabled={this.state.showGrid} onClick={this.onShowGrid.bind(this, true)}>
Create Grid
</button>
</div>
<div style={{padding: '4px'}}>
<b>Employees Skills and Contact Details</b> <span id="rowCount"/>
</div>
</div>
);
// showing the bottom header and grid is optional, so we put in a switch
if (this.state.showGrid) {
bottomHeaderTemplate = (
<div>
<div style={{padding: 4}} className={'toolbar'}>
<span>
Grid API:
<button onClick={this.selectAll.bind(this)}>Select All</button>
<button onClick={this.deselectAll.bind(this)}>Clear Selection</button>
</span>
<span style={{marginLeft: 20}}>
Column API:
<button onClick={this.setCountryVisible.bind(this, false)}>Hide Country Column</button>
<button onClick={this.setCountryVisible.bind(this, true)}>Show Country Column</button>
</span>
</div>
<div style={{clear: 'both'}}></div>
<div style={{padding: 4}} className={'toolbar'}>
<span>
<label>
<input type="checkbox" onChange={this.onToggleToolPanel.bind(this)}/>
Show Tool Panel
</label>
<button onClick={this.onRefreshData.bind(this)}>Refresh Data</button>
</span>
<span style={{marginLeft: 20}}>
Filter API:
<button onClick={this.invokeSkillsFilterMethod.bind(this, false)}>Invoke Skills Filter Method</button>
<button onClick={this.dobFilter.bind(this)}>DOB equals to 01/01/2000</button>
</span>
</div>
<div style={{clear: 'both'}}></div>
</div>
);
gridTemplate = (
<div style={{height: 400}} className="ag-fresh">
<AgGridReact
// gridOptions is optional - it's possible to provide
// all values as React props
gridOptions={this.gridOptions}
// listening for events
onGridReady={this.onGridReady.bind(this)}
onRowSelected={this.onRowSelected.bind(this)}
onCellClicked={this.onCellClicked.bind(this)}
// binding to simple properties
showToolPanel={this.state.showToolPanel}
quickFilterText={this.state.quickFilterText}
// binding to an object property
icons={this.state.icons}
// no binding, just providing hard coded strings for the properties
suppressRowClickSelection="true"
rowSelection="multiple"
enableColResize="true"
enableSorting="true"
enableFilter="true"
groupHeaders="true"
rowHeight="22"
// we cannot filter on the groups, as filters work on the child nodes, and in this example
// the child nodes are not aggregations of the parent.
suppressMenuFilterPanel="true"
isFullWidthCell = {this.onIsFullWidthCell.bind(this)}
// see ag-Grid docs cellRenderer for details on how to build cellRenderers
fullWidthCellRendererFramework= {DetailPanelCellRenderer}
getRowHeight={this.onGetRowHeight.bind(this)}
getNodeChildDetails={this.onGetNodeChildDetails.bind(this)}
/>
</div>
);
}
return <div style={{width: '1024px'}}>
<div style={{padding: '4px'}}>
{topHeaderTemplate}
{bottomHeaderTemplate}
{gridTemplate}
</div>
</div>;
}
}

View File

@@ -0,0 +1,17 @@
export default class ColDefFactory {
createColDefs() {
return [
{headerName: "Athlete", field: "athlete", width: 200},
{headerName: "Age", field: "age", width: 90},
{headerName: "Gold", field: "gold", width: 100, aggFunc: 'sum'},
{headerName: "Silver", field: "silver", width: 100, aggFunc: 'sum'},
{headerName: "Bronze", field: "bronze", width: 100, aggFunc: 'sum'},
{headerName: "Total", field: "total", width: 100, aggFunc: 'sum'},
{headerName: "Country", field: "country", width: 120, rowGroupIndex: 0},
{headerName: "Year", field: "year", width: 90},
{headerName: "Date", field: "date", width: 110},
{headerName: "Sport", field: "sport", width: 110}
];
}
}

18
src-grouped/index.js Normal file
View File

@@ -0,0 +1,18 @@
'use strict';
import ReactDOM from 'react-dom';
import React from 'react';
import MyApp from './myApp.jsx';
// is there a better way of doing this?
import 'ag-grid-root/dist/styles/ag-grid.css';
import 'ag-grid-root/dist/styles/theme-fresh.css';
// waiting for dom to load before booting react. we could alternatively
// put the index.js reference at the end fo the index.html, but i prefer this way.
document.addEventListener('DOMContentLoaded', ()=> {
var container = document.getElementById('myAppContainer');
ReactDOM.render(
React.createElement(MyApp),
container
);
});

28
src-grouped/myApp.css Normal file
View File

@@ -0,0 +1,28 @@
.ag-cell {
padding-top: 2px !important;
padding-bottom: 2px !important;
}
label {
font-weight: normal !important;
}
.div-percent-bar {
display: inline-block;
height: 20px;
position: relative;
}
.div-percent-value {
position: absolute;
padding-left: 4px;
font-weight: bold;
font-size: 13px;
}
.div-outer-div {
display: inline-block;
height: 100%;
width: 100%;
}

99
src-grouped/myApp.jsx Normal file
View File

@@ -0,0 +1,99 @@
import React from "react";
import {AgGridReact} from "ag-grid-react";
import ColDefFactory from "./ColDefFactory.jsx";
import "./myApp.css";
// take this line out if you do not want to use ag-Grid-Enterprise
import "ag-grid-enterprise";
export default class MyApp extends React.Component {
constructor() {
super();
this.state = {
showToolPanel: false,
columnDefs: new ColDefFactory().createColDefs(),
rowData: null,
};
this.gridOptions = {
groupRowInnerRenderer: function (params) {
var FLAG_CODES = {
'Ireland': 'ie',
'United States': 'us',
'Russia': 'ru',
'Australia': 'au',
'Canada': 'ca',
'Norway': 'no',
'China': 'cn',
'Zimbabwe': 'zw',
'Netherlands': 'nl',
'South Korea': 'kr',
'Croatia': 'hr',
'France': 'fr'
};
var flagCode = FLAG_CODES[params.node.key];
var html = '';
if (flagCode) {
html += '<img class="flag" border="0" width="20" height="15" src="https://flags.fmcdn.net/data/flags/mini/' + flagCode + '.png">'
}
html += '<span class="groupTitle"> COUNTRY_NAME</span>'.replace('COUNTRY_NAME', params.node.key);
html += '<span class="medal gold"> Gold: GOLD_COUNT</span>'.replace('GOLD_COUNT', params.data.gold);
html += '<span class="medal silver"> Silver: SILVER_COUNT</span>'.replace('SILVER_COUNT', params.data.silver);
html += '<span class="medal bronze"> Bronze: BRONZE_COUNT</span>'.replace('BRONZE_COUNT', params.data.bronze);
return html;
}
};
}
onGridReady(params) {
this.api = params.api;
this.columnApi = params.columnApi;
var that = this;
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', '/olympicWinners.json');
httpRequest.send();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var httpResult = JSON.parse(httpRequest.responseText);
that.api.setRowData(httpResult);
}
};
}
render() {
var gridTemplate = (
<div style={{height: 400}} className="ag-fresh">
<AgGridReact
// gridOptions is optional - it's possible to provide
// all values as React props
gridOptions={this.gridOptions}
// listening for events
onGridReady={this.onGridReady.bind(this)}
// binding to array properties
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}
groupUseEntireRow="true"
/>
</div>
);
return <div style={{width: '800px'}}>
<div>
{gridTemplate}
</div>
</div>;
}
}

View File

@@ -4,6 +4,7 @@ import ProficiencyCellRenderer from './ProficiencyCellRenderer.jsx';
import RefData from './RefData';
import SkillsFilter from './SkillsFilter.jsx';
import ProficiencyFilter from './ProficiencyFilter.jsx';
import MyReactHeaderGroupComponent from './MyReactHeaderGroupComponent.jsx';
export default class ColDefFactory {
@@ -14,16 +15,28 @@ export default class ColDefFactory {
suppressMenu: true, pinned: true},
{
headerName: 'Employee',
headerGroupComponentFramework: MyReactHeaderGroupComponent,
children: [
{headerName: "Name", field: "name", enableRowGroup: true, enablePivot: true,
{
headerName: "Name", field: "name", enableRowGroup: true, enablePivot: true,
width: 150, pinned: true, editable: true,
// use a React cellEditor
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
cellRenderer: countryCellRenderer, pinned: true,
filterParams: {cellRenderer: countryCellRenderer, cellHeight: 20}},
filterParams: {
cellRenderer: countryCellRenderer, cellHeight: 20
}, columnGroupShow: 'open'
}, {
headerName: "DOB", field: "dob", width: 110, enableRowGroup: true, enablePivot: true, filter:'date',
pinned: true, cellRenderer: function(params) {
return pad(params.value.getDate(), 2) + '/' +
pad(params.value.getMonth() + 1, 2)+ '/' +
params.value.getFullYear();
}, columnGroupShow: 'open'
}
]
},
{
@@ -35,7 +48,7 @@ export default class ColDefFactory {
// supply a React component
filterFramework: SkillsFilter
},
{headerName: "Proficiency", field: "proficiency", width: 120, enableValue: true,
{headerName: "Proficiency", field: "proficiency", width: 135, enableValue: true,
// supply a React component
cellRendererFramework: ProficiencyCellRenderer,
// supply a React component
@@ -68,3 +81,10 @@ function countryCellRenderer(params) {
return null;
}
}
//Utility function used to pad the date formatting.
function pad(num, totalStringSize) {
let asString = num + "";
while (asString.length < totalStringSize) asString = "0" + asString;
return asString;
}

View File

@@ -0,0 +1,167 @@
import React from 'react';
// Date Component to be used in the date filter.
// This is a very simple example of how a React component can be plugged as a DateComponentFramework
// as you can see, the only requirement is that the React component implements the required methods
// getDate and setDate and that it calls back into props.onDateChanged every time that the date changes.
export default class MyReactDateComponent extends React.Component {
constructor(props) {
super(props);
//The state of this component is represented of:
// The current date it holds, null by default, null if the date typed by the user is not valid or fields are blank
// The current values that the user types in the input boxes, by default ''
//The textBoxes state is necessary since it can be set from ag-Grid. This can be seen in this example through
// the usage of the button DOB equals to 01/01/2000 in the example page.
this.state = {
date: null,
textBoxes: {
dd: '',
mm: '',
yyyy: ''
}
}
}
render() {
//Inlining styles to make simpler the component
let filterStyle = {
margin:'2px'
};
let ddStyle = {
width: '30px'
};
let mmStyle = {
width: '30px'
};
let yyyyStyle = {
width: '60px'
};
let resetStyle = {
padding: '2px',
backgroundColor: 'red',
borderRadius: '3px',
fontSize: '10px',
marginRight: '5px',
color: 'white'
};
return (
<div style={filterStyle}>
<span style={resetStyle} onClick={this.resetDate.bind(this)}>x</span>
<input onInput = {this.onDateChanged.bind(this)} ref="dd" placeholder="dd" style={ddStyle} value={this.state.textBoxes.dd} maxLength="2"/>/
<input onInput = {this.onDateChanged.bind(this)} ref="mm" placeholder="mm" style={mmStyle} value={this.state.textBoxes.mm} maxLength="2"/>/
<input onInput = {this.onDateChanged.bind(this)} ref="yyyy" placeholder="yyyy" style={yyyyStyle} value={this.state.textBoxes.yyyy} maxLength="4"/>
</div>
);
}
//*********************************************************************************
// METHODS REQUIRED BY AG-GRID
//*********************************************************************************
getDate (){
//ag-grid will call us here when in need to check what the current date value is hold by this
//component.
return this.state.date;
}
setDate (date){
//ag-grid will call us here when it needs this component to update the date that it holds.
this.setState({
date:date,
textBoxes:{
dd: date.getDate(),
mm: date.getMonth() + 1,
yyyy: date.getFullYear()
}
})
}
//*********************************************************************************
// LINKS THE INTERNAL STATE AND AG-GRID
//*********************************************************************************
updateAndNotifyAgGrid (date, textBoxes){
this.setState ({
date: date,
textBoxes:textBoxes
},
//Callback after the state is set. This is where we tell ag-grid that the date has changed so
//it will proceed with the filtering and we can then expect ag-Grid to call us back to getDate
this.props.onDateChanged
);
}
//*********************************************************************************
// LINKING THE UI, THE STATE AND AG-GRID
//*********************************************************************************
resetDate (){
let date = null;
let textBoxes = {
dd : '',
mm : '',
yyyy : '',
};
this.updateAndNotifyAgGrid(date, textBoxes)
}
onDateChanged () {
let date = this.parseDate(this.refs.dd.value, this.refs.mm.value, this.refs.yyyy.value);
let textBoxes = {
dd : this.refs.dd.value,
mm : this.refs.mm.value,
yyyy : this.refs.yyyy.value,
};
this.updateAndNotifyAgGrid(date, textBoxes)
}
//*********************************************************************************
// INTERNAL LOGIC
//*********************************************************************************
parseDate (dd, mm, yyyy){
//If any of the three input date fields are empty, stop and return null
if (dd.trim() === '' || mm.trim() === '' || yyyy.trim() === '') {
return null;
}
let day = Number(dd);
let month = Number(mm);
let year = Number(yyyy);
let date = new Date(year, month - 1, day);
//If the date is not valid
if (isNaN(date.getTime())){
return null;
}
//Given that new Date takes any garbage in, it is possible for the user to specify a new Date
//like this (-1, 35, 1) and it will return a valid javascript date. In this example, it will
//return Sat Dec 01 1 00:00:00 GMT+0000 (GMT) - Go figure...
//To ensure that we are not letting non sensical dates to go through we check that the resultant
//javascript date parts (month, year and day) match the given date fields provided as parameters.
//If the javascript date parts don't match the provided fields, we assume that the input is non
//sensical... ie: Day=-1 or month=14, if this is the case, we return null
//This also protects us from non sensical dates like dd=31, mm=2 of any year
if (date.getDate() != day || date.getMonth() + 1 != month || date.getFullYear() != year){
return null;
}
return date;
}
}
// the grid will always pass in one props called 'params',
// which is the grid passing you the params for the cellRenderer.
// this piece is optional. the grid will always pass the 'params'
// props, so little need for adding this validation meta-data.
MyReactDateComponent.propTypes = {
params: React.PropTypes.object
};

View File

@@ -0,0 +1,76 @@
import React from 'react';
// Header component to be used as default for all the columns.
export default class MyReactHeaderComponent extends React.Component {
constructor(props) {
super(props);
this.props.column.addEventListener('sortChanged', this.onSortChanged.bind(this));
//The state of this component contains the current sort state of this column
//The possible values are: 'asc', 'desc' and ''
this.state = {
sorted: ''
}
}
render() {
let sortElements = [];
if (this.props.enableSorting){
let downArrowClass = "customSortDownLabel " + (this.state.sorted === 'desc' ? " active" : "");
let upArrowClass = "customSortUpLabel " + (this.state.sorted === 'asc' ? " active" : "");
let removeArrowClass = "customSortRemoveLabel " + (this.state.sorted === '' ? " active" : "");
sortElements.push(<div className={downArrowClass} onClick={this.onSortRequested.bind(this, 'desc')}><i className="fa fa-long-arrow-down"/></div>)
sortElements.push(<div className={upArrowClass} onClick={this.onSortRequested.bind(this, 'asc')}><i className="fa fa-long-arrow-up"/></div>)
sortElements.push(<div className={removeArrowClass} onClick={this.onSortRequested.bind(this, '')}><i className="fa fa-times"/></div>)
}
let menuButton = null;
if (this.props.enableMenu){
menuButton = <div ref="menuButton" className="customHeaderMenuButton" onClick={this.onMenuClick.bind(this)}><i className={"fa " + this.props.menuIcon}/></div>
}
return <div>
{menuButton}
<div className="customHeaderLabel">{this.props.displayName}</div>
{sortElements}
</div>
}
onSortRequested (order, event) {
this.props.setSort (order, event.shiftKey);
};
onSortChanged (){
if (this.props.column.isSortAscending()){
this.setState({
sorted: 'asc'
})
} else if (this.props.column.isSortDescending()){
this.setState({
sorted: 'desc'
})
} else {
this.setState({
sorted: ''
})
}
};
onMenuClick (){
this.props.showColumnMenu (this.refs.menuButton);
};
}
// the grid will always pass in one props called 'params',
// which is the grid passing you the params for the cellRenderer.
// this piece is optional. the grid will always pass the 'params'
// props, so little need for adding this validation meta-data.
MyReactHeaderComponent.propTypes = {
params: React.PropTypes.object
};

View File

@@ -0,0 +1,41 @@
import React from 'react';
// Header component to be used as default for all the columns.
export default class MyReactHeaderGroupComponent extends React.Component {
constructor(props) {
super(props);
this.props.columnGroup.getOriginalColumnGroup().addEventListener('expandedChanged', this.onExpandChanged.bind(this));
this.state = {
expanded:null
}
this.onExpandChanged();
}
render() {
let arrowClassName = "customExpandButton " + (this.state.expanded ? " expanded": " collapsed");
return <div>
<div className="customHeaderLabel"> {this.props.displayName}</div>
<div onClick={this.expandOrCollapse.bind(this)} className={arrowClassName}><i className="fa fa-arrow-right" /></div>
</div>
}
expandOrCollapse (){
this.props.setExpanded(!this.state.expanded);
};
onExpandChanged (){
this.setState({
expanded: this.props.columnGroup.getOriginalColumnGroup().isExpanded()
})
}
}
// the grid will always pass in one props called 'params',
// which is the grid passing you the params for the cellRenderer.
// this piece is optional. the grid will always pass the 'params'
// props, so little need for adding this validation meta-data.
MyReactHeaderGroupComponent.propTypes = {
params: React.PropTypes.object
};

View File

@@ -56,6 +56,21 @@ RefData.COUNTRIES = [
{country: "Uruguay", continent: "South America", language: "Spanish"}
];
RefData.DOB = [
new Date(2000, 0, 1 ),
new Date(2001, 1, 2 ),
new Date(2002, 2, 3 ),
new Date(2003, 3, 4 ),
new Date(2004, 4, 5 ),
new Date(2005, 5, 6 ),
new Date(2006, 6, 7 ),
new Date(2007, 7, 8 ),
new Date(2008, 8, 9 ),
new Date(2009, 9, 10 ),
new Date(2010, 10, 11 ),
new Date(2011, 11, 12 )
];
RefData.ADDRESSES = [
'1197 Thunder Wagon Common, Cataract, RI, 02987-1016, US, (401) 747-0763',
'3685 Rocky Glade, Showtucket, NU, X1E-9I0, CA, (867) 371-4215',

View File

@@ -5,7 +5,7 @@ export default class RowDataFactory {
createRowData() {
var rowData = [];
for (var i = 0; i < 1000; i++) {
for (var i = 0; i < 200; i++) {
var countryData = RefData.COUNTRIES[i % RefData.COUNTRIES.length];
rowData.push({
name: RefData.FIRST_NAMES[i % RefData.FIRST_NAMES.length] + ' ' + RefData.LAST_NAMES[i % RefData.LAST_NAMES.length],
@@ -16,6 +16,7 @@ export default class RowDataFactory {
windows: Math.random() < 0.4,
css: Math.random() < 0.4
},
dob: RefData.DOB[i % RefData.DOB.length],
address: RefData.ADDRESSES[i % RefData.ADDRESSES.length],
years: Math.round(Math.random() * 100),
proficiency: Math.round(Math.random() * 100),

View File

@@ -71,6 +71,10 @@ export default class SkillsFilter extends React.Component {
this.setState(newModel, this.props.filterChangedCallback );
}
helloFromSkillsFilter() {
alert("Hello From The Skills Filter!");
}
render() {
var skillsTemplates = [];

View File

@@ -1,13 +1,13 @@
import ReactDOM from 'react-dom';
import React from 'react';
import {AgGridReact} from 'ag-grid-react';
import RefData from './RefData';
import RowDataFactory from './RowDataFactory';
import ColDefFactory from './ColDefFactory.jsx';
import './myApp.css';
import React from "react";
import {AgGridReact} from "ag-grid-react";
import RowDataFactory from "./RowDataFactory";
import ColDefFactory from "./ColDefFactory.jsx";
import MyReactDateComponent from "./MyReactDateComponent.jsx";
import MyReactHeaderComponent from "./MyReactHeaderComponent.jsx";
import "./myApp.css";
import "ag-grid-enterprise";
// take this line out if you do not want to use ag-Grid-Enterprise
import 'ag-grid-enterprise';
export default class MyApp extends React.Component {
@@ -39,10 +39,18 @@ export default class MyApp extends React.Component {
// you do, the providing the gridOptions as a standalone object is just
// what you want!
this.gridOptions = {
//We register the react date component that ag-grid will use to render
dateComponentFramework:MyReactDateComponent,
// this is how you listen for events using gridOptions
onModelUpdated: function() {
onModelUpdated: function () {
console.log('event onModelUpdated received');
},
defaultColDef : {
headerComponentFramework : MyReactHeaderComponent,
headerComponentParams : {
menuIcon: 'fa-bars'
}
},
// this is a simple property
rowBuffer: 10 // no need to set this, the default is fine for almost all scenarios
};
@@ -94,6 +102,20 @@ export default class MyApp extends React.Component {
});
}
invokeSkillsFilterMethod() {
var skillsFilter = this.api.getFilterInstance('skills');
var componentInstance = skillsFilter.getFrameworkComponentInstance();
componentInstance.helloFromSkillsFilter();
}
dobFilter () {
let dateFilterComponent = this.gridOptions.api.getFilterInstance('dob');
dateFilterComponent.setFilterType('equals');
dateFilterComponent.setDateFrom('2000-01-01');
this.gridOptions.api.onFilterChanged();
}
render() {
var gridTemplate;
var bottomHeaderTemplate;
@@ -102,9 +124,14 @@ export default class MyApp extends React.Component {
topHeaderTemplate = (
<div>
<div style={{float: 'right'}}>
<input type="text" onChange={this.onQuickFilterText.bind(this)} placeholder="Type text to filter..."/>
<button id="btDestroyGrid" disabled={!this.state.showGrid} onClick={this.onShowGrid.bind(this, false)}>Destroy Grid</button>
<button id="btCreateGrid" disabled={this.state.showGrid} onClick={this.onShowGrid.bind(this, true)}>Create Grid</button>
<input type="text" onChange={this.onQuickFilterText.bind(this)}
placeholder="Type text to filter..."/>
<button id="btDestroyGrid" disabled={!this.state.showGrid}
onClick={this.onShowGrid.bind(this, false)}>Destroy Grid
</button>
<button id="btCreateGrid" disabled={this.state.showGrid} onClick={this.onShowGrid.bind(this, true)}>
Create Grid
</button>
</div>
<div style={{padding: '4px'}}>
<b>Employees Skills and Contact Details</b> <span id="rowCount"/>
@@ -130,11 +157,18 @@ export default class MyApp extends React.Component {
</div>
<div style={{clear: 'both'}}></div>
<div style={{padding: 4}} className={'toolbar'}>
<span>
<label>
<input type="checkbox" onChange={this.onToggleToolPanel.bind(this)}/>
Show Tool Panel
</label>
<button onClick={this.onRefreshData.bind(this)}>Refresh Data</button>
</span>
<span style={{marginLeft: 20}}>
Filter API:
<button onClick={this.invokeSkillsFilterMethod.bind(this, false)}>Invoke Skills Filter Method</button>
<button onClick={this.dobFilter.bind(this)}>DOB equals to 01/01/2000</button>
</span>
</div>
<div style={{clear: 'both'}}></div>
</div>
@@ -170,13 +204,12 @@ export default class MyApp extends React.Component {
enableFilter="true"
groupHeaders="true"
rowHeight="22"
debug="true"
/>
</div>
);
}
return <div style={{width: '800px'}}>
return <div style={{width: '1024px'}}>
<div style={{padding: '4px'}}>
{topHeaderTemplate}
{bottomHeaderTemplate}

View File

@@ -0,0 +1,27 @@
module.exports = {
entry: "./src-full-width/index.js",
output: {
path: __dirname,
filename: "dist/bundle.js"
},
module: {
loaders: [
{
test: /\.css$/,
loader: "style!css"
},
{
test: /\.js$|\.jsx$/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
}
]
},
resolve: {
alias: {
"ag-grid-root" : __dirname + "/node_modules/ag-grid"
}
}
};

27
webpack.config.grouped.js Normal file
View File

@@ -0,0 +1,27 @@
module.exports = {
entry: "./src-grouped/index.js",
output: {
path: __dirname,
filename: "dist/bundle.js"
},
module: {
loaders: [
{
test: /\.css$/,
loader: "style!css"
},
{
test: /\.js$|\.jsx$/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
}
]
},
resolve: {
alias: {
"ag-grid-root" : __dirname + "/node_modules/ag-grid"
}
}
};