import * as React from 'react'; import { generatedata } from './generatedata'; import JqxButton from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxbuttons'; import JqxDataTable, { IDataTableProps, jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxdatatable'; import JqxDropDownList from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxdropdownlist'; class App extends React.PureComponent<{}, IDataTableProps> { private myDataTable = React.createRef(); private columnName = React.createRef(); private sortOrder = React.createRef(); constructor(props: {}) { super(props); this.sortBtnOnClick = this.sortBtnOnClick.bind(this); this.clearBtnOnClick = this.clearBtnOnClick.bind(this); const 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(85, false) } this.state = { columns: [ { text: 'Name', dataField: 'firstname', width: 200 }, { text: 'Last Name', dataField: 'lastname', width: 200 }, { text: 'Product', editable: false, dataField: 'productname', width: 180 }, { text: 'Quantity', dataField: 'quantity', width: 80, align: 'right', cellsAlign: 'right' }, { text: 'Unit Price', dataField: 'price', width: 90, align: 'right', cellsAlign: 'right', cellsFormat: 'c2' }, { text: 'Total', dataField: 'total', width: 100, align: 'right', cellsAlign: 'right', cellsFormat: 'c2' } ], source: new jqx.dataAdapter(source) }; } public render() { return (
Settings
Column:
Sort Order:
Sort Clear
); } private sortBtnOnClick(): void { const columnIndex = this.columnName.current!.getOptions('selectedIndex'); const sortOrder = this.sortOrder.current!.getOptions('selectedIndex') === 0 ? 'asc' : 'desc'; this.myDataTable.current!.sortBy(this.state.columns![columnIndex].dataField!, sortOrder); } private clearBtnOnClick(): void { this.myDataTable.current!.sortBy('firstname', null); } } export default App;