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 { dropDownSource1: IDropDownListProps['source']; dropDownSource2: IDropDownListProps['source']; } class App extends React.PureComponent<{}, IState> { private myGrid = React.createRef(); private myDropDownList = React.createRef(); private myInput1 = React.createRef(); private myInput2 = React.createRef(); private selectedCell = React.createRef(); private unselectedCell = React.createRef(); constructor(props: {}) { super(props); this.scrollToBtnOnClick = this.scrollToBtnOnClick.bind(this); this.clearBtnOnClick = this.clearBtnOnClick.bind(this); this.selectBtnOnClick = this.selectBtnOnClick.bind(this); this.myDropDownListOnSelect = this.myDropDownListOnSelect.bind(this); this.myCheckBoxOnChange = this.myCheckBoxOnChange.bind(this); this.myGridOnCellSelect = this.myGridOnCellSelect.bind(this); this.myGridOnCellUnselect = this.myGridOnCellUnselect.bind(this); const source: any = { datafields: [ { name: 'id', type: 'number' }, { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'available', type: 'bool' }, { 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' } ], dropDownSource1: ['none', 'single cell', 'multiple cells', 'multiple cells extended', 'multiple cells advanced'], dropDownSource2: ['First Name', 'Last Name', 'Product Name', 'Quantity', 'Unit Price', 'Total'], enablehover: true, source: new jqx.dataAdapter(source) } } public render() { return (
Scroll to Row
Enable Hover
Selection Mode
Row
Column:
Clear Selection Select Cell
Selection Log:
Selected Cell:
Unselected Cell:
); } private scrollToBtnOnClick(): void { const index = parseInt(this.myInput1.current!.getOptions('value'), 10); if (!isNaN(index)) { this.myGrid.current!.ensurerowvisible(index); } }; private clearBtnOnClick(): void { this.myGrid.current!.clearselection(); }; private selectBtnOnClick(): void { const index = parseInt(this.myInput2.current!.getOptions('value'), 10); const columnindex = this.myDropDownList.current!.getSelectedIndex(); const columndatafield = this.myGrid.current!.getcolumnat(columnindex).datafield; if (!isNaN(index)) { this.myGrid.current!.selectcell(index, columndatafield); } }; // enable or disable the selection. private myDropDownListOnSelect(event: any): void { const index = event.args.index; let newSelectionMode: IGridProps['selectionmode']; switch (index) { case 0: newSelectionMode = 'none'; break; case 1: newSelectionMode = 'singlecell'; break; case 2: newSelectionMode = 'multiplecells'; break; case 3: newSelectionMode = 'multiplecellsextended'; break; case 4: newSelectionMode = 'multiplecellsadvanced'; break; } this.myGrid.current!.setOptions({ selectionmode: newSelectionMode }); }; // enable or disable the hover state. private myCheckBoxOnChange(event: any): void { this.myGrid.current!.setOptions({ enablehover: event.args.checked }); }; // display selected row index. private myGridOnCellSelect(event: any): void { const columnheader = this.myGrid.current!.getcolumn(event.args.datafield).text; this.selectedCell.current!.innerHTML = 'Row: ' + event.args.rowindex + ', Column: ' + columnheader; }; // display unselected row index. private myGridOnCellUnselect(event: any): void { const columnheader = this.myGrid.current!.getcolumn(event.args.datafield).text; this.unselectedCell.current!.innerHTML = 'Row: ' + event.args.rowindex + ', Column: ' + columnheader; }; } export default App;