필터가 보는 값 바꾸기Change the value the filter sees
filterValue로 필터와 값 목록이 월 같은 다른 값을 보게 하고, valueKey로 객체 값을 id로 묶어요. 표시와 정렬은 그대로 getValue예요.filterValue makes the filter and the value list see another value, such as the month, and valueKey groups object values by id. Display and sort keep using getValue.
코드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="feb">2월만</button>
<button type="button" id="kim">김 담당만</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 300px"></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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows = [
{ id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
export const options = {
columns: [
{ id: 'name', title: '이름', width: 110 },
{
id: 'hired',
title: '입사 월',
kind: 'date',
width: 130,
filter: { type: 'set' },
filterValue: ({ value }) => `${value.getMonth() + 1}월`,
},
{
id: 'owner',
title: '담당',
width: 130,
filter: { type: 'set' },
valueKey: (value) => `u${value.id}`,
formatValue: (value) => value.label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say = () => undefined;
export function setup(grid, log) {
say = log;
return grid.on('filterChanged', () => log({
ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
en: `${grid.getVisibleRowCount()} rows visible`,
}));
}
export const actions = {
feb: (grid) => grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
}),
kim: (grid) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
},
clear: (grid) => grid.setFilterModel(null),
};<!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="feb">2월만</button>
<button type="button" id="kim">김 담당만</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows = [
{ id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
const options = {
columns: [
{ id: 'name', title: '이름', width: 110 },
{
id: 'hired',
title: '입사 월',
kind: 'date',
width: 130,
filter: { type: 'set' },
filterValue: ({ value }) => `${value.getMonth() + 1}월`,
},
{
id: 'owner',
title: '담당',
width: 130,
filter: { type: 'set' },
valueKey: (value) => `u${value.id}`,
formatValue: (value) => value.label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say = () => undefined;
function setup(grid, log) {
say = log;
return grid.on('filterChanged', () => log({
ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
en: `${grid.getVisibleRowCount()} rows visible`,
}));
}
const actions = {
feb: (grid) => grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
}),
kim: (grid) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
},
clear: (grid) => grid.setFilterModel(null),
};
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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(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.feb(api)}
>2월만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.kim(api)}
>김 담당만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
</div>
<Grid style={{ height: 300 }} 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;
hired: Date;
owner: { id: number; label: string };
}
const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows: Row[] = [
{ id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 110 },
{
id: 'hired',
title: '입사 월',
kind: 'date',
width: 130,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => `${(value as Date).getMonth() + 1}월`,
},
{
id: 'owner',
title: '담당',
width: 130,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () =>
log({
ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
en: `${grid.getVisibleRowCount()} rows visible`,
}),
);
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
},
clear: (grid: GridApi<Row>) => grid.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">
<button type="button" :disabled="!api" @click="api && actions.feb(api)">2월만</button>
<button type="button" :disabled="!api" @click="api && actions.kim(api)">김 담당만</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
</div>
<Grid style="height: 300px" :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;
hired: Date;
owner: { id: number; label: string };
}
const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows: Row[] = [
{ id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 110 },
{
id: 'hired',
title: '입사 월',
kind: 'date',
width: 130,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => `${(value as Date).getMonth() + 1}월`,
},
{
id: 'owner',
title: '담당',
width: 130,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () =>
log({
ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
en: `${grid.getVisibleRowCount()} rows visible`,
}),
);
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
},
clear: (grid: GridApi<Row>) => grid.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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.feb(api)"
>2월만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.kim(api)"
>김 담당만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
</div>
<mx-grid style="height: 300px" [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;
hired: Date;
owner: { id: number; label: string };
}
const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows: Row[] = [
{ id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 110 },
{
id: 'hired',
title: '입사 월',
kind: 'date',
width: 130,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => `${(value as Date).getMonth() + 1}월`,
},
{
id: 'owner',
title: '담당',
width: 130,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () =>
log({
ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
en: `${grid.getVisibleRowCount()} rows visible`,
}),
);
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
},
clear: (grid: GridApi<Row>) => grid.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">
<button type="button" id="feb">Only February</button>
<button type="button" id="kim">Only Kim</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 300px"></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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows = [
{ id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'hired',
title: 'Hired month',
kind: 'date',
width: 160,
filter: { type: 'set' },
filterValue: ({ value }) => MONTHS[value.getMonth()],
},
{
id: 'owner',
title: 'Owner',
width: 150,
filter: { type: 'set' },
valueKey: (value) => `u${value.id}`,
formatValue: (value) => value.label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say = () => undefined;
export function setup(grid, log) {
say = log;
return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
export const actions = {
feb: (grid) => grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
}),
kim: (grid) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say('Filtered by the owner key u1.');
},
clear: (grid) => grid.setFilterModel(null),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the value the filter sees</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="feb">Only February</button>
<button type="button" id="kim">Only Kim</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows = [
{ id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
const options = {
columns: [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'hired',
title: 'Hired month',
kind: 'date',
width: 160,
filter: { type: 'set' },
filterValue: ({ value }) => MONTHS[value.getMonth()],
},
{
id: 'owner',
title: 'Owner',
width: 150,
filter: { type: 'set' },
valueKey: (value) => `u${value.id}`,
formatValue: (value) => value.label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say = () => undefined;
function setup(grid, log) {
say = log;
return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
const actions = {
feb: (grid) => grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
}),
kim: (grid) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say('Filtered by the owner key u1.');
},
clear: (grid) => grid.setFilterModel(null),
};
options.ariaLabel = "Change the value the filter sees";
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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(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.feb(api)}
>Only February</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.kim(api)}
>Only Kim</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
hired: Date;
owner: { id: number; label: string };
}
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows: Row[] = [
{ id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'hired',
title: 'Hired month',
kind: 'date',
width: 160,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => MONTHS[(value as Date).getMonth()] as string,
},
{
id: 'owner',
title: 'Owner',
width: 150,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say('Filtered by the owner key u1.');
},
clear: (grid: GridApi<Row>) => grid.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">
<button type="button" :disabled="!api" @click="api && actions.feb(api)">Only February</button>
<button type="button" :disabled="!api" @click="api && actions.kim(api)">Only Kim</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
hired: Date;
owner: { id: number; label: string };
}
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows: Row[] = [
{ id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'hired',
title: 'Hired month',
kind: 'date',
width: 160,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => MONTHS[(value as Date).getMonth()] as string,
},
{
id: 'owner',
title: 'Owner',
width: 150,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say('Filtered by the owner key u1.');
},
clear: (grid: GridApi<Row>) => grid.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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.feb(api)"
>Only February</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.kim(api)"
>Only Kim</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 300px" [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;
hired: Date;
owner: { id: number; label: string };
}
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows: Row[] = [
{ id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
{ id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
{ id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
{ id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'hired',
title: 'Hired month',
kind: 'date',
width: 160,
filter: { type: 'set' },
filterValue: ({ value }: { value: unknown }) => MONTHS[(value as Date).getMonth()] as string,
},
{
id: 'owner',
title: 'Owner',
width: 150,
filter: { type: 'set' },
valueKey: (value: unknown) => `u${(value as { id: number }).id}`,
formatValue: (value: unknown) => (value as { label: string }).label,
},
],
rows,
rowKey: 'id',
filterMenu: true,
filterRow: false,
};
let say: (message: LogText) => void = () => undefined;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
export const actions = {
feb: (grid: GridApi<Row>) =>
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
}),
kim: (grid: GridApi<Row>) => {
grid.setFilterModel({
match: 'all',
items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
});
say('Filtered by the owner key u1.');
},
clear: (grid: GridApi<Row>) => grid.setFilterModel(null),
};