Find
api.find(text) finds text in the visible rows, marks the found cells and lets you move between them with findNext() and findPrev() (1.4.0). It does not filter or hide rows, unlike the quick filter. Without a find call the DOM and the cost stay as they are.
const result = api.find('Seoul'); // { text, count, active, hits }
api.findNext(); // next cell: focus it and scroll it into view
api.clearFind(); // clearMethods and event
| Name | Behavior |
|---|---|
find(text, options?) | Finds and returns the result; the first cell is active and scrolled into view but not focused; an empty text clears |
findNext() · findPrev() | Moves the active cell in row order, focuses it and scrolls to it; wraps at the ends |
clearFind() | Clears the find and removes the marks |
getFindResult() | The last result; null when nothing was found yet or it was cleared |
findChanged event | { text, active, count } when a find, a move, a clear or a recompute changes the result |
The result is { text, count, active, hits }. active is 0-based and -1 when none, and hits is a list of { rowKey, columnId }. Changing the returned object does not change the internal state.
Where it looks
| Target | Rule |
|---|---|
| Rows | The visible rows after sort, filter and quick filter; collapsed tree branches and rows on other pages are not searched |
| Columns | Visible columns in display order (start-pinned, middle, end-pinned); columns also reaches hidden columns |
| Order | Row first, then column order inside the row |
| Text | The displayed text by default (formatValue, optionLabel, multiselect labels); text: 'value' uses the stored value |
Options
The second argument of find(text, options), and the grid option find gives defaults (the call arguments win).
| Option | Value | Default | Effect |
|---|---|---|---|
columns | array of column ids | all visible columns | Columns to search; an unknown id is an invalid-option |
text | 'shown' · 'value' | 'shown' | Displayed text or the stored value |
caseSensitive | boolean | false | Distinguishes case |
wholeCell | boolean | false | Matches only when the whole cell equals the text (outer spaces ignored). A column with searchBy is compared with that text |
highlight | boolean | true | Adds the mark classes to found cells; false returns the result without marks |
An unknown key or a wrong value is an invalid-option, and the current find state is not changed.
Text per column (searchBy)
{ id: 'city', searchBy: (row, { value }) => `${value} ${row.cityAlias}` }searchBy returns the text searched in that column. Find and the quick filter read the same text. If the function throws, an error event (callback-error) is reported and that cell counts as a non-match.
Marks
Found cells get mxg-find-hit and the pointed cell also gets mxg-find-active. The mark is a cell-wide background and line, and text is never split. Colours are theme tokens (--mxg-bg-find-hit, --mxg-border-find-hit, --mxg-bg-find-active, --mxg-border-find-active); background and line together mean the marks are not told apart by colour alone (an outline in forced-colors mode).
It finds again when things change
A sort, a filter, replacing, adding or removing rows, a column change, expanding or collapsing, grouping and a page change recompute the find once per tick. The active cell stays when the same cell is still there, otherwise it moves to the nearest following cell. destroy() clears the result.
Gallery example: find-basic
Gallery example: find-next-prev
Gallery example: find-columns