찾을 컬럼과 방식 고르기Choose the columns and the way to search
find(text, options)의 columns로 찾을 컬럼을, text로 화면 글자('shown')나 저장 값('value')을, caseSensitive·wholeCell로 대소문자와 칸 전체 일치를 정해요. 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정하고 빠른 필터도 같은 글자를 봐요. 옵션 find로 기본값을 줄 수 있어요.The options of find(text, options) choose the columns (columns), the displayed text ('shown') or the stored value ('value') (text), and case and whole-cell matching (caseSensitive, wholeCell). A column's searchBy sets the text searched in that column, and quick filter reads the same text. The find option gives defaults.
코드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">
<button type="button" id="nameOnly">이름만</button>
<button type="button" id="value">저장 값(dev)</button>
<button type="button" id="shown">화면 글자(개발)</button>
<button type="button" id="whole">칸 전체 일치</button>
<button type="button" id="searchBy">searchBy(seoul)</button>
<button type="button" id="caseSensitive">대소문자 구분</button>
</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('nameOnly').addEventListener('click', () => actions.nameOnly(api));
document.getElementById('value').addEventListener('click', () => actions.value(api));
document.getElementById('shown').addEventListener('click', () => actions.shown(api));
document.getElementById('whole').addEventListener('click', () => actions.whole(api));
document.getElementById('searchBy').addEventListener('click', () => actions.searchBy(api));
document.getElementById('caseSensitive').addEventListener('click', () => actions.caseSensitive(api));const rows = [
{ id: 1, name: '김하늘', city: '서울', office: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', office: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', office: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', office: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', office: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', office: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', office: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', office: '부산', dept: 'ops', memo: '' },
];
// find(text, options)의 options: columns(찾을 컬럼), text('shown' 화면 글자 | 'value' 저장 값), caseSensitive, wholeCell.
// 칸 전체 일치(wholeCell)는 그 칸에서 찾는 글자(searchBy가 있으면 그 글자)와 견줘요.
// 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정해요(여기서는 도시 칸에 "서울특별시" 같은 별칭을 더해요).
export const options = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{
id: 'city',
title: '도시',
width: 90,
searchBy: (row) => `${row.city}${row.city === '서울' ? ' 서울특별시 seoul' : ''}`,
},
{ id: 'office', title: '근무지', width: 90 }, // searchBy가 없는 칸: 칸 전체 일치는 보이는 글자 그대로 견줘요
{
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',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({
ko: '버튼마다 다른 찾기 옵션을 써요. 결과 개수가 로그에 나와요.',
en: 'Each button uses different find options. The log shows the count.',
});
}
function show(text, count) {
const t = typeof text === 'string' ? { ko: text, en: text } : text;
say({ ko: `"${t.ko}" → ${count}칸`, en: `"${t.en}" → ${count} cells` });
}
export const actions = {
nameOnly: (api) => show({ ko: '김 (이름만)', en: '김 (name column only)' }, api.find('김', { columns: ['name'] }).count),
value: (api) => show({ ko: 'dev (저장 값)', en: 'dev (stored value)' }, api.find('dev', { text: 'value' }).count),
shown: (api) => show({ ko: '개발 (화면 글자)', en: '개발 (shown text)' }, api.find('개발').count),
whole: (api) => {
show({ ko: '서울 (칸 전체 일치, 근무지)', en: '서울 (whole cell, office column)' }, api.find('서울', { wholeCell: true, columns: ['office'] }).count);
// 도시 칸은 searchBy가 "서울 서울특별시 seoul"을 돌려주니 전체 일치가 아니에요.
show({
ko: '서울 (칸 전체 일치, 도시: searchBy 글자와 견줌)',
en: '서울 (whole cell, city: compared with its searchBy text)',
}, api.find('서울', { wholeCell: true, columns: ['city'] }).count);
},
searchBy: (api) => show({ ko: 'seoul (searchBy)', en: 'seoul (searchBy text)' }, api.find('seoul').count),
caseSensitive: (api) => show({ ko: 'KIM (대소문자 구분)', en: 'KIM (case-sensitive)' }, api.find('KIM', { caseSensitive: true }).count),
};<!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">
<button type="button" id="nameOnly">이름만</button>
<button type="button" id="value">저장 값(dev)</button>
<button type="button" id="shown">화면 글자(개발)</button>
<button type="button" id="whole">칸 전체 일치</button>
<button type="button" id="searchBy">searchBy(seoul)</button>
<button type="button" id="caseSensitive">대소문자 구분</button>
</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: '서울', office: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', office: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', office: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', office: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', office: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', office: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', office: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', office: '부산', dept: 'ops', memo: '' },
];
// find(text, options)의 options: columns(찾을 컬럼), text('shown' 화면 글자 | 'value' 저장 값), caseSensitive, wholeCell.
// 칸 전체 일치(wholeCell)는 그 칸에서 찾는 글자(searchBy가 있으면 그 글자)와 견줘요.
// 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정해요(여기서는 도시 칸에 "서울특별시" 같은 별칭을 더해요).
const options = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{
id: 'city',
title: '도시',
width: 90,
searchBy: (row) => `${row.city}${row.city === '서울' ? ' 서울특별시 seoul' : ''}`,
},
{ id: 'office', title: '근무지', width: 90 }, // searchBy가 없는 칸: 칸 전체 일치는 보이는 글자 그대로 견줘요
{
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',
};
let say = () => { };
function setup(_api, log) {
say = log;
log({
ko: '버튼마다 다른 찾기 옵션을 써요. 결과 개수가 로그에 나와요.',
en: 'Each button uses different find options. The log shows the count.',
});
}
function show(text, count) {
const t = typeof text === 'string' ? { ko: text, en: text } : text;
say({ ko: `"${t.ko}" → ${count}칸`, en: `"${t.en}" → ${count} cells` });
}
const actions = {
nameOnly: (api) => show({ ko: '김 (이름만)', en: '김 (name column only)' }, api.find('김', { columns: ['name'] }).count),
value: (api) => show({ ko: 'dev (저장 값)', en: 'dev (stored value)' }, api.find('dev', { text: 'value' }).count),
shown: (api) => show({ ko: '개발 (화면 글자)', en: '개발 (shown text)' }, api.find('개발').count),
whole: (api) => {
show({ ko: '서울 (칸 전체 일치, 근무지)', en: '서울 (whole cell, office column)' }, api.find('서울', { wholeCell: true, columns: ['office'] }).count);
// 도시 칸은 searchBy가 "서울 서울특별시 seoul"을 돌려주니 전체 일치가 아니에요.
show({
ko: '서울 (칸 전체 일치, 도시: searchBy 글자와 견줌)',
en: '서울 (whole cell, city: compared with its searchBy text)',
}, api.find('서울', { wholeCell: true, columns: ['city'] }).count);
},
searchBy: (api) => show({ ko: 'seoul (searchBy)', en: 'seoul (searchBy text)' }, api.find('seoul').count),
caseSensitive: (api) => show({ ko: 'KIM (대소문자 구분)', en: 'KIM (case-sensitive)' }, api.find('KIM', { caseSensitive: true }).count),
};
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('nameOnly').addEventListener('click', () => actions.nameOnly(api));
document.getElementById('value').addEventListener('click', () => actions.value(api));
document.getElementById('shown').addEventListener('click', () => actions.shown(api));
document.getElementById('whole').addEventListener('click', () => actions.whole(api));
document.getElementById('searchBy').addEventListener('click', () => actions.searchBy(api));
document.getElementById('caseSensitive').addEventListener('click', () => actions.caseSensitive(api));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.nameOnly(api)}
>이름만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.value(api)}
>저장 값(dev)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shown(api)}
>화면 글자(개발)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.whole(api)}
>칸 전체 일치</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.searchBy(api)}
>searchBy(seoul)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.caseSensitive(api)}
>대소문자 구분</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', office: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', office: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', office: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', office: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', office: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', office: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', office: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', office: '부산', dept: 'ops', memo: '' },
];
// find(text, options)의 options: columns(찾을 컬럼), text('shown' 화면 글자 | 'value' 저장 값), caseSensitive, wholeCell.
// 칸 전체 일치(wholeCell)는 그 칸에서 찾는 글자(searchBy가 있으면 그 글자)와 견줘요.
// 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정해요(여기서는 도시 칸에 "서울특별시" 같은 별칭을 더해요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{
id: 'city',
title: '도시',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === '서울' ? ' 서울특별시 seoul' : ''}`,
},
{ id: 'office', title: '근무지', width: 90 }, // searchBy가 없는 칸: 칸 전체 일치는 보이는 글자 그대로 견줘요
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼마다 다른 찾기 옵션을 써요. 결과 개수가 로그에 나와요.',
en: 'Each button uses different find options. The log shows the count.',
});
}
function show(text: string | { ko: string; en: string }, count: number): void {
const t = typeof text === 'string' ? { ko: text, en: text } : text;
say({ ko: `"${t.ko}" → ${count}칸`, en: `"${t.en}" → ${count} cells` });
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show(
{ ko: '김 (이름만)', en: '김 (name column only)' },
api.find('김', { columns: ['name'] }).count,
),
value: (api: GridApi<Row>) =>
show(
{ ko: 'dev (저장 값)', en: 'dev (stored value)' },
api.find('dev', { text: 'value' }).count,
),
shown: (api: GridApi<Row>) =>
show({ ko: '개발 (화면 글자)', en: '개발 (shown text)' }, api.find('개발').count),
whole: (api: GridApi<Row>) => {
show(
{ ko: '서울 (칸 전체 일치, 근무지)', en: '서울 (whole cell, office column)' },
api.find('서울', { wholeCell: true, columns: ['office'] }).count,
);
// 도시 칸은 searchBy가 "서울 서울특별시 seoul"을 돌려주니 전체 일치가 아니에요.
show(
{
ko: '서울 (칸 전체 일치, 도시: searchBy 글자와 견줌)',
en: '서울 (whole cell, city: compared with its searchBy text)',
},
api.find('서울', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) =>
show({ ko: 'seoul (searchBy)', en: 'seoul (searchBy text)' }, api.find('seoul').count),
caseSensitive: (api: GridApi<Row>) =>
show(
{ ko: 'KIM (대소문자 구분)', en: 'KIM (case-sensitive)' },
api.find('KIM', { caseSensitive: true }).count,
),
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
:disabled="!api"
@click="api && actions.nameOnly(api)"
>이름만</button>
<button type="button" :disabled="!api" @click="api && actions.value(api)">저장 값(dev)</button>
<button type="button" :disabled="!api" @click="api && actions.shown(api)">화면 글자(개발)</button>
<button type="button" :disabled="!api" @click="api && actions.whole(api)">칸 전체 일치</button>
<button
type="button"
:disabled="!api"
@click="api && actions.searchBy(api)"
>searchBy(seoul)</button>
<button
type="button"
:disabled="!api"
@click="api && actions.caseSensitive(api)"
>대소문자 구분</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', office: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', office: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', office: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', office: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', office: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', office: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', office: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', office: '부산', dept: 'ops', memo: '' },
];
// find(text, options)의 options: columns(찾을 컬럼), text('shown' 화면 글자 | 'value' 저장 값), caseSensitive, wholeCell.
// 칸 전체 일치(wholeCell)는 그 칸에서 찾는 글자(searchBy가 있으면 그 글자)와 견줘요.
// 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정해요(여기서는 도시 칸에 "서울특별시" 같은 별칭을 더해요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{
id: 'city',
title: '도시',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === '서울' ? ' 서울특별시 seoul' : ''}`,
},
{ id: 'office', title: '근무지', width: 90 }, // searchBy가 없는 칸: 칸 전체 일치는 보이는 글자 그대로 견줘요
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼마다 다른 찾기 옵션을 써요. 결과 개수가 로그에 나와요.',
en: 'Each button uses different find options. The log shows the count.',
});
}
function show(text: string | { ko: string; en: string }, count: number): void {
const t = typeof text === 'string' ? { ko: text, en: text } : text;
say({ ko: `"${t.ko}" → ${count}칸`, en: `"${t.en}" → ${count} cells` });
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show(
{ ko: '김 (이름만)', en: '김 (name column only)' },
api.find('김', { columns: ['name'] }).count,
),
value: (api: GridApi<Row>) =>
show(
{ ko: 'dev (저장 값)', en: 'dev (stored value)' },
api.find('dev', { text: 'value' }).count,
),
shown: (api: GridApi<Row>) =>
show({ ko: '개발 (화면 글자)', en: '개발 (shown text)' }, api.find('개발').count),
whole: (api: GridApi<Row>) => {
show(
{ ko: '서울 (칸 전체 일치, 근무지)', en: '서울 (whole cell, office column)' },
api.find('서울', { wholeCell: true, columns: ['office'] }).count,
);
// 도시 칸은 searchBy가 "서울 서울특별시 seoul"을 돌려주니 전체 일치가 아니에요.
show(
{
ko: '서울 (칸 전체 일치, 도시: searchBy 글자와 견줌)',
en: '서울 (whole cell, city: compared with its searchBy text)',
},
api.find('서울', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) =>
show({ ko: 'seoul (searchBy)', en: 'seoul (searchBy text)' }, api.find('seoul').count),
caseSensitive: (api: GridApi<Row>) =>
show(
{ ko: 'KIM (대소문자 구분)', en: 'KIM (case-sensitive)' },
api.find('KIM', { caseSensitive: true }).count,
),
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.nameOnly(api)"
>이름만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.value(api)"
>저장 값(dev)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shown(api)"
>화면 글자(개발)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.whole(api)"
>칸 전체 일치</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.searchBy(api)"
>searchBy(seoul)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.caseSensitive(api)"
>대소문자 구분</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{ id: 1, name: '김하늘', city: '서울', office: '서울', dept: 'dev', memo: '김 팀장님과 면담' },
{ id: 2, name: '이도윤', city: '부산', office: '부산', dept: 'ops', memo: '' },
{ id: 3, name: '박서연', city: '서울', office: '서울', dept: 'dev', memo: '서울 출장 예정' },
{ id: 4, name: '김해린', city: '김해', office: '김해', dept: 'ops', memo: 'Kim 팀 합류' },
{ id: 5, name: '최지우', city: '대전', office: '대전', dept: 'dev', memo: '' },
{ id: 6, name: '정민준', city: '서울', office: '서울', dept: 'ops', memo: '김밥 주문 담당' },
{ id: 7, name: '강서윤', city: '광주', office: '광주', dept: 'dev', memo: '서울 본사 파견' },
{ id: 8, name: '조현우', city: '부산', office: '부산', dept: 'ops', memo: '' },
];
// find(text, options)의 options: columns(찾을 컬럼), text('shown' 화면 글자 | 'value' 저장 값), caseSensitive, wholeCell.
// 칸 전체 일치(wholeCell)는 그 칸에서 찾는 글자(searchBy가 있으면 그 글자)와 견줘요.
// 컬럼의 searchBy는 그 컬럼에서 찾을 글자를 직접 정해요(여기서는 도시 칸에 "서울특별시" 같은 별칭을 더해요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 100 },
{
id: 'city',
title: '도시',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === '서울' ? ' 서울특별시 seoul' : ''}`,
},
{ id: 'office', title: '근무지', width: 90 }, // searchBy가 없는 칸: 칸 전체 일치는 보이는 글자 그대로 견줘요
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼마다 다른 찾기 옵션을 써요. 결과 개수가 로그에 나와요.',
en: 'Each button uses different find options. The log shows the count.',
});
}
function show(text: string | { ko: string; en: string }, count: number): void {
const t = typeof text === 'string' ? { ko: text, en: text } : text;
say({ ko: `"${t.ko}" → ${count}칸`, en: `"${t.en}" → ${count} cells` });
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show(
{ ko: '김 (이름만)', en: '김 (name column only)' },
api.find('김', { columns: ['name'] }).count,
),
value: (api: GridApi<Row>) =>
show(
{ ko: 'dev (저장 값)', en: 'dev (stored value)' },
api.find('dev', { text: 'value' }).count,
),
shown: (api: GridApi<Row>) =>
show({ ko: '개발 (화면 글자)', en: '개발 (shown text)' }, api.find('개발').count),
whole: (api: GridApi<Row>) => {
show(
{ ko: '서울 (칸 전체 일치, 근무지)', en: '서울 (whole cell, office column)' },
api.find('서울', { wholeCell: true, columns: ['office'] }).count,
);
// 도시 칸은 searchBy가 "서울 서울특별시 seoul"을 돌려주니 전체 일치가 아니에요.
show(
{
ko: '서울 (칸 전체 일치, 도시: searchBy 글자와 견줌)',
en: '서울 (whole cell, city: compared with its searchBy text)',
},
api.find('서울', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) =>
show({ ko: 'seoul (searchBy)', en: 'seoul (searchBy text)' }, api.find('seoul').count),
caseSensitive: (api: GridApi<Row>) =>
show(
{ ko: 'KIM (대소문자 구분)', en: 'KIM (case-sensitive)' },
api.find('KIM', { caseSensitive: true }).count,
),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="nameOnly">Name only</button>
<button type="button" id="value">Stored value (dev)</button>
<button type="button" id="shown">Displayed text</button>
<button type="button" id="whole">Whole cell</button>
<button type="button" id="searchBy">searchBy (atx)</button>
<button type="button" id="caseSensitive">Case sensitive</button>
</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('nameOnly').addEventListener('click', () => actions.nameOnly(api));
document.getElementById('value').addEventListener('click', () => actions.value(api));
document.getElementById('shown').addEventListener('click', () => actions.shown(api));
document.getElementById('whole').addEventListener('click', () => actions.whole(api));
document.getElementById('searchBy').addEventListener('click', () => actions.searchBy(api));
document.getElementById('caseSensitive').addEventListener('click', () => actions.caseSensitive(api));const rows = [
{
id: 1,
name: 'Emma Clark',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Meeting with team lead Clark',
},
{ id: 2, name: 'Liam Carter', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{
id: 4,
name: 'Noah Clarke',
city: 'Clarksville',
office: 'Clarksville',
dept: 'ops',
memo: 'Kim joins the team',
},
{ id: 5, name: 'Ava Brooks', city: 'Seattle', office: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
office: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{
id: 7,
name: 'Mia Foster',
city: 'Portland',
office: 'Portland',
dept: 'dev',
memo: 'Sent to the Austin HQ',
},
{ id: 8, name: 'Lucas Reed', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
];
// Options of find(text, options): columns (columns to search), text ('shown' displayed text | 'value' stored value), caseSensitive, wholeCell.
// wholeCell compares with the text searched in that cell (the column's searchBy text if it has one).
// A column's searchBy sets the text searched in that column (here the city column gets an alias such as "Austin, Texas").
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{
id: 'city',
title: 'City',
width: 90,
searchBy: (row) => `${row.city}${row.city === 'Austin' ? ' Austin, Texas atx' : ''}`,
},
{ id: 'office', title: 'Office', width: 90 }, // no searchBy: wholeCell compares with the shown text
{
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',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log('Each button uses different find options. The log shows the count.');
}
function show(text, count) {
say(`"${text}" → ${count} cells`);
}
export const actions = {
nameOnly: (api) => show('Clark (name column only)', api.find('Clark', { columns: ['name'] }).count),
value: (api) => show('dev (stored value)', api.find('dev', { text: 'value' }).count),
shown: (api) => show('Development (shown text)', api.find('Development').count),
whole: (api) => {
show('Austin (whole cell, office column)', api.find('Austin', { wholeCell: true, columns: ['office'] }).count);
// The city column's searchBy returns "Austin Austin, Texas atx", so it is not a whole-cell match.
show('Austin (whole cell, city: compared with its searchBy text)', api.find('Austin', { wholeCell: true, columns: ['city'] }).count);
},
searchBy: (api) => show('atx (searchBy text)', api.find('atx').count),
caseSensitive: (api) => show('KIM (case-sensitive)', api.find('KIM', { caseSensitive: true }).count),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Choose the columns and the way to search</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="nameOnly">Name only</button>
<button type="button" id="value">Stored value (dev)</button>
<button type="button" id="shown">Displayed text</button>
<button type="button" id="whole">Whole cell</button>
<button type="button" id="searchBy">searchBy (atx)</button>
<button type="button" id="caseSensitive">Case sensitive</button>
</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',
office: 'Austin',
dept: 'dev',
memo: 'Meeting with team lead Clark',
},
{ id: 2, name: 'Liam Carter', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{
id: 4,
name: 'Noah Clarke',
city: 'Clarksville',
office: 'Clarksville',
dept: 'ops',
memo: 'Kim joins the team',
},
{ id: 5, name: 'Ava Brooks', city: 'Seattle', office: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
office: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{
id: 7,
name: 'Mia Foster',
city: 'Portland',
office: 'Portland',
dept: 'dev',
memo: 'Sent to the Austin HQ',
},
{ id: 8, name: 'Lucas Reed', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
];
// Options of find(text, options): columns (columns to search), text ('shown' displayed text | 'value' stored value), caseSensitive, wholeCell.
// wholeCell compares with the text searched in that cell (the column's searchBy text if it has one).
// A column's searchBy sets the text searched in that column (here the city column gets an alias such as "Austin, Texas").
const options = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{
id: 'city',
title: 'City',
width: 90,
searchBy: (row) => `${row.city}${row.city === 'Austin' ? ' Austin, Texas atx' : ''}`,
},
{ id: 'office', title: 'Office', width: 90 }, // no searchBy: wholeCell compares with the shown text
{
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',
};
let say = () => { };
function setup(_api, log) {
say = log;
log('Each button uses different find options. The log shows the count.');
}
function show(text, count) {
say(`"${text}" → ${count} cells`);
}
const actions = {
nameOnly: (api) => show('Clark (name column only)', api.find('Clark', { columns: ['name'] }).count),
value: (api) => show('dev (stored value)', api.find('dev', { text: 'value' }).count),
shown: (api) => show('Development (shown text)', api.find('Development').count),
whole: (api) => {
show('Austin (whole cell, office column)', api.find('Austin', { wholeCell: true, columns: ['office'] }).count);
// The city column's searchBy returns "Austin Austin, Texas atx", so it is not a whole-cell match.
show('Austin (whole cell, city: compared with its searchBy text)', api.find('Austin', { wholeCell: true, columns: ['city'] }).count);
},
searchBy: (api) => show('atx (searchBy text)', api.find('atx').count),
caseSensitive: (api) => show('KIM (case-sensitive)', api.find('KIM', { caseSensitive: true }).count),
};
options.ariaLabel = "Choose the columns and the way to search";
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('nameOnly').addEventListener('click', () => actions.nameOnly(api));
document.getElementById('value').addEventListener('click', () => actions.value(api));
document.getElementById('shown').addEventListener('click', () => actions.shown(api));
document.getElementById('whole').addEventListener('click', () => actions.whole(api));
document.getElementById('searchBy').addEventListener('click', () => actions.searchBy(api));
document.getElementById('caseSensitive').addEventListener('click', () => actions.caseSensitive(api));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.nameOnly(api)}
>Name only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.value(api)}
>Stored value (dev)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shown(api)}
>Displayed text</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.whole(api)}
>Whole cell</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.searchBy(api)}
>searchBy (atx)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.caseSensitive(api)}
>Case sensitive</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Emma Clark',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Meeting with team lead Clark',
},
{ id: 2, name: 'Liam Carter', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{
id: 4,
name: 'Noah Clarke',
city: 'Clarksville',
office: 'Clarksville',
dept: 'ops',
memo: 'Kim joins the team',
},
{ id: 5, name: 'Ava Brooks', city: 'Seattle', office: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
office: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{
id: 7,
name: 'Mia Foster',
city: 'Portland',
office: 'Portland',
dept: 'dev',
memo: 'Sent to the Austin HQ',
},
{ id: 8, name: 'Lucas Reed', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
];
// Options of find(text, options): columns (columns to search), text ('shown' displayed text | 'value' stored value), caseSensitive, wholeCell.
// wholeCell compares with the text searched in that cell (the column's searchBy text if it has one).
// A column's searchBy sets the text searched in that column (here the city column gets an alias such as "Austin, Texas").
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{
id: 'city',
title: 'City',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === 'Austin' ? ' Austin, Texas atx' : ''}`,
},
{ id: 'office', title: 'Office', width: 90 }, // no searchBy: wholeCell compares with the shown text
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Each button uses different find options. The log shows the count.');
}
function show(text: string, count: number): void {
say(`"${text}" → ${count} cells`);
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show('Clark (name column only)', api.find('Clark', { columns: ['name'] }).count),
value: (api: GridApi<Row>) =>
show('dev (stored value)', api.find('dev', { text: 'value' }).count),
shown: (api: GridApi<Row>) => show('Development (shown text)', api.find('Development').count),
whole: (api: GridApi<Row>) => {
show(
'Austin (whole cell, office column)',
api.find('Austin', { wholeCell: true, columns: ['office'] }).count,
);
// The city column's searchBy returns "Austin Austin, Texas atx", so it is not a whole-cell match.
show(
'Austin (whole cell, city: compared with its searchBy text)',
api.find('Austin', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) => show('atx (searchBy text)', api.find('atx').count),
caseSensitive: (api: GridApi<Row>) =>
show('KIM (case-sensitive)', api.find('KIM', { caseSensitive: true }).count),
};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">
<button
type="button"
:disabled="!api"
@click="api && actions.nameOnly(api)"
>Name only</button>
<button type="button" :disabled="!api" @click="api && actions.value(api)">Stored value (dev)</button>
<button type="button" :disabled="!api" @click="api && actions.shown(api)">Displayed text</button>
<button type="button" :disabled="!api" @click="api && actions.whole(api)">Whole cell</button>
<button
type="button"
:disabled="!api"
@click="api && actions.searchBy(api)"
>searchBy (atx)</button>
<button
type="button"
:disabled="!api"
@click="api && actions.caseSensitive(api)"
>Case sensitive</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Emma Clark',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Meeting with team lead Clark',
},
{ id: 2, name: 'Liam Carter', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{
id: 4,
name: 'Noah Clarke',
city: 'Clarksville',
office: 'Clarksville',
dept: 'ops',
memo: 'Kim joins the team',
},
{ id: 5, name: 'Ava Brooks', city: 'Seattle', office: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
office: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{
id: 7,
name: 'Mia Foster',
city: 'Portland',
office: 'Portland',
dept: 'dev',
memo: 'Sent to the Austin HQ',
},
{ id: 8, name: 'Lucas Reed', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
];
// Options of find(text, options): columns (columns to search), text ('shown' displayed text | 'value' stored value), caseSensitive, wholeCell.
// wholeCell compares with the text searched in that cell (the column's searchBy text if it has one).
// A column's searchBy sets the text searched in that column (here the city column gets an alias such as "Austin, Texas").
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{
id: 'city',
title: 'City',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === 'Austin' ? ' Austin, Texas atx' : ''}`,
},
{ id: 'office', title: 'Office', width: 90 }, // no searchBy: wholeCell compares with the shown text
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Each button uses different find options. The log shows the count.');
}
function show(text: string, count: number): void {
say(`"${text}" → ${count} cells`);
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show('Clark (name column only)', api.find('Clark', { columns: ['name'] }).count),
value: (api: GridApi<Row>) =>
show('dev (stored value)', api.find('dev', { text: 'value' }).count),
shown: (api: GridApi<Row>) => show('Development (shown text)', api.find('Development').count),
whole: (api: GridApi<Row>) => {
show(
'Austin (whole cell, office column)',
api.find('Austin', { wholeCell: true, columns: ['office'] }).count,
);
// The city column's searchBy returns "Austin Austin, Texas atx", so it is not a whole-cell match.
show(
'Austin (whole cell, city: compared with its searchBy text)',
api.find('Austin', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) => show('atx (searchBy text)', api.find('atx').count),
caseSensitive: (api: GridApi<Row>) =>
show('KIM (case-sensitive)', api.find('KIM', { caseSensitive: true }).count),
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.nameOnly(api)"
>Name only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.value(api)"
>Stored value (dev)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shown(api)"
>Displayed text</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.whole(api)"
>Whole cell</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.searchBy(api)"
>searchBy (atx)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.caseSensitive(api)"
>Case sensitive</button>
</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;
office: string;
dept: string;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Emma Clark',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Meeting with team lead Clark',
},
{ id: 2, name: 'Liam Carter', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
{
id: 3,
name: 'Olivia Stone',
city: 'Austin',
office: 'Austin',
dept: 'dev',
memo: 'Austin business trip planned',
},
{
id: 4,
name: 'Noah Clarke',
city: 'Clarksville',
office: 'Clarksville',
dept: 'ops',
memo: 'Kim joins the team',
},
{ id: 5, name: 'Ava Brooks', city: 'Seattle', office: 'Seattle', dept: 'dev', memo: '' },
{
id: 6,
name: 'Ethan Hayes',
city: 'Austin',
office: 'Austin',
dept: 'ops',
memo: 'Handles the Clarkson lunch order',
},
{
id: 7,
name: 'Mia Foster',
city: 'Portland',
office: 'Portland',
dept: 'dev',
memo: 'Sent to the Austin HQ',
},
{ id: 8, name: 'Lucas Reed', city: 'Denver', office: 'Denver', dept: 'ops', memo: '' },
];
// Options of find(text, options): columns (columns to search), text ('shown' displayed text | 'value' stored value), caseSensitive, wholeCell.
// wholeCell compares with the text searched in that cell (the column's searchBy text if it has one).
// A column's searchBy sets the text searched in that column (here the city column gets an alias such as "Austin, Texas").
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 100 },
{
id: 'city',
title: 'City',
width: 90,
searchBy: (row) =>
`${(row as Row).city}${(row as Row).city === 'Austin' ? ' Austin, Texas atx' : ''}`,
},
{ id: 'office', title: 'Office', width: 90 }, // no searchBy: wholeCell compares with the shown text
{
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',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Each button uses different find options. The log shows the count.');
}
function show(text: string, count: number): void {
say(`"${text}" → ${count} cells`);
}
export const actions = {
nameOnly: (api: GridApi<Row>) =>
show('Clark (name column only)', api.find('Clark', { columns: ['name'] }).count),
value: (api: GridApi<Row>) =>
show('dev (stored value)', api.find('dev', { text: 'value' }).count),
shown: (api: GridApi<Row>) => show('Development (shown text)', api.find('Development').count),
whole: (api: GridApi<Row>) => {
show(
'Austin (whole cell, office column)',
api.find('Austin', { wholeCell: true, columns: ['office'] }).count,
);
// The city column's searchBy returns "Austin Austin, Texas atx", so it is not a whole-cell match.
show(
'Austin (whole cell, city: compared with its searchBy text)',
api.find('Austin', { wholeCell: true, columns: ['city'] }).count,
);
},
searchBy: (api: GridApi<Row>) => show('atx (searchBy text)', api.find('atx').count),
caseSensitive: (api: GridApi<Row>) =>
show('KIM (case-sensitive)', api.find('KIM', { caseSensitive: true }).count),
};