SolutionIn Grid, search action has been been handled by Search item of the toolbar. By default, on pressing the Enter key, search action will be started. To overcome the default behavior of the search action, we are searching the Grid in keystrokes. On each keystroke (over the input element), certain time interval (of debouncing) has been handled to search the Grid. Using event delegation concept, you can handle the keydown event for the input textbox (Search item). Define the GridDefine the Grid with the load event where you can bind the keydown event for the Grid. import { Grid, Page, Selection, Toolbar } from '@syncfusion/ej2-grids'; import { categoryData } from './data-source'; Grid.Inject(Page, Selection, Toolbar); let grid: Grid = new Grid( { dataSource: categoryData, allowPaging: true, toolbar: ['Search'], load: onLoad, columns: [ { field: 'CategoryName', headerText: 'Category Name', width: 160 }, { field: 'ProductName', headerText: 'Product Name', width: 170 }, { field: 'QuantityPerUnit', headerText: 'Quantity Per Unit', width: 170, textAlign: 'Right' }, { field: 'UnitsInStock', headerText: 'Units In Stock', width: 170, textAlign: 'Right' }, { field: 'Discontinued', headerText: 'Discontinued', width: 150, textAlign: 'Center', displayAsCheckBox: true, type: 'boolean' } ], pageSettings: { pageCount: 5 } }); grid.appendTo('#Grid');
In the Keydown listener, search action has been handled using the search method of the Grid.
OutputFigure 1: Grid with the searched records Typescript demo: https://stackblitz.com/edit/5g89yd-xhbewq?file=index.ts Angular Demo: https://stackblitz.com/edit/angular-yta9sj?file=app.component.ts React Demo: https://stackblitz.com/edit/react-hhbfey?file=index.js |
This page will automatically be redirected to the sign-in page in 10 seconds.