헤더 아래 칸에서 바로 걸러 보기Filter right under the header
컬럼마다 필터 칸이 있어서 값 목록에서 체크하거나, 숫자 식(>=50000)을 입력하면 바로 걸러져요. 여러 컬럼에 걸면 모두 만족하는 행만 남고, 비어 있는 값만 골라 볼 수도 있어요.Every column has a filter cell: tick values from a list or type a number expression such as >=50. Filters on several columns combine, and you can pick only empty values.
코드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="twoNames">김민준·이서연만</button>
<button type="button" id="nameAndRegion">이서연·박지호이면서 서울</button>
<button type="button" id="emptyRegion">지역이 빈 행만</button>
<button type="button" id="sortByPrice">가격 높은 순 정렬</button>
<button type="button" id="clear">필터·정렬 지우기</button>
</div>
<div id="grid" style="height: 640px"></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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
// - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
export const options = {
filterRow: true,
columns: [
{ id: 'customer', title: '고객명', kind: 'select', width: 130 },
{ id: 'region', title: '지역', kind: 'select', width: 110 },
{ id: 'product', title: '상품', kind: 'select', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
customer: i % 7 === 6 ? null : customers[i % 7],
region: i % 5 === 4 ? null : regions[(i * 3) % 4],
product: products[(i * 2) % 5],
quantity: 1 + ((i * 7) % 15),
price: 29000 + ((i * 53000) % 480000),
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log({
ko: filterModel === null || filterModel.items.length === 0
? '필터 없음: 모든 행이 보여요'
: `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
en: filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
// 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
nameAndRegion: (api) => show(api, [
{ columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
{ columnId: 'region', operator: 'in', value: ['서울'] },
]),
// 값이 비어 있는 행만
emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};<!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="twoNames">김민준·이서연만</button>
<button type="button" id="nameAndRegion">이서연·박지호이면서 서울</button>
<button type="button" id="emptyRegion">지역이 빈 행만</button>
<button type="button" id="sortByPrice">가격 높은 순 정렬</button>
<button type="button" id="clear">필터·정렬 지우기</button>
</div>
<div id="grid" style="height: 640px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
// - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
const options = {
filterRow: true,
columns: [
{ id: 'customer', title: '고객명', kind: 'select', width: 130 },
{ id: 'region', title: '지역', kind: 'select', width: 110 },
{ id: 'product', title: '상품', kind: 'select', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
customer: i % 7 === 6 ? null : customers[i % 7],
region: i % 5 === 4 ? null : regions[(i * 3) % 4],
product: products[(i * 2) % 5],
quantity: 1 + ((i * 7) % 15),
price: 29000 + ((i * 53000) % 480000),
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log({
ko: filterModel === null || filterModel.items.length === 0
? '필터 없음: 모든 행이 보여요'
: `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
en: filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
const actions = {
// 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
// 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
nameAndRegion: (api) => show(api, [
{ columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
{ columnId: 'region', operator: 'in', value: ['서울'] },
]),
// 값이 비어 있는 행만
emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};
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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(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.twoNames(api)}
>김민준·이서연만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.nameAndRegion(api)}
>이서연·박지호이면서 서울</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.emptyRegion(api)}
>지역이 빈 행만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortByPrice(api)}
>가격 높은 순 정렬</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터·정렬 지우기</button>
</div>
<Grid style={{ height: 640 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
// - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: '고객명', kind: 'select', width: 130 },
{ id: 'region', title: '지역', kind: 'select', width: 110 },
{ id: 'product', title: '상품', kind: 'select', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29000 + ((i * 53000) % 480000),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
filterModel === null || filterModel.items.length === 0
? '필터 없음: 모든 행이 보여요'
: `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
// 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
{ columnId: 'region', operator: 'in', value: ['서울'] },
]),
// 값이 비어 있는 행만
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};버튼을 누르면 이 예제의 코드가 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.twoNames(api)"
>김민준·이서연만</button>
<button
type="button"
:disabled="!api"
@click="api && actions.nameAndRegion(api)"
>이서연·박지호이면서 서울</button>
<button
type="button"
:disabled="!api"
@click="api && actions.emptyRegion(api)"
>지역이 빈 행만</button>
<button
type="button"
:disabled="!api"
@click="api && actions.sortByPrice(api)"
>가격 높은 순 정렬</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터·정렬 지우기</button>
</div>
<Grid style="height: 640px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
// - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: '고객명', kind: 'select', width: 130 },
{ id: 'region', title: '지역', kind: 'select', width: 110 },
{ id: 'product', title: '상품', kind: 'select', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29000 + ((i * 53000) % 480000),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
filterModel === null || filterModel.items.length === 0
? '필터 없음: 모든 행이 보여요'
: `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
// 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
{ columnId: 'region', operator: 'in', value: ['서울'] },
]),
// 값이 비어 있는 행만
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};버튼을 누르면 이 예제의 코드가 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.twoNames(api)"
>김민준·이서연만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.nameAndRegion(api)"
>이서연·박지호이면서 서울</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.emptyRegion(api)"
>지역이 빈 행만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortByPrice(api)"
>가격 높은 순 정렬</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터·정렬 지우기</button>
</div>
<mx-grid style="height: 640px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
// - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: '고객명', kind: 'select', width: 130 },
{ id: 'region', title: '지역', kind: 'select', width: 110 },
{ id: 'product', title: '상품', kind: 'select', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29000 + ((i * 53000) % 480000),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
filterModel === null || filterModel.items.length === 0
? '필터 없음: 모든 행이 보여요'
: `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
// 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
{ columnId: 'region', operator: 'in', value: ['서울'] },
]),
// 값이 비어 있는 행만
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};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="twoNames">Two customers only</button>
<button type="button" id="nameAndRegion">Two names and Seoul</button>
<button type="button" id="emptyRegion">Empty region only</button>
<button type="button" id="sortByPrice">Sort by price</button>
<button type="button" id="clear">Clear filter and sort</button>
</div>
<div id="grid" style="height: 640px"></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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const customers = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless Earbuds',
'Smart Watch',
'Laptop Stand',
'Power Bank',
'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
// - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
export const options = {
filterRow: true,
columns: [
{ id: 'customer', title: 'Customer', kind: 'select', width: 140 },
{ id: 'region', title: 'Region', kind: 'select', width: 120 },
{ id: 'product', title: 'Product', kind: 'select', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
filter: { placeholder: 'e.g. >=50' },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// Deliberately empty cells: customer on every 7th row, region on every 5th
customer: i % 7 === 6 ? null : customers[i % 7],
region: i % 5 === 4 ? null : regions[(i * 3) % 4],
product: products[(i * 2) % 5],
quantity: 1 + ((i * 7) % 15),
price: 29 + ((i * 53) % 480),
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log(filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`));
return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
// Two columns together (AND): Emma Stone or Noah Kim, and region New York
nameAndRegion: (api) => show(api, [
{ columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
{ columnId: 'region', operator: 'in', value: ['New York'] },
]),
// Only rows with an empty value
emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// Sorting and filtering can be combined: filter while viewing by price, highest first
sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Filter right under the header</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="twoNames">Two customers only</button>
<button type="button" id="nameAndRegion">Two names and Seoul</button>
<button type="button" id="emptyRegion">Empty region only</button>
<button type="button" id="sortByPrice">Sort by price</button>
<button type="button" id="clear">Clear filter and sort</button>
</div>
<div id="grid" style="height: 640px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless Earbuds',
'Smart Watch',
'Laptop Stand',
'Power Bank',
'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
// - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
const options = {
filterRow: true,
columns: [
{ id: 'customer', title: 'Customer', kind: 'select', width: 140 },
{ id: 'region', title: 'Region', kind: 'select', width: 120 },
{ id: 'product', title: 'Product', kind: 'select', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
filter: { placeholder: 'e.g. >=50' },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// Deliberately empty cells: customer on every 7th row, region on every 5th
customer: i % 7 === 6 ? null : customers[i % 7],
region: i % 5 === 4 ? null : regions[(i * 3) % 4],
product: products[(i * 2) % 5],
quantity: 1 + ((i * 7) % 15),
price: 29 + ((i * 53) % 480),
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log(filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`));
return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
const actions = {
// Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
// Two columns together (AND): Emma Stone or Noah Kim, and region New York
nameAndRegion: (api) => show(api, [
{ columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
{ columnId: 'region', operator: 'in', value: ['New York'] },
]),
// Only rows with an empty value
emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// Sorting and filtering can be combined: filter while viewing by price, highest first
sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};
options.ariaLabel = "Filter right under the header";
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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(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.twoNames(api)}
>Two customers only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.nameAndRegion(api)}
>Two names and Seoul</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.emptyRegion(api)}
>Empty region only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortByPrice(api)}
>Sort by price</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter and sort</button>
</div>
<Grid style={{ height: 640 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless Earbuds',
'Smart Watch',
'Laptop Stand',
'Power Bank',
'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
// - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: 'Customer', kind: 'select', width: 140 },
{ id: 'region', title: 'Region', kind: 'select', width: 120 },
{ id: 'product', title: 'Product', kind: 'select', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
filter: { placeholder: 'e.g. >=50' },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// Deliberately empty cells: customer on every 7th row, region on every 5th
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29 + ((i * 53) % 480),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
// Two columns together (AND): Emma Stone or Noah Kim, and region New York
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
{ columnId: 'region', operator: 'in', value: ['New York'] },
]),
// Only rows with an empty value
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// Sorting and filtering can be combined: filter while viewing by price, highest first
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};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.twoNames(api)"
>Two customers only</button>
<button
type="button"
:disabled="!api"
@click="api && actions.nameAndRegion(api)"
>Two names and Seoul</button>
<button
type="button"
:disabled="!api"
@click="api && actions.emptyRegion(api)"
>Empty region only</button>
<button
type="button"
:disabled="!api"
@click="api && actions.sortByPrice(api)"
>Sort by price</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter and sort</button>
</div>
<Grid style="height: 640px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless Earbuds',
'Smart Watch',
'Laptop Stand',
'Power Bank',
'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
// - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: 'Customer', kind: 'select', width: 140 },
{ id: 'region', title: 'Region', kind: 'select', width: 120 },
{ id: 'product', title: 'Product', kind: 'select', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
filter: { placeholder: 'e.g. >=50' },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// Deliberately empty cells: customer on every 7th row, region on every 5th
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29 + ((i * 53) % 480),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
// Two columns together (AND): Emma Stone or Noah Kim, and region New York
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
{ columnId: 'region', operator: 'in', value: ['New York'] },
]),
// Only rows with an empty value
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// Sorting and filtering can be combined: filter while viewing by price, highest first
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};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.twoNames(api)"
>Two customers only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.nameAndRegion(api)"
>Two names and Seoul</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.emptyRegion(api)"
>Empty region only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortByPrice(api)"
>Sort by price</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter and sort</button>
</div>
<mx-grid style="height: 640px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
customer: string | null;
region: string | null;
product: string;
quantity: number;
price: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless Earbuds',
'Smart Watch',
'Laptop Stand',
'Power Bank',
'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
// - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{ id: 'customer', title: 'Customer', kind: 'select', width: 140 },
{ id: 'region', title: 'Region', kind: 'select', width: 120 },
{ id: 'product', title: 'Product', kind: 'select', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
filter: { placeholder: 'e.g. >=50' },
},
],
rows: Array.from({ length: 16 }, (_, i) => ({
id: i + 1,
// Deliberately empty cells: customer on every 7th row, region on every 5th
customer: i % 7 === 6 ? null : (customers[i % 7] as string),
region: i % 5 === 4 ? null : (regions[(i * 3) % 4] as string),
product: products[(i * 2) % 5] as string,
quantity: 1 + ((i * 7) % 15),
price: 29 + ((i * 53) % 480),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
filterModel === null || filterModel.items.length === 0
? 'No filter: all rows are visible'
: `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
// Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
twoNames: (api: GridApi<Row>) =>
show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
// Two columns together (AND): Emma Stone or Noah Kim, and region New York
nameAndRegion: (api: GridApi<Row>) =>
show(api, [
{ columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
{ columnId: 'region', operator: 'in', value: ['New York'] },
]),
// Only rows with an empty value
emptyRegion: (api: GridApi<Row>) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
// Sorting and filtering can be combined: filter while viewing by price, highest first
sortByPrice: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => {
api.setFilterModel(null);
api.setSortModel([]);
},
};