Skip to content

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.

ts
const result = api.find('Seoul'); // { text, count, active, hits }
api.findNext(); // next cell: focus it and scroll it into view
api.clearFind(); // clear

Methods and event ​

NameBehavior
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 ​

TargetRule
RowsThe visible rows after sort, filter and quick filter; collapsed tree branches and rows on other pages are not searched
ColumnsVisible columns in display order (start-pinned, middle, end-pinned); columns also reaches hidden columns
OrderRow first, then column order inside the row
TextThe 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).

OptionValueDefaultEffect
columnsarray of column idsall visible columnsColumns to search; an unknown id is an invalid-option
text'shown' · 'value''shown'Displayed text or the stored value
caseSensitivebooleanfalseDistinguishes case
wholeCellbooleanfalseMatches only when the whole cell equals the text (outer spaces ignored). A column with searchBy is compared with that text
highlightbooleantrueAdds 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) ​

ts
{ 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.

See also ​