이름 검색: 포함·시작·같음·끝Name search: contains, starts with, equals, ends with
글자 필터는 '포함', '시작 문자', '같음', '끝 문자', '포함하지 않음' 중에서 고를 수 있고 대소문자는 구분하지 않아요. 같은 입력도 방식에 따라 결과가 달라져요.A text filter can match contains, starts with, equals, ends with or does not contain, ignoring case. The same input gives different results per mode.
코드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">
<select aria-label="방식" id="operator">
<option value="contains" selected>포함 (기본)</option>
<option value="startsWith">시작 문자</option>
<option value="equals">같음</option>
<option value="endsWith">끝 문자</option>
<option value="notContains">포함하지 않음</option>
</select>
<input type="text" aria-label="이름" placeholder="이름 (예: 김)" id="text" />
</div>
<div id="grid" style="height: 560px"></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('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(api, event.target.value));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options = {
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'email', title: '이메일', width: 220 },
{ id: 'dept', title: '부서', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4],
})),
rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null);
export function setup(api, log) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () => log({
ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
}));
return () => off();
}
export const actions = {
operator: (api, value) => {
state.op = value ?? 'contains';
apply(api);
},
text: (api, value) => {
state.text = (value ?? '').trim();
apply(api);
},
};<!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">
<select aria-label="방식" id="operator">
<option value="contains" selected>포함 (기본)</option>
<option value="startsWith">시작 문자</option>
<option value="equals">같음</option>
<option value="endsWith">끝 문자</option>
<option value="notContains">포함하지 않음</option>
</select>
<input type="text" aria-label="이름" placeholder="이름 (예: 김)" id="text" />
</div>
<div id="grid" style="height: 560px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const options = {
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'email', title: '이메일', width: 220 },
{ id: 'dept', title: '부서', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4],
})),
rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null);
function setup(api, log) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () => log({
ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
}));
return () => off();
}
const actions = {
operator: (api, value) => {
state.op = value ?? 'contains';
apply(api);
},
text: (api, value) => {
state.text = (value ?? '').trim();
apply(api);
},
};
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('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(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">
<select
aria-label="방식"
disabled={!api}
onChange={(event) => api && actions.operator(api, event.target.value)}
>
<option value="contains">포함 (기본)</option>
<option value="startsWith">시작 문자</option>
<option value="equals">같음</option>
<option value="endsWith">끝 문자</option>
<option value="notContains">포함하지 않음</option>
</select>
<input
type="text"
aria-label="이름"
placeholder="이름 (예: 김)"
disabled={!api}
onChange={(event) => api && actions.text(api, event.target.value)}
/>
</div>
<Grid style={{ height: 560 }} ref={gridRef} options={options} />
</>
);
}import type { FilterOperator, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'email', title: '이메일', width: 220 },
{ id: 'dept', title: '부서', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// 글자 조건은 포함·시작·같음·끝·포함하지 않음 중에서 골라요. 대소문자는 구분하지 않아요.
// 입력칸이 비면 조건이 빠져요. 이름 컬럼에 거는 단일 조건이에요.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
}),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="방식"
:disabled="!api"
@change="api && actions.operator(api, ($event.target as HTMLSelectElement).value)"
>
<option value="contains" selected>포함 (기본)</option>
<option value="startsWith">시작 문자</option>
<option value="equals">같음</option>
<option value="endsWith">끝 문자</option>
<option value="notContains">포함하지 않음</option>
</select>
<input
type="text"
aria-label="이름"
placeholder="이름 (예: 김)"
:disabled="!api"
@input="api && actions.text(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 560px" :options="options" @ready="onReady" />
</template>import type { FilterOperator, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'email', title: '이메일', width: 220 },
{ id: 'dept', title: '부서', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// 글자 조건은 포함·시작·같음·끝·포함하지 않음 중에서 골라요. 대소문자는 구분하지 않아요.
// 입력칸이 비면 조건이 빠져요. 이름 컬럼에 거는 단일 조건이에요.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
}),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="방식"
[disabled]="!api"
(change)="api && actions.operator(api, $any($event.target).value)"
>
<option value="contains" selected>포함 (기본)</option>
<option value="startsWith">시작 문자</option>
<option value="equals">같음</option>
<option value="endsWith">끝 문자</option>
<option value="notContains">포함하지 않음</option>
</select>
<input
type="text"
aria-label="이름"
placeholder="이름 (예: 김)"
[disabled]="!api"
(input)="api && actions.text(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 560px" [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 { FilterOperator, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'email', title: '이메일', width: 220 },
{ id: 'dept', title: '부서', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// 글자 조건은 포함·시작·같음·끝·포함하지 않음 중에서 골라요. 대소문자는 구분하지 않아요.
// 입력칸이 비면 조건이 빠져요. 이름 컬럼에 거는 단일 조건이에요.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
}),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Mode" id="operator">
<option value="contains" selected>Contains (default)</option>
<option value="startsWith">Starts with</option>
<option value="equals">Equals</option>
<option value="endsWith">Ends with</option>
<option value="notContains">Does not contain</option>
</select>
<input
type="text"
aria-label="Name"
placeholder="Name (e.g. Lee)"
id="text"
/>
</div>
<div id="grid" style="height: 560px"></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('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(api, event.target.value));const names = [
'Lee Carter',
'Emma Stone',
'Noah Park',
'Olivia Brooks',
'Ethan Reed',
'Sophia Hayes',
'Mason Foster',
'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'email', title: 'Email', width: 220 },
{ id: 'dept', title: 'Department', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4],
})),
rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null);
export function setup(api, log) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () => log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`));
return () => off();
}
export const actions = {
operator: (api, value) => {
state.op = value ?? 'contains';
apply(api);
},
text: (api, value) => {
state.text = (value ?? '').trim();
apply(api);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Name search: contains, starts with, equals, ends with</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Mode" id="operator">
<option value="contains" selected>Contains (default)</option>
<option value="startsWith">Starts with</option>
<option value="equals">Equals</option>
<option value="endsWith">Ends with</option>
<option value="notContains">Does not contain</option>
</select>
<input
type="text"
aria-label="Name"
placeholder="Name (e.g. Lee)"
id="text"
/>
</div>
<div id="grid" style="height: 560px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Lee Carter',
'Emma Stone',
'Noah Park',
'Olivia Brooks',
'Ethan Reed',
'Sophia Hayes',
'Mason Foster',
'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
const options = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'email', title: 'Email', width: 220 },
{ id: 'dept', title: 'Department', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4],
})),
rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null);
function setup(api, log) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () => log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`));
return () => off();
}
const actions = {
operator: (api, value) => {
state.op = value ?? 'contains';
apply(api);
},
text: (api, value) => {
state.text = (value ?? '').trim();
apply(api);
},
};
options.ariaLabel = "Name search: contains, starts with, equals, ends with";
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('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(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">
<select
aria-label="Mode"
disabled={!api}
onChange={(event) => api && actions.operator(api, event.target.value)}
>
<option value="contains">Contains (default)</option>
<option value="startsWith">Starts with</option>
<option value="equals">Equals</option>
<option value="endsWith">Ends with</option>
<option value="notContains">Does not contain</option>
</select>
<input
type="text"
aria-label="Name"
placeholder="Name (e.g. Lee)"
disabled={!api}
onChange={(event) => api && actions.text(api, event.target.value)}
/>
</div>
<Grid style={{ height: 560 }} ref={gridRef} options={options} />
</>
);
}import type { FilterOperator, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = [
'Lee Carter',
'Emma Stone',
'Noah Park',
'Olivia Brooks',
'Ethan Reed',
'Sophia Hayes',
'Mason Foster',
'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'email', title: 'Email', width: 220 },
{ id: 'dept', title: 'Department', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// A text condition is one of contains, starts with, equals, ends with, does not contain. Case is ignored.
// An empty input drops the condition. It is a single condition on the Name column.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};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">
<select
aria-label="Mode"
:disabled="!api"
@change="api && actions.operator(api, ($event.target as HTMLSelectElement).value)"
>
<option value="contains" selected>Contains (default)</option>
<option value="startsWith">Starts with</option>
<option value="equals">Equals</option>
<option value="endsWith">Ends with</option>
<option value="notContains">Does not contain</option>
</select>
<input
type="text"
aria-label="Name"
placeholder="Name (e.g. Lee)"
:disabled="!api"
@input="api && actions.text(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 560px" :options="options" @ready="onReady" />
</template>import type { FilterOperator, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = [
'Lee Carter',
'Emma Stone',
'Noah Park',
'Olivia Brooks',
'Ethan Reed',
'Sophia Hayes',
'Mason Foster',
'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'email', title: 'Email', width: 220 },
{ id: 'dept', title: 'Department', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// A text condition is one of contains, starts with, equals, ends with, does not contain. Case is ignored.
// An empty input drops the condition. It is a single condition on the Name column.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};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">
<select
aria-label="Mode"
[disabled]="!api"
(change)="api && actions.operator(api, $any($event.target).value)"
>
<option value="contains" selected>Contains (default)</option>
<option value="startsWith">Starts with</option>
<option value="equals">Equals</option>
<option value="endsWith">Ends with</option>
<option value="notContains">Does not contain</option>
</select>
<input
type="text"
aria-label="Name"
placeholder="Name (e.g. Lee)"
[disabled]="!api"
(input)="api && actions.text(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 560px" [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 { FilterOperator, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
email: string;
dept: string;
}
const names = [
'Lee Carter',
'Emma Stone',
'Noah Park',
'Olivia Brooks',
'Ethan Reed',
'Sophia Hayes',
'Mason Foster',
'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'email', title: 'Email', width: 220 },
{ id: 'dept', title: 'Department', width: 130 },
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
email: `${mails[i % 8]}${i + 1}@maxmine.com`,
dept: depts[(i * 3) % 4] as string,
})),
rowKey: 'id',
};
// A text condition is one of contains, starts with, equals, ends with, does not contain. Case is ignored.
// An empty input drops the condition. It is a single condition on the Name column.
type TextOp = Extract<
FilterOperator,
'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'equals'
>;
const state: { op: TextOp; text: string } = { op: 'contains', text: '' };
const apply = (api: GridApi<Row>): void =>
api.setFilterModel(
state.text
? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
: null,
);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.op = 'contains';
state.text = '';
const off = api.on('filterChanged', () =>
log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`),
);
return () => off();
}
export const actions = {
operator: (api: GridApi<Row>, value?: string) => {
state.op = (value as TextOp) ?? 'contains';
apply(api);
},
text: (api: GridApi<Row>, value?: string) => {
state.text = (value ?? '').trim();
apply(api);
},
};