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, { IDropDownListProps } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxdropdownlist'; import JqxInput from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxinput'; export interface IState extends IDataTableProps { selectedIndex: IDropDownListProps['selectedIndex']; } class App extends React.PureComponent<{}, IState> { private myDataTable = React.createRef(); private myInput = React.createRef(); private selectedRows = React.createRef(); constructor(props: {}) { super(props); this.dropDownOnChange = this.dropDownOnChange.bind(this); this.rowSelectBtnOnClick = this.rowSelectBtnOnClick.bind(this); this.clearSelectionBtnOnClick = this.clearSelectionBtnOnClick.bind(this); this.selectionInfo = this.selectionInfo.bind(this); const source = { dataFields: [ { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' } ], dataType: 'array', localData: generatedata(15, false), }; this.state = { columns: [ { text: 'First Name', dataField: 'firstname', width: 200 }, { text: 'Last Name', dataField: 'lastname', width: 200 }, { text: 'Product', dataField: 'productname', width: 180 }, { text: 'Unit Price', dataField: 'price', width: 90, align: 'right', cellsAlign: 'right', cellsFormat: 'c2' }, { text: 'Quantity', dataField: 'quantity', align: 'right', cellsAlign: 'right' } ], selectedIndex: 1, selectionMode: 'multipleRows', source: new jqx.dataAdapter(source) }; } public render() { return (
Settings
Select Row:

Select Clear Selection

Selection Mode:
); } private dropDownOnChange(event: any): void { const index = event.args.index let newSelectionMode: IDataTableProps['selectionMode']; switch (index) { case 0: // disable multiple rows selection with Shift or Ctrl. newSelectionMode = 'singleRow'; break; case 1: // enable multiple rows selection with Shift or Ctrl. newSelectionMode = 'multipleRows'; break; } this.setState({ selectedIndex: index, selectionMode: newSelectionMode }); }; private rowSelectBtnOnClick(): void { const index = parseInt(this.myInput.current!.getOptions('value'), 10); this.myDataTable.current!.selectRow(index); }; private clearSelectionBtnOnClick(): void { this.myDataTable.current!.clearSelection(); }; private selectionInfo() { // gets selected row indexes. The method returns an Array of indexes. const selection = this.myDataTable.current!.getSelection(); let selectedRows = '
Selected Row Indexes:
'; if (selection && selection.length > 0) { const rows = this.myDataTable.current!.getRows(); for (let i = 0; i < selection.length; i++) { const rowData = selection[i]; selectedRows += rows.indexOf(rowData); if (i < selection.length - 1) { selectedRows += ', '; } if (i > 1 && i % 8 === 0) { selectedRows += '
'; } } } this.selectedRows.current!.innerHTML = selectedRows; } } export default App;