Search
//<code-header>
fiddle.title = 'Search';
//</code-header>
targetElement.innerHTML = '<p>Type in the field below to search in the grid</p>';
const searchField = new TextField({
appendTo : targetElement,
label : 'Search',
icon : 'b-icon b-icon-search',
value : 'on',
style : 'margin-bottom: 1em',
onInput : () => grid.features.search.search(searchField.value)
});
// grid with Search feature
const grid = new Grid({
appendTo : targetElement,
// makes grid as high as it needs to be to fit rows
autoHeight : true,
features : {
// enable searching
search : true
},
data : DataGenerator.generateData(5),
columns : [
{ field : 'name', text : 'Name', flex : 1 },
{ field : 'city', text : 'City', flex : 1 }
]
});
// initial search
grid.features.search.search(searchField.value);Feature that allows the user to search the entire grid. Navigate between hits using the keyboard, [F3] or [Ctrl/CMD + G] moves to next, also pressing [Shift] moves to previous.
Note that this feature does not include a UI, please build your own and call appropriate methods in the feature. For a demo implementation, see Search example.
This feature is disabled by default.
Keyboard shortcuts
This feature has the following default keyboard shortcuts:
| Keys | Action | Action description |
|---|---|---|
F3 |
goToNextHit | Move focus to next search hit |
Shift+F3 |
goToPrevHit | Move focus to previous search hit |
Ctrl+G |
goToNextHit | Move focus to next search hit |
Ctrl+Shift+G |
goToPrevHit | Move focus to previous search hit |
Ctrl is the equivalent to Command and Alt
is the equivalent to Option for Mac usersFor more information on how to customize keyboard shortcuts, please see our guide
// enable Search
let grid = new Grid({
features : {
search : true
}
});
// perform search
grid.features.search.search('steve');
Configs
12
Configs
12Other
See Keyboard shortcuts for details
The maximum amount of search hits
Set to false to not show the search hit index numbers
Misc
Properties
17
Properties
17Common
Class hierarchy
Other
Number of results found
Returns true if focused row is a hit
Functions
35
Functions
35Other
Clears search results.
Go to the first hit.
Go to the last hit.
Select the next hit, scrolling it into view. Triggered with [f3] or [ctrl]/[cmd] + [g].
Select the previous hit, scrolling it into view. Triggered with [shift] + [f3] or [shift] + [ctrl]/[cmd] + [g].
Performs a search and highlights hits.
| Parameter | Type | Description |
|---|---|---|
text | String | Text to search for |
gotoHit | Boolean | Go to first hit after search |
reapply | Boolean | Pass true to force search |
fields | String[] | An array of the fields to search for the value in |