Skip to content

Search

Find matching cells, step through matches, and replace text from code or with Ctrl+F.
On this page

grid.search(query, opts?) scans cells, highlights every match, scrolls the first match into view, and emits a search event.

Find matching cells
const result = grid.search("error");
console.log(`${result.matches.length} match(es)`); // "2 match(es)"
ABCD
1LogMessageSourceDetail
2Job 1errorImportInvalid file
3Job 2OKImportComplete
4Job 3OKExportComplete
5Job 4OKImportComplete
6Job 5OKExportComplete
7Job 6FailedExporterror
Result: B2 is the active match and D7 is also highlighted; values are unchanged. The static controls show the equivalent Ctrl+F view after entering “error”; calling grid.search alone does not open the widget.
Usage example (requires an initialized grid)

This API excerpt needs an initialized grid. Populate its first seven rows with the log cells above, using plain "error" in B2 and D7. The final call clears the search highlights, not the values.

Find, step, and clear
const result = grid.search("error");
console.log(`${result.matches.length} match(es)`);
grid.findNext(); // advance the active match and scroll to it
grid.clearSearch(); // remove the highlights when done

If cells B2 and D7 contain "error", the log shows 2 match(es). result.matches is [B2, D7] as zero-based addresses, and result.active is 0.

findNext() and findPrev() move the active match. clearSearch() clears the highlights. The built-in Ctrl+F find widget, gated by config.find (on by default), drives this same API.

Options and result

SearchOptions and SearchResult
interface SearchOptions {
matchCase?: boolean; // case-sensitive match (default false)
wholeCell?: boolean; // match the whole cell, not a substring (default false)
sheet?: SheetId; // restrict to one sheet (default: the active sheet)
columns?: number[]; // restrict to these column indices (default: all)
}
interface SearchResult {
query: string;
matches: CellAddress[]; // matching cells, in row-major order
active: number; // index of the active match, or -1 when there are none
}
MethodPurpose
search(query, opts?)Find matching cells; highlights them, emits search, returns a SearchResult.
findNext() / findPrev()Step the active match forward / backward and scroll it into view.
clearSearch()Drop the current search and clear its highlights.
replaceCurrent(replacement) / replaceAll(replacement)Replace literal text/number matches through undoable transactions.

Edge cases and limits

  • An active search picks up matches that a value edit adds or removes, without scrolling.
  • On sheets with formulas or references, an active search rescans after each edit, including edits to off-screen inputs or other sheets. This keeps matches whose computed text changes.
  • highlightCells(ranges, color?) highlights arbitrary ranges independently of search. Pass null to clear; color overrides the theme highlight color. See Temporary highlights.
  • Set config.find: false to turn off the Ctrl+F widget. The methods still work.

See also

Documentation