import * as React from 'react'; import * as ReactDOM from 'react-dom'; import './App.css'; import { generatedata } from './generatedata'; import JqxButton from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxbuttons'; import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxcheckbox'; import JqxGrid, { IGridProps, jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxgrid'; import JqxInput from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxinput'; import JqxPanel from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxpanel'; class App extends React.PureComponent<{}, IGridProps> { private myGrid = React.createRef(); private myPanel = React.createRef(); private myInput = React.createRef(); constructor(props: {}) { super(props); this.myGridOnFilter = this.myGridOnFilter.bind(this); this.removeFilterBtnOnClick = this.removeFilterBtnOnClick.bind(this); this.filterBackgroundCheckBoxOnChange = this.filterBackgroundCheckBoxOnChange.bind(this); this.filterIconsCheckBoxOnChange = this.filterIconsCheckBoxOnChange.bind(this); const source: any = { datafields: [ { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'date', type: 'date' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' } ], datatype: 'array', localdata: generatedata(500, false) }; const dataAdapter = new jqx.dataAdapter(source); const buildFilterPanel = (filterPanel: any, datafield: string): void => { const dataSource = { async: false, datatype: 'array', localdata: dataAdapter.records } const inputDataAdapter = new jqx.dataAdapter(dataSource, { async: false, autoBind: false, autoSort: true, autoSortField: datafield, uniqueDataFields: [datafield] } ); const column = this.myGrid.current!.getcolumn(datafield); const filterButtonClick = () => { const filtergroup = new jqx.filter(); const filterOrOperator = 1; const filtervalue = this.myInput.current!.getOptions('value'); const filtercondition = 'contains'; const filter1 = filtergroup.createfilter('stringfilter', filtervalue, filtercondition); filtergroup.addfilter(filterOrOperator, filter1); // add the filters. this.myGrid.current!.addfilter(datafield, filtergroup); // apply the filters. this.myGrid.current!.applyfilters(); this.myGrid.current!.closemenu(); }; const filterClearButtonClick = () => { this.myGrid.current!.removefilter(datafield, false); // apply the filters. this.myGrid.current!.applyfilters(); this.myGrid.current!.closemenu(); } ReactDOM.render(
, filterPanel[0] ); }; const columnmenuopening = (menu: any, datafield: any, height: any): void => { const column: any = this.myGrid.current!.getcolumn(datafield); if (column.filtertype === 'custom') { menu.height(155); setTimeout(() => { menu.find('input').focus(); }, 25); } else { menu.height(height); } }; this.state = { columnmenuopening, columns: [ { createfilterpanel: (datafield: string, filterPanel: any): void => { buildFilterPanel(filterPanel, datafield); }, datafield: 'firstname', filtertype: 'custom', text: 'First Name', width: 160 }, { createfilterpanel: (datafield: string, filterPanel: any): void => { buildFilterPanel(filterPanel, datafield); }, datafield: 'lastname', filtertype: 'custom', text: 'Last Name', width: 160 }, { text: 'Product', datafield: 'productname', filtertype: 'checkedlist', width: 170 }, { text: 'Order Date', datafield: 'date', filtertype: 'date', width: 160, cellsformat: 'dd-MMMM-yyyy' }, { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' }, { text: 'Unit Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2' } ], source: dataAdapter } } public render() { return (
Remove Filter Filter Background Show All Filter Icons
Event Log:
); } private myGridOnFilter(): void { this.myPanel.current!.clearcontent(); const filterinfo = this.myGrid.current!.getfilterinformation(); for (const filterinfoItem of filterinfo) { const eventData = 'Filter Column: ' + filterinfoItem.filtercolumntext; this.myPanel.current!.prepend('
' + eventData + '
'); } }; private removeFilterBtnOnClick(): void { this.myGrid.current!.clearfilters(); }; private filterBackgroundCheckBoxOnChange(event: any): void { this.myGrid.current!.setOptions({ showfiltercolumnbackground: event.args.checked }); }; private filterIconsCheckBoxOnChange(event: any): void { this.myGrid.current!.setOptions({ autoshowfiltericon: !event.args.checked }); }; } export default App;