import * as React from 'react'; import * as ReactDOM from 'react-dom'; 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<{}> { private myTable = React.createRef(); constructor(props: {}) { super(props); this.loadBtn = this.loadBtn.bind(this); this.generateData = this.generateData.bind(this); } public render() { return (
First Name Last Name Product Available Ship Date Quantity Price
Nancy Vileid Espresso con Panna true 5/20/2012 9 $3.25
Elio Nagase Espresso con Panna true 9/26/2012 6 $3.25
Cheryl Nagase Doubleshot Espresso false 4/19/2012 9 $3.30
Regina Devling Caramel Latte true 2/26/2012 11 $3.80
Michael Winkler Doubleshot Espresso false 7/16/2012 4 $3.30
Mayumi Burke Caffe Americano false 9/7/2012 1 $2.50
Andrew Nagase Caffe Espresso true 4/15/2012 3 $3.00
Ian Burke Green Tea false 11/16/2012 5 $1.50
Yoshi Petersen White Chocolate Mocha false 7/26/2012 2 $3.60
Lars Bjorn Peppermint Mocha Twist false 7/17/2012 11 $4.00
Guylene Devling Caramel Latte true 8/9/2012 6 $3.80
Michael Burke Caffe Americano false 9/10/2012 11 $2.50
Petra Vileid White Chocolate Mocha false 8/21/2012 7 $3.60
Lars Nodier White Chocolate Mocha false 7/16/2012 8 $3.60
Load React Grid from Table
); } private loadBtn(): void { const source = { datafields: [ { name: 'First Name', type: 'string' }, { name: 'Last Name', type: 'string' }, { name: 'Product', type: 'string' }, { name: 'Available', type: 'string' }, { name: 'Ship Date', type: 'date', format: 'MM/dd/yyyy' }, { name: 'Quantity', type: 'number' }, { name: 'Price', type: 'number' } ], datatype: 'array', localdata: this.generateData(), }; const dataAdapter = new jqx.dataAdapter(source); const columns: IGridProps['columns'] = [ { text: 'First Name', datafield: 'First Name', align: 'center', width: 130 }, { text: 'Last Name', datafield: 'Last Name', align: 'center', width: 130 }, { text: 'Product', datafield: 'Product', align: 'center', width: 170 }, { text: 'Available', datafield: 'Available', columntype: 'checkbox', align: 'center', width: 90 }, { text: 'Ship Date', datafield: 'Ship Date', align: 'center', cellsformat: 'd', width: 100 }, { text: 'Quantity', datafield: 'Quantity', align: 'center', cellsalign: 'right', width: 100 }, { text: 'Price', datafield: 'Price', align: 'right', cellsalign: 'right', cellsformat: 'c2' } ]; ReactDOM.render( , document.getElementById('grid') ); } private generateData(): any[] { const table = this.myTable.current!; const columns = table.children[0].getElementsByTagName('th'); const rows = table.children[1].getElementsByTagName('tr'); const data: any[] = []; Array.prototype.forEach.call(rows, (row: any) => { const datarow: any = {}; for (let j = 0; j < columns.length; j++) { // Get column's title. const columnName = columns[j].innerHTML; // Get cell. const cell = row.children[j].innerHTML; datarow[columnName] = cell; } data[data.length] = datarow; }); return data; } } export default App;