import * as React from 'react'; import { generatedata } from './generatedata'; import JqxButton from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxbuttons'; import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxcheckbox'; import JqxDropDownList, { IDropDownListProps } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxdropdownlist'; import JqxGrid, { IGridProps, jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxgrid'; import JqxInput from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxinput'; export interface IState extends IGridProps { dropDownSource: IDropDownListProps['source']; } class App extends React.PureComponent<{}, IState> { private myGrid = React.createRef(); private mySelectRowBtn = React.createRef(); private myInput1 = React.createRef(); private myInput2 = React.createRef(); private selectedRowIndex = React.createRef(); private unselectedRowIndex = React.createRef(); constructor(props: {}) { super(props); this.scrollToBtnOnClick = this.scrollToBtnOnClick.bind(this); this.selectRowBtnOnClick = this.selectRowBtnOnClick.bind(this); this.clearSelectionBtnOnClick = this.clearSelectionBtnOnClick.bind(this); this.enableSelectionOnSelect = this.enableSelectionOnSelect.bind(this); this.enableHoverOnChange = this.enableHoverOnChange.bind(this); this.myGridOnRowSelect = this.myGridOnRowSelect.bind(this); this.myGridOnRowUnselect = this.myGridOnRowUnselect.bind(this); const source: any = { datafields: [ { name: 'id', type: 'number' }, { 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(200, 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: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' }, { text: 'Unit Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2' } ], dropDownSource: ['none', 'single row', 'multiple rows', 'multiple rows extended'], ready: () => { this.myGrid.current!.selectrow(2); }, source: new jqx.dataAdapter(source) } } public render() { return (
Scroll to Row
Select Row Clear Selection
Enable Hover
Selection Mode:
Selection Modes:
  • 'none' - disables the selection. Selection is possible only through the API.
  • 'singlerow' - full row selection. Each click changes the selected row.
  • 'multiplerows' - each click selects a new row. Click on a selected row unselects it.
  • 'multiplerowsextended' - users can select multiple rows with drag and drop or
    by clicking on rows while holding Ctrl or Shift.
Selection Log:
Selected Row Index:
Unselected Row Index:
); } private scrollToBtnOnClick(): void { const index = parseInt(this.myInput1.current!.getOptions('value'), 10); if (!isNaN(index)) { this.myGrid.current!.ensurerowvisible(index); } }; private selectRowBtnOnClick(): void { const index = parseInt(this.myInput2.current!.getOptions('value'), 10); if (!isNaN(index)) { this.myGrid.current!.selectrow(index); } }; private clearSelectionBtnOnClick(): void { this.myGrid.current!.clearselection(); }; private enableSelectionOnSelect(event: any): void { const index = event.args.index; this.mySelectRowBtn.current!.setOptions({ disabled: false }); let newSelectionMode: IGridProps['selectionmode']; switch (index) { case 0: newSelectionMode = 'none'; this.mySelectRowBtn.current!.setOptions({ disabled: true }); break; case 1: newSelectionMode = 'singlerow'; break; case 2: newSelectionMode = 'multiplerows'; break; case 3: newSelectionMode = 'multiplerowsextended'; break; } this.myGrid.current!.setOptions({ selectionmode: newSelectionMode }); }; private enableHoverOnChange(event: any): void { this.myGrid.current!.setOptions({ enablehover: event.args.checked }); }; private myGridOnRowSelect(event: any): void { this.selectedRowIndex.current!.innerHTML = event.args.rowindex; }; private myGridOnRowUnselect(event: any): void { this.unselectedRowIndex.current!.innerHTML = event.args.rowindex; }; } export default App;