import * as React from 'react'; import { generatedata } from './generatedata'; import JqxButton from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxbuttons'; import JqxGrid, { IGridProps, jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxgrid'; class App extends React.PureComponent<{}, IGridProps> { private myGrid = React.createRef(); private source: any = { datafields: [ { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' }, { name: 'total', type: 'number' } ], datatype: 'array', localdata: generatedata(500, false) }; constructor(props: {}) { super(props); this.refreshBtnOnClick = this.refreshBtnOnClick.bind(this); this.clearBtnOnClick = this.clearBtnOnClick.bind(this); this.state = { columns: [ { text: 'First Name', datafield: 'firstname', width: 130 }, { text: 'Last Name', datafield: 'lastname', width: 130 }, { text: 'Product', datafield: 'productname', width: 180 }, { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' }, { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' }, { text: 'Total', datafield: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' } ], source: new jqx.dataAdapter(this.source) } } public render() { const style = { display: 'inline-block' } return (
Refresh Data Clear
); } private refreshBtnOnClick(): void { this.source.localdata = generatedata(500, false); // passing 'cells' to the 'updatebounddata' method will refresh only the cells values when the new rows count is equal to the previous rows count. this.myGrid.current!.updatebounddata('cells'); } private clearBtnOnClick(): void { this.myGrid.current!.clear(); } } export default App;