글자를 찾아 칸 표시하기Find text and mark the cells
api.find(text)는 보이는 행과 컬럼의 화면 글자에서 글자를 찾아 찾은 칸을 표시하고 { count, active, hits }를 돌려줘요. 행을 거르는 필터와 달리 표는 그대로이고, 부서처럼 optionLabel로 보이는 글자도 찾아요. 빈 글자는 지우기예요. 찾으면 활성 칸이 화면에 보이도록 스크롤돼요.api.find(text) searches the displayed text of the visible rows and columns, marks the found cells and returns { count, active, hits }. Unlike a filter it keeps all rows, and it finds shown text such as an optionLabel. An empty text clears. The active cell is scrolled into view.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<input
type="text"
aria-label="찾기"
placeholder="찾을 글자 (예: 김, 개발)"
id="search"
/>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('search').addEventListener('input', (event) => actions.search(api, event.target.value));const rows = [
{ id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// api.find(text)는 보이는 행의 화면 글자에서 글자를 찾아 칸을 표시해요(찾은 칸 노란색, 활성 칸 주황색).
// 행을 거르거나 숨기지 않아서 빠른 필터와 달라요. 부서 칸은 저장 값(dev)이 아니라 화면 글자(개발)로 찾아요.
export const options = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{ id: 'city', title: '도시', width: 90 },
{
id: 'dept',
title: '부서',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'memo', title: '메모', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '위 입력칸에 글자를 치면 찾은 칸이 표시돼요. "개발"도 찾아져요(화면 글자).',
en: 'Type in the box above and the found cells are marked. "개발" (Development) is found too: it searches the displayed text.',
});
const off = api.on('findChanged', (e) => log({
ko: e.text === ''
? '찾기를 지웠어요.'
: `"${e.text}": ${e.count}칸 찾음, 활성 ${e.active + 1}번째`,
en: e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
}));
return off;
}
export const actions = {
search: (api, value) => void api.find((value ?? '').trim()),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>글자를 찾아 칸 표시하기</title>
</head>
<body>
<div class="toolbar">
<input
type="text"
aria-label="찾기"
placeholder="찾을 글자 (예: 김, 개발)"
id="search"
/>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// api.find(text)는 보이는 행의 화면 글자에서 글자를 찾아 칸을 표시해요(찾은 칸 노란색, 활성 칸 주황색).
// 행을 거르거나 숨기지 않아서 빠른 필터와 달라요. 부서 칸은 저장 값(dev)이 아니라 화면 글자(개발)로 찾아요.
const options = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{ id: 'city', title: '도시', width: 90 },
{
id: 'dept',
title: '부서',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'memo', title: '메모', width: 200 },
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '위 입력칸에 글자를 치면 찾은 칸이 표시돼요. "개발"도 찾아져요(화면 글자).',
en: 'Type in the box above and the found cells are marked. "개발" (Development) is found too: it searches the displayed text.',
});
const off = api.on('findChanged', (e) => log({
ko: e.text === ''
? '찾기를 지웠어요.'
: `"${e.text}": ${e.count}칸 찾음, 활성 ${e.active + 1}번째`,
en: e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
}));
return off;
}
const actions = {
search: (api, value) => void api.find((value ?? '').trim()),
};
options.ariaLabel = "글자를 찾아 칸 표시하기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('search').addEventListener('input', (event) => actions.search(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<input
type="text"
aria-label="찾기"
placeholder="찾을 글자 (예: 김, 개발)"
disabled={!api}
onChange={(event) => api && actions.search(api, event.target.value)}
/>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// api.find(text)는 보이는 행의 화면 글자에서 글자를 찾아 칸을 표시해요(찾은 칸 노란색, 활성 칸 주황색).
// 행을 거르거나 숨기지 않아서 빠른 필터와 달라요. 부서 칸은 저장 값(dev)이 아니라 화면 글자(개발)로 찾아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{ id: 'city', title: '도시', width: 90 },
{
id: 'dept',
title: '부서',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'memo', title: '메모', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '위 입력칸에 글자를 치면 찾은 칸이 표시돼요. "개발"도 찾아져요(화면 글자).',
en: 'Type in the box above and the found cells are marked. "개발" (Development) is found too: it searches the displayed text.',
});
const off = api.on('findChanged', (e) =>
log({
ko:
e.text === ''
? '찾기를 지웠어요.'
: `"${e.text}": ${e.count}칸 찾음, 활성 ${e.active + 1}번째`,
en:
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
}),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<input
type="text"
aria-label="찾기"
placeholder="찾을 글자 (예: 김, 개발)"
:disabled="!api"
@input="api && actions.search(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// api.find(text)는 보이는 행의 화면 글자에서 글자를 찾아 칸을 표시해요(찾은 칸 노란색, 활성 칸 주황색).
// 행을 거르거나 숨기지 않아서 빠른 필터와 달라요. 부서 칸은 저장 값(dev)이 아니라 화면 글자(개발)로 찾아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{ id: 'city', title: '도시', width: 90 },
{
id: 'dept',
title: '부서',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'memo', title: '메모', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '위 입력칸에 글자를 치면 찾은 칸이 표시돼요. "개발"도 찾아져요(화면 글자).',
en: 'Type in the box above and the found cells are marked. "개발" (Development) is found too: it searches the displayed text.',
});
const off = api.on('findChanged', (e) =>
log({
ko:
e.text === ''
? '찾기를 지웠어요.'
: `"${e.text}": ${e.count}칸 찾음, 활성 ${e.active + 1}번째`,
en:
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
}),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<input
type="text"
aria-label="찾기"
placeholder="찾을 글자 (예: 김, 개발)"
[disabled]="!api"
(input)="api && actions.search(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', dept: 'ops', memo: '' },
];
// api.find(text)는 보이는 행의 화면 글자에서 글자를 찾아 칸을 표시해요(찾은 칸 노란색, 활성 칸 주황색).
// 행을 거르거나 숨기지 않아서 빠른 필터와 달라요. 부서 칸은 저장 값(dev)이 아니라 화면 글자(개발)로 찾아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{ id: 'city', title: '도시', width: 90 },
{
id: 'dept',
title: '부서',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'memo', title: '메모', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '위 입력칸에 글자를 치면 찾은 칸이 표시돼요. "개발"도 찾아져요(화면 글자).',
en: 'Type in the box above and the found cells are marked. "개발" (Development) is found too: it searches the displayed text.',
});
const off = api.on('findChanged', (e) =>
log({
ko:
e.text === ''
? '찾기를 지웠어요.'
: `"${e.text}": ${e.count}칸 찾음, 활성 ${e.active + 1}번째`,
en:
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
}),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<input
type="text"
aria-label="Find"
placeholder="Text to find (e.g. Clark, Development)"
id="search"
/>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('search').addEventListener('input', (event) => actions.search(api, event.target.value));const rows = [
{ id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
{ id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{ id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
{ id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{ id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
{ id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// api.find(text) searches the displayed text of the visible rows and marks the cells (found cells yellow, active cell orange).
// It does not filter or hide rows, unlike quick filter. The dept column is searched by its displayed text (Development), not the stored value (dev).
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{ id: 'city', title: 'City', width: 90 },
{
id: 'dept',
title: 'Dept',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'memo', title: 'Memo', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Type in the box above and the found cells are marked. "Development" is found too: it searches the displayed text.');
const off = api.on('findChanged', (e) => log(e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`));
return off;
}
export const actions = {
search: (api, value) => void api.find((value ?? '').trim()),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Find text and mark the cells</title>
</head>
<body>
<div class="toolbar">
<input
type="text"
aria-label="Find"
placeholder="Text to find (e.g. Clark, Development)"
id="search"
/>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
{ id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{ id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
{ id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{ id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
{ id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// api.find(text) searches the displayed text of the visible rows and marks the cells (found cells yellow, active cell orange).
// It does not filter or hide rows, unlike quick filter. The dept column is searched by its displayed text (Development), not the stored value (dev).
const options = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{ id: 'city', title: 'City', width: 90 },
{
id: 'dept',
title: 'Dept',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'memo', title: 'Memo', width: 200 },
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Type in the box above and the found cells are marked. "Development" is found too: it searches the displayed text.');
const off = api.on('findChanged', (e) => log(e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`));
return off;
}
const actions = {
search: (api, value) => void api.find((value ?? '').trim()),
};
options.ariaLabel = "Find text and mark the cells";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('search').addEventListener('input', (event) => actions.search(api, event.target.value));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<input
type="text"
aria-label="Find"
placeholder="Text to find (e.g. Clark, Development)"
disabled={!api}
onChange={(event) => api && actions.search(api, event.target.value)}
/>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
{ id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{ id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
{ id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{ id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
{ id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// api.find(text) searches the displayed text of the visible rows and marks the cells (found cells yellow, active cell orange).
// It does not filter or hide rows, unlike quick filter. The dept column is searched by its displayed text (Development), not the stored value (dev).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{ id: 'city', title: 'City', width: 90 },
{
id: 'dept',
title: 'Dept',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'memo', title: 'Memo', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Type in the box above and the found cells are marked. "Development" is found too: it searches the displayed text.',
);
const off = api.on('findChanged', (e) =>
log(
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<input
type="text"
aria-label="Find"
placeholder="Text to find (e.g. Clark, Development)"
:disabled="!api"
@input="api && actions.search(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
{ id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{ id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
{ id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{ id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
{ id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// api.find(text) searches the displayed text of the visible rows and marks the cells (found cells yellow, active cell orange).
// It does not filter or hide rows, unlike quick filter. The dept column is searched by its displayed text (Development), not the stored value (dev).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{ id: 'city', title: 'City', width: 90 },
{
id: 'dept',
title: 'Dept',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'memo', title: 'Memo', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Type in the box above and the found cells are marked. "Development" is found too: it searches the displayed text.',
);
const off = api.on('findChanged', (e) =>
log(
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<input
type="text"
aria-label="Find"
placeholder="Text to find (e.g. Clark, Development)"
[disabled]="!api"
(input)="api && actions.search(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
city: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: 'Emma Clark', city: 'Austin', dept: 'dev', memo: 'Meeting with team lead Clark' },
{ id: 2, name: 'Liam Carter', city: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{ id: 4, name: 'Noah Clarke', city: 'Clarksville', dept: 'ops', memo: 'Kim joins the team' },
{ id: 5, name: 'Ava Brooks', city: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{ id: 7, name: 'Mia Foster', city: 'Portland', dept: 'dev', memo: 'Sent to the Austin HQ' },
{ id: 8, name: 'Lucas Reed', city: 'Denver', dept: 'ops', memo: '' },
];
// api.find(text) searches the displayed text of the visible rows and marks the cells (found cells yellow, active cell orange).
// It does not filter or hide rows, unlike quick filter. The dept column is searched by its displayed text (Development), not the stored value (dev).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{ id: 'city', title: 'City', width: 90 },
{
id: 'dept',
title: 'Dept',
width: 90,
kind: 'select',
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'memo', title: 'Memo', width: 200 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Type in the box above and the found cells are marked. "Development" is found too: it searches the displayed text.',
);
const off = api.on('findChanged', (e) =>
log(
e.text === ''
? 'Find cleared.'
: `"${e.text}": ${e.count} cells found, active ${e.active + 1}`,
),
);
return off;
}
export const actions = {
search: (api: GridApi<Row>, value?: string) => void api.find((value ?? '').trim()),
};