헤더의 깔때기로 Excel처럼 걸러 보기Filter from the header funnel, like Excel
헤더 오른쪽 깔때기를 누르면 정렬, 조건 두 개(그리고/또는), 값 목록 체크가 한 팝업에 나와요. 값 목록에는 검색과 (모두 선택), (비어 있음), 값마다 행 개수가 있고, 휴대폰에서는 아래에서 올라오는 시트로 바뀌어요.The funnel in each header opens one popup with sorting, two conditions joined by AND/OR, and a value checklist with search, select all, empty values and row counts. On phones it becomes a bottom sheet.
코드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="apply">
<option value="button" selected>적용 버튼 (기본)</option>
<option value="live">체크하면 바로</option>
</select>
<button type="button" id="preset">코드로 걸기: 연봉 5,000↑ & (개발팀 또는 비어 있음)</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 520px"></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('apply').addEventListener('change', (event) => actions.apply(api, event.target.value));
document.getElementById('preset').addEventListener('click', () => actions.preset(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀', null];
// filterMenu: true면 필터가 되는 컬럼마다 헤더에 깔때기 버튼이 생겨요. 누르면 정렬, 조건(두 개까지, 그리고/또는),
// 값 목록(검색·모두 선택·비어 있음·행 개수)이 한 팝업에 나와요. 필터 행(filterRow)과 같이 써도 돼요.
export const options = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
dept: depts[(i * 3) % 5] ?? null,
salary: 3600 + ((i * 530) % 4600),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log({
ko: count === 0
? `필터 없음 · ${api.getVisibleRowCount()}행`
: `조건 ${count}개 적용 · ${api.getVisibleRowCount()}행 보임`,
en: count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
});
});
return () => off();
}
export const actions = {
// 값 목록을 체크하면 바로 걸지, 적용 버튼을 눌러야 걸지 정해요.
apply: (api, value) => api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// 코드로 걸어도 깔때기와 팝업에 그대로 나타나요: 연봉 5,000 이상이면서 (개발팀 또는 비어 있음)
preset: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 5000 },
{ columnId: 'dept', operator: 'in', value: ['개발팀'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api) => api.setFilterModel(null),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>헤더의 깔때기로 Excel처럼 걸러 보기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="값 목록 적용" id="apply">
<option value="button" selected>적용 버튼 (기본)</option>
<option value="live">체크하면 바로</option>
</select>
<button type="button" id="preset">코드로 걸기: 연봉 5,000↑ & (개발팀 또는 비어 있음)</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 520px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀', null];
// filterMenu: true면 필터가 되는 컬럼마다 헤더에 깔때기 버튼이 생겨요. 누르면 정렬, 조건(두 개까지, 그리고/또는),
// 값 목록(검색·모두 선택·비어 있음·행 개수)이 한 팝업에 나와요. 필터 행(filterRow)과 같이 써도 돼요.
const options = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
dept: depts[(i * 3) % 5] ?? null,
salary: 3600 + ((i * 530) % 4600),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log({
ko: count === 0
? `필터 없음 · ${api.getVisibleRowCount()}행`
: `조건 ${count}개 적용 · ${api.getVisibleRowCount()}행 보임`,
en: count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
});
});
return () => off();
}
const actions = {
// 값 목록을 체크하면 바로 걸지, 적용 버튼을 눌러야 걸지 정해요.
apply: (api, value) => api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// 코드로 걸어도 깔때기와 팝업에 그대로 나타나요: 연봉 5,000 이상이면서 (개발팀 또는 비어 있음)
preset: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 5000 },
{ columnId: 'dept', operator: 'in', value: ['개발팀'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "헤더의 깔때기로 Excel처럼 걸러 보기";
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('apply').addEventListener('change', (event) => actions.apply(api, event.target.value));
document.getElementById('preset').addEventListener('click', () => actions.preset(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">
<select
aria-label="값 목록 적용"
disabled={!api}
onChange={(event) => api && actions.apply(api, event.target.value)}
>
<option value="button">적용 버튼 (기본)</option>
<option value="live">체크하면 바로</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.preset(api)}
>코드로 걸기: 연봉 5,000↑ & (개발팀 또는 비어 있음)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
</div>
<Grid style={{ height: 520 }} 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;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀', null];
// filterMenu: true면 필터가 되는 컬럼마다 헤더에 깔때기 버튼이 생겨요. 누르면 정렬, 조건(두 개까지, 그리고/또는),
// 값 목록(검색·모두 선택·비어 있음·행 개수)이 한 팝업에 나와요. 필터 행(filterRow)과 같이 써도 돼요.
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 3600 + ((i * 530) % 4600),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log({
ko:
count === 0
? `필터 없음 · ${api.getVisibleRowCount()}행`
: `조건 ${count}개 적용 · ${api.getVisibleRowCount()}행 보임`,
en:
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
});
});
return () => off();
}
export const actions = {
// 값 목록을 체크하면 바로 걸지, 적용 버튼을 눌러야 걸지 정해요.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// 코드로 걸어도 깔때기와 팝업에 그대로 나타나요: 연봉 5,000 이상이면서 (개발팀 또는 비어 있음)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 5000 },
{ columnId: 'dept', operator: 'in', value: ['개발팀'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 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.apply(api, ($event.target as HTMLSelectElement).value)"
>
<option value="button" selected>적용 버튼 (기본)</option>
<option value="live">체크하면 바로</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.preset(api)">코드로 걸기: 연봉 5,000↑ & (개발팀 또는 비어 있음)</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
</div>
<Grid style="height: 520px" :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;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀', null];
// filterMenu: true면 필터가 되는 컬럼마다 헤더에 깔때기 버튼이 생겨요. 누르면 정렬, 조건(두 개까지, 그리고/또는),
// 값 목록(검색·모두 선택·비어 있음·행 개수)이 한 팝업에 나와요. 필터 행(filterRow)과 같이 써도 돼요.
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 3600 + ((i * 530) % 4600),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log({
ko:
count === 0
? `필터 없음 · ${api.getVisibleRowCount()}행`
: `조건 ${count}개 적용 · ${api.getVisibleRowCount()}행 보임`,
en:
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
});
});
return () => off();
}
export const actions = {
// 값 목록을 체크하면 바로 걸지, 적용 버튼을 눌러야 걸지 정해요.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// 코드로 걸어도 깔때기와 팝업에 그대로 나타나요: 연봉 5,000 이상이면서 (개발팀 또는 비어 있음)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 5000 },
{ columnId: 'dept', operator: 'in', value: ['개발팀'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 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.apply(api, $any($event.target).value)"
>
<option value="button" selected>적용 버튼 (기본)</option>
<option value="live">체크하면 바로</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.preset(api)"
>코드로 걸기: 연봉 5,000↑ & (개발팀 또는 비어 있음)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
</div>
<mx-grid style="height: 520px" [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;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀', null];
// filterMenu: true면 필터가 되는 컬럼마다 헤더에 깔때기 버튼이 생겨요. 누르면 정렬, 조건(두 개까지, 그리고/또는),
// 값 목록(검색·모두 선택·비어 있음·행 개수)이 한 팝업에 나와요. 필터 행(filterRow)과 같이 써도 돼요.
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 3600 + ((i * 530) % 4600),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log({
ko:
count === 0
? `필터 없음 · ${api.getVisibleRowCount()}행`
: `조건 ${count}개 적용 · ${api.getVisibleRowCount()}행 보임`,
en:
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
});
});
return () => off();
}
export const actions = {
// 값 목록을 체크하면 바로 걸지, 적용 버튼을 눌러야 걸지 정해요.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// 코드로 걸어도 깔때기와 팝업에 그대로 나타나요: 연봉 5,000 이상이면서 (개발팀 또는 비어 있음)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 5000 },
{ columnId: 'dept', operator: 'in', value: ['개발팀'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};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="Value list apply" id="apply">
<option value="button" selected>Apply button (default)</option>
<option value="live">Immediately</option>
</select>
<button type="button" id="preset">Set in code: salary $50,000+ and (Dev or empty)</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 520px"></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('apply').addEventListener('change', (event) => actions.apply(api, event.target.value));
document.getElementById('preset').addEventListener('click', () => actions.preset(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR', null];
// With filterMenu: true, every filterable column gets a funnel button in its header. It opens one popup with sorting, conditions
// (up to two, AND/OR) and a value list (search, select all, empty, row counts). It can be used together with the filter row (filterRow).
export const options = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
dept: depts[(i * 3) % 5] ?? null,
salary: 36000 + ((i * 5300) % 46000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log(count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`);
});
return () => off();
}
export const actions = {
// Decide whether ticking the value list applies at once or only after pressing the apply button.
apply: (api, value) => api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// Applying from code also shows up in the funnel and popup: salary $50,000 or more and (Dev or empty)
preset: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 50000 },
{ columnId: 'dept', operator: 'in', value: ['Dev'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api) => api.setFilterModel(null),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Filter from the header funnel, like Excel</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Value list apply" id="apply">
<option value="button" selected>Apply button (default)</option>
<option value="live">Immediately</option>
</select>
<button type="button" id="preset">Set in code: salary $50,000+ and (Dev or empty)</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 520px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR', null];
// With filterMenu: true, every filterable column gets a funnel button in its header. It opens one popup with sorting, conditions
// (up to two, AND/OR) and a value list (search, select all, empty, row counts). It can be used together with the filter row (filterRow).
const options = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
dept: depts[(i * 3) % 5] ?? null,
salary: 36000 + ((i * 5300) % 46000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log(count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`);
});
return () => off();
}
const actions = {
// Decide whether ticking the value list applies at once or only after pressing the apply button.
apply: (api, value) => api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// Applying from code also shows up in the funnel and popup: salary $50,000 or more and (Dev or empty)
preset: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 50000 },
{ columnId: 'dept', operator: 'in', value: ['Dev'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "Filter from the header funnel, like Excel";
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('apply').addEventListener('change', (event) => actions.apply(api, event.target.value));
document.getElementById('preset').addEventListener('click', () => actions.preset(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">
<select
aria-label="Value list apply"
disabled={!api}
onChange={(event) => api && actions.apply(api, event.target.value)}
>
<option value="button">Apply button (default)</option>
<option value="live">Immediately</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.preset(api)}
>Set in code: salary $50,000+ and (Dev or empty)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 520 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR', null];
// With filterMenu: true, every filterable column gets a funnel button in its header. It opens one popup with sorting, conditions
// (up to two, AND/OR) and a value list (search, select all, empty, row counts). It can be used together with the filter row (filterRow).
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 36000 + ((i * 5300) % 46000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log(
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
);
});
return () => off();
}
export const actions = {
// Decide whether ticking the value list applies at once or only after pressing the apply button.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// Applying from code also shows up in the funnel and popup: salary $50,000 or more and (Dev or empty)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 50000 },
{ columnId: 'dept', operator: 'in', value: ['Dev'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};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="Value list apply"
:disabled="!api"
@change="api && actions.apply(api, ($event.target as HTMLSelectElement).value)"
>
<option value="button" selected>Apply button (default)</option>
<option value="live">Immediately</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.preset(api)">Set in code: salary $50,000+ and (Dev or empty)</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
</div>
<Grid style="height: 520px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR', null];
// With filterMenu: true, every filterable column gets a funnel button in its header. It opens one popup with sorting, conditions
// (up to two, AND/OR) and a value list (search, select all, empty, row counts). It can be used together with the filter row (filterRow).
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 36000 + ((i * 5300) % 46000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log(
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
);
});
return () => off();
}
export const actions = {
// Decide whether ticking the value list applies at once or only after pressing the apply button.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// Applying from code also shows up in the funnel and popup: salary $50,000 or more and (Dev or empty)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 50000 },
{ columnId: 'dept', operator: 'in', value: ['Dev'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};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="Value list apply"
[disabled]="!api"
(change)="api && actions.apply(api, $any($event.target).value)"
>
<option value="button" selected>Apply button (default)</option>
<option value="live">Immediately</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.preset(api)"
>Set in code: salary $50,000+ and (Dev or empty)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 520px" [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;
export interface Row {
id: number;
name: string;
dept: string | null;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const depts = ['Dev', 'Design', 'Sales', 'HR', null];
// With filterMenu: true, every filterable column gets a funnel button in its header. It opens one popup with sorting, conditions
// (up to two, AND/OR) and a value list (search, select all, empty, row counts). It can be used together with the filter row (filterRow).
export const options: GridOptions<Row> = {
filterMenu: true,
columnMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 160,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 130,
formatValue: (value) => (value instanceof Date ? value.toISOString().slice(0, 10) : ''),
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
dept: depts[(i * 3) % 5] ?? null,
salary: 36000 + ((i * 5300) % 46000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
const count = filterModel?.items.length ?? 0;
log(
count === 0
? `No filter · ${api.getVisibleRowCount()} rows`
: `${count} conditions applied · ${api.getVisibleRowCount()} rows visible`,
);
});
return () => off();
}
export const actions = {
// Decide whether ticking the value list applies at once or only after pressing the apply button.
apply: (api: GridApi<Row>, value?: string) =>
api.setOptions({ filterMenu: { applyOnChange: value === 'live' } }),
// Applying from code also shows up in the funnel and popup: salary $50,000 or more and (Dev or empty)
preset: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'salary', operator: 'gte', value: 50000 },
{ columnId: 'dept', operator: 'in', value: ['Dev'] },
{ columnId: 'dept', operator: 'isEmpty' },
],
columnMatch: { dept: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};