AG-420 Improve React implementation
This commit is contained in:
@@ -32,50 +32,58 @@ class TopMoversGrid extends Component {
|
||||
headerName: '% NC',
|
||||
headerClass: 'align-right',
|
||||
cellRenderer: 'animateShowChange',
|
||||
cellClass: 'align-right'
|
||||
cellClass: 'align-right',
|
||||
cellFormatter(params) {
|
||||
return params.value.toFixed(2)
|
||||
}
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
// grid events
|
||||
this.onGridReady = this.onGridReady.bind(this);
|
||||
this.getRowNodeId = this.getRowNodeId.bind(this);
|
||||
}
|
||||
|
||||
getRowNodeId(data) {
|
||||
return data.symbol;
|
||||
}
|
||||
|
||||
onGridReady(params) {
|
||||
this.gridApi = params.api;
|
||||
this.columnApi = params.columnApi;
|
||||
|
||||
if (this.props.rowData) {
|
||||
this.gridApi.setRowData(this.props.rowData);
|
||||
}
|
||||
// if (this.props.rowData) {
|
||||
// this.gridApi.setRowData(this.props.rowData);
|
||||
// }
|
||||
this.gridApi.sizeColumnsToFit();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
let newRowData = nextProps.rowData;
|
||||
let model = this.gridApi.getModel();
|
||||
|
||||
// remove nodes not in new data set
|
||||
let nodesToRemove = [];
|
||||
for (let rowIndex = 0; rowIndex < model.getRowCount(); rowIndex++) {
|
||||
let rowNode = model.getRow(rowIndex);
|
||||
if (rowNode.data.symbol !== newRowData[rowIndex].symbol) {
|
||||
nodesToRemove.push(rowNode);
|
||||
}
|
||||
}
|
||||
this.gridApi.removeItems(nodesToRemove);
|
||||
|
||||
// add new items in set
|
||||
for (let rowIndex = 0; rowIndex < newRowData.length; rowIndex++) {
|
||||
let model = this.gridApi.getModel();
|
||||
let rowNode = model.getRow(rowIndex);
|
||||
|
||||
if (!rowNode ||
|
||||
rowNode.data.symbol !== newRowData[rowIndex].symbol) {
|
||||
this.gridApi.insertItemsAtIndex(rowIndex, [newRowData[rowIndex]])
|
||||
}
|
||||
}
|
||||
}
|
||||
// componentWillReceiveProps(nextProps) {
|
||||
// let newRowData = nextProps.rowData;
|
||||
// let model = this.gridApi.getModel();
|
||||
//
|
||||
// // remove nodes not in new data set
|
||||
// let nodesToRemove = [];
|
||||
// for (let rowIndex = 0; rowIndex < model.getRowCount(); rowIndex++) {
|
||||
// let rowNode = model.getRow(rowIndex);
|
||||
// if (rowNode.data.symbol !== newRowData[rowIndex].symbol) {
|
||||
// nodesToRemove.push(rowNode);
|
||||
// }
|
||||
// }
|
||||
// this.gridApi.removeItems(nodesToRemove);
|
||||
//
|
||||
// // add new items in set
|
||||
// for (let rowIndex = 0; rowIndex < newRowData.length; rowIndex++) {
|
||||
// let model = this.gridApi.getModel();
|
||||
// let rowNode = model.getRow(rowIndex);
|
||||
//
|
||||
// if (!rowNode ||
|
||||
// rowNode.data.symbol !== newRowData[rowIndex].symbol) {
|
||||
// this.gridApi.insertItemsAtIndex(rowIndex, [newRowData[rowIndex]])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
render() {
|
||||
return (
|
||||
@@ -84,9 +92,12 @@ class TopMoversGrid extends Component {
|
||||
<AgGridReact
|
||||
// properties
|
||||
columnDefs={this.state.columnDefs}
|
||||
enableSorting="false"
|
||||
rowData={this.props.rowData}
|
||||
enableSorting="true"
|
||||
enableFilter="false"
|
||||
animateRows="true"
|
||||
enableImmutableMode="true"
|
||||
getRowNodeId={this.getRowNodeId}
|
||||
|
||||
// events
|
||||
onGridReady={this.onGridReady}>
|
||||
|
||||
Reference in New Issue
Block a user