조건 두 개를 '그리고'·'또는'으로 묶기Combine two conditions with AND or OR
헤더의 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'(둘 다)나 '또는'(하나라도)으로 묶어요. 예를 들어 상품 이름에 '무선'이 있으면서 '이어폰'도 있는 것, 숫자는 '5만 원 이하 또는 20만 원 이상'처럼 양 끝도 고를 수 있어요.In the header funnel popup, put up to two conditions on a column and join them with AND or OR: product names with both words, or prices of $50 or less OR $200 or more.
코드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="both">상품: 무선 그리고 이어폰</button>
<button type="button" id="either">상품: 무선 또는 이어폰</button>
<button type="button" id="priceEnds">가격: 5만 원 이하 또는 20만 원 이상</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 440px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
'무선 이어폰',
'무선 키보드',
'무선 충전기',
'유선 이어폰',
'블루투스 스피커',
'노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
export const options = {
filterMenu: true,
columns: [
{ id: 'customer', title: '고객사', width: 140 },
{ id: 'product', title: '상품', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
product: products[(i * 5) % 6],
quantity: 1 + ((i * 7) % 12),
price: 19000 + ((i * 47000) % 260000),
})),
rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE = {
customer: '고객사',
product: '상품',
quantity: '수량',
price: '가격',
};
const OP_EN = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
const OP = {
contains: '포함',
notContains: '포함하지 않음',
equals: '같음',
notEquals: '같지 않음',
startsWith: '시작',
endsWith: '끝',
gt: '초과',
gte: '이상',
lt: '미만',
lte: '이하',
between: '사이',
in: '선택값',
isEmpty: '비어 있음',
isNotEmpty: '비어 있지 않음',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
// 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
const byColumn = new Map();
for (const i of filterModel?.items ?? []) {
const value = typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
const text = [
`${value} ${OP[i.operator] ?? i.operator}`,
`${value} ${OP_EN[i.operator] ?? i.operator}`,
];
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return {
ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
};
});
const rows = api.getVisibleRowCount();
log(parts.length === 0
? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
: {
ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
});
});
return () => off();
}
export const actions = {
// 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
both: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'all' },
}),
either: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'any' },
}),
// 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
priceEnds: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50000 },
{ columnId: 'price', operator: 'gte', value: 200000 },
],
columnMatch: { price: '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>조건 두 개를 '그리고'·'또는'으로 묶기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="both">상품: 무선 그리고 이어폰</button>
<button type="button" id="either">상품: 무선 또는 이어폰</button>
<button type="button" id="priceEnds">가격: 5만 원 이하 또는 20만 원 이상</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 440px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
'무선 이어폰',
'무선 키보드',
'무선 충전기',
'유선 이어폰',
'블루투스 스피커',
'노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
const options = {
filterMenu: true,
columns: [
{ id: 'customer', title: '고객사', width: 140 },
{ id: 'product', title: '상품', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
product: products[(i * 5) % 6],
quantity: 1 + ((i * 7) % 12),
price: 19000 + ((i * 47000) % 260000),
})),
rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE = {
customer: '고객사',
product: '상품',
quantity: '수량',
price: '가격',
};
const OP_EN = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
const OP = {
contains: '포함',
notContains: '포함하지 않음',
equals: '같음',
notEquals: '같지 않음',
startsWith: '시작',
endsWith: '끝',
gt: '초과',
gte: '이상',
lt: '미만',
lte: '이하',
between: '사이',
in: '선택값',
isEmpty: '비어 있음',
isNotEmpty: '비어 있지 않음',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
// 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
const byColumn = new Map();
for (const i of filterModel?.items ?? []) {
const value = typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
const text = [
`${value} ${OP[i.operator] ?? i.operator}`,
`${value} ${OP_EN[i.operator] ?? i.operator}`,
];
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return {
ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
};
});
const rows = api.getVisibleRowCount();
log(parts.length === 0
? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
: {
ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
});
});
return () => off();
}
const actions = {
// 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
both: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'all' },
}),
either: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'any' },
}),
// 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
priceEnds: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50000 },
{ columnId: 'price', operator: 'gte', value: 200000 },
],
columnMatch: { price: 'any' },
}),
clear: (api) => api.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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(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.both(api)}
>상품: 무선 그리고 이어폰</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.either(api)}
>상품: 무선 또는 이어폰</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.priceEnds(api)}
>가격: 5만 원 이하 또는 20만 원 이상</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
'무선 이어폰',
'무선 키보드',
'무선 충전기',
'유선 이어폰',
'블루투스 스피커',
'노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: '고객사', width: 140 },
{ id: 'product', title: '상품', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19000 + ((i * 47000) % 260000),
})),
rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE: Record<string, string> = {
customer: '고객사',
product: '상품',
quantity: '수량',
price: '가격',
};
const OP_EN: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
const OP: Record<string, string> = {
contains: '포함',
notContains: '포함하지 않음',
equals: '같음',
notEquals: '같지 않음',
startsWith: '시작',
endsWith: '끝',
gt: '초과',
gte: '이상',
lt: '미만',
lte: '이하',
between: '사이',
in: '선택값',
isEmpty: '비어 있음',
isNotEmpty: '비어 있지 않음',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
const byColumn = new Map<string, [string, string][]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
const text: [string, string] = [
`${value} ${OP[i.operator] ?? i.operator}`,
`${value} ${OP_EN[i.operator] ?? i.operator}`,
];
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return {
ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
};
});
const rows = api.getVisibleRowCount();
log(
parts.length === 0
? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
: {
ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
},
);
});
return () => off();
}
export const actions = {
// 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'any' },
}),
// 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50000 },
{ columnId: 'price', operator: 'gte', value: 200000 },
],
columnMatch: { price: '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">
<button type="button" :disabled="!api" @click="api && actions.both(api)">상품: 무선 그리고 이어폰</button>
<button type="button" :disabled="!api" @click="api && actions.either(api)">상품: 무선 또는 이어폰</button>
<button
type="button"
:disabled="!api"
@click="api && actions.priceEnds(api)"
>가격: 5만 원 이하 또는 20만 원 이상</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
</div>
<Grid style="height: 440px" :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;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
'무선 이어폰',
'무선 키보드',
'무선 충전기',
'유선 이어폰',
'블루투스 스피커',
'노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: '고객사', width: 140 },
{ id: 'product', title: '상품', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19000 + ((i * 47000) % 260000),
})),
rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE: Record<string, string> = {
customer: '고객사',
product: '상품',
quantity: '수량',
price: '가격',
};
const OP_EN: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
const OP: Record<string, string> = {
contains: '포함',
notContains: '포함하지 않음',
equals: '같음',
notEquals: '같지 않음',
startsWith: '시작',
endsWith: '끝',
gt: '초과',
gte: '이상',
lt: '미만',
lte: '이하',
between: '사이',
in: '선택값',
isEmpty: '비어 있음',
isNotEmpty: '비어 있지 않음',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
const byColumn = new Map<string, [string, string][]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
const text: [string, string] = [
`${value} ${OP[i.operator] ?? i.operator}`,
`${value} ${OP_EN[i.operator] ?? i.operator}`,
];
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return {
ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
};
});
const rows = api.getVisibleRowCount();
log(
parts.length === 0
? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
: {
ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
},
);
});
return () => off();
}
export const actions = {
// 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'any' },
}),
// 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50000 },
{ columnId: 'price', operator: 'gte', value: 200000 },
],
columnMatch: { price: '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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.both(api)"
>상품: 무선 그리고 이어폰</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.either(api)"
>상품: 무선 또는 이어폰</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.priceEnds(api)"
>가격: 5만 원 이하 또는 20만 원 이상</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
</div>
<mx-grid style="height: 440px" [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;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
'무선 이어폰',
'무선 키보드',
'무선 충전기',
'유선 이어폰',
'블루투스 스피커',
'노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: '고객사', width: 140 },
{ id: 'product', title: '상품', width: 170 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: '가격(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19000 + ((i * 47000) % 260000),
})),
rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE: Record<string, string> = {
customer: '고객사',
product: '상품',
quantity: '수량',
price: '가격',
};
const OP_EN: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
const OP: Record<string, string> = {
contains: '포함',
notContains: '포함하지 않음',
equals: '같음',
notEquals: '같지 않음',
startsWith: '시작',
endsWith: '끝',
gt: '초과',
gte: '이상',
lt: '미만',
lte: '이하',
between: '사이',
in: '선택값',
isEmpty: '비어 있음',
isNotEmpty: '비어 있지 않음',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
const byColumn = new Map<string, [string, string][]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
const text: [string, string] = [
`${value} ${OP[i.operator] ?? i.operator}`,
`${value} ${OP_EN[i.operator] ?? i.operator}`,
];
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return {
ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
};
});
const rows = api.getVisibleRowCount();
log(
parts.length === 0
? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
: {
ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
},
);
});
return () => off();
}
export const actions = {
// 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: '무선' },
{ columnId: 'product', operator: 'contains', value: '이어폰' },
],
columnMatch: { product: 'any' },
}),
// 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50000 },
{ columnId: 'price', operator: 'gte', value: 200000 },
],
columnMatch: { price: '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">
<button type="button" id="both">Product: Wireless AND Earbuds</button>
<button type="button" id="either">Product: Wireless OR Earbuds</button>
<button type="button" id="priceEnds">Price: ≤$50 or ≥$200</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 440px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const customers = [
'Harbor Logistics',
'Bluesky Foods',
'Polaris Trading',
'Evergreen Supply',
'Dawn Farms',
'Mode Fashion',
];
const products = [
'Wireless Earbuds',
'Wireless Keyboard',
'Wireless Charger',
'Wired Earbuds',
'Bluetooth Speaker',
'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
export const options = {
filterMenu: true,
columns: [
{ id: 'customer', title: 'Customer', width: 160 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
product: products[(i * 5) % 6],
quantity: 1 + ((i * 7) % 12),
price: 19 + ((i * 47) % 260),
})),
rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE = {
customer: 'Customer',
product: 'Product',
quantity: 'Qty',
price: 'Price',
};
const OP = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
// Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
const byColumn = new Map();
for (const i of filterModel?.items ?? []) {
const value = typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
const text = `${value} ${OP[i.operator] ?? i.operator}`;
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
});
const rows = api.getVisibleRowCount();
log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
});
return () => off();
}
export const actions = {
// The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
both: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'all' },
}),
either: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'any' },
}),
// Numbers work the same way: $50 or less OR $200 or more
priceEnds: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50 },
{ columnId: 'price', operator: 'gte', value: 200 },
],
columnMatch: { price: '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>Combine two conditions with AND or OR</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="both">Product: Wireless AND Earbuds</button>
<button type="button" id="either">Product: Wireless OR Earbuds</button>
<button type="button" id="priceEnds">Price: ≤$50 or ≥$200</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 440px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'Harbor Logistics',
'Bluesky Foods',
'Polaris Trading',
'Evergreen Supply',
'Dawn Farms',
'Mode Fashion',
];
const products = [
'Wireless Earbuds',
'Wireless Keyboard',
'Wireless Charger',
'Wired Earbuds',
'Bluetooth Speaker',
'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
const options = {
filterMenu: true,
columns: [
{ id: 'customer', title: 'Customer', width: 160 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
product: products[(i * 5) % 6],
quantity: 1 + ((i * 7) % 12),
price: 19 + ((i * 47) % 260),
})),
rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE = {
customer: 'Customer',
product: 'Product',
quantity: 'Qty',
price: 'Price',
};
const OP = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => {
// Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
const byColumn = new Map();
for (const i of filterModel?.items ?? []) {
const value = typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
const text = `${value} ${OP[i.operator] ?? i.operator}`;
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
});
const rows = api.getVisibleRowCount();
log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
});
return () => off();
}
const actions = {
// The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
both: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'all' },
}),
either: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'any' },
}),
// Numbers work the same way: $50 or less OR $200 or more
priceEnds: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50 },
{ columnId: 'price', operator: 'gte', value: 200 },
],
columnMatch: { price: 'any' },
}),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "Combine two conditions with AND or OR";
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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(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.both(api)}
>Product: Wireless AND Earbuds</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.either(api)}
>Product: Wireless OR Earbuds</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.priceEnds(api)}
>Price: ≤$50 or ≥$200</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = [
'Harbor Logistics',
'Bluesky Foods',
'Polaris Trading',
'Evergreen Supply',
'Dawn Farms',
'Mode Fashion',
];
const products = [
'Wireless Earbuds',
'Wireless Keyboard',
'Wireless Charger',
'Wired Earbuds',
'Bluetooth Speaker',
'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: 'Customer', width: 160 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19 + ((i * 47) % 260),
})),
rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE: Record<string, string> = {
customer: 'Customer',
product: 'Product',
quantity: 'Qty',
price: 'Price',
};
const OP: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
const byColumn = new Map<string, string[]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
const text = `${value} ${OP[i.operator] ?? i.operator}`;
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
});
const rows = api.getVisibleRowCount();
log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
});
return () => off();
}
export const actions = {
// The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'any' },
}),
// Numbers work the same way: $50 or less OR $200 or more
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50 },
{ columnId: 'price', operator: 'gte', value: 200 },
],
columnMatch: { price: '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">
<button type="button" :disabled="!api" @click="api && actions.both(api)">Product: Wireless AND Earbuds</button>
<button type="button" :disabled="!api" @click="api && actions.either(api)">Product: Wireless OR Earbuds</button>
<button
type="button"
:disabled="!api"
@click="api && actions.priceEnds(api)"
>Price: ≤$50 or ≥$200</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
</div>
<Grid style="height: 440px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = [
'Harbor Logistics',
'Bluesky Foods',
'Polaris Trading',
'Evergreen Supply',
'Dawn Farms',
'Mode Fashion',
];
const products = [
'Wireless Earbuds',
'Wireless Keyboard',
'Wireless Charger',
'Wired Earbuds',
'Bluetooth Speaker',
'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: 'Customer', width: 160 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19 + ((i * 47) % 260),
})),
rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE: Record<string, string> = {
customer: 'Customer',
product: 'Product',
quantity: 'Qty',
price: 'Price',
};
const OP: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
const byColumn = new Map<string, string[]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
const text = `${value} ${OP[i.operator] ?? i.operator}`;
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
});
const rows = api.getVisibleRowCount();
log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
});
return () => off();
}
export const actions = {
// The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'any' },
}),
// Numbers work the same way: $50 or less OR $200 or more
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50 },
{ columnId: 'price', operator: 'gte', value: 200 },
],
columnMatch: { price: '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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.both(api)"
>Product: Wireless AND Earbuds</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.either(api)"
>Product: Wireless OR Earbuds</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.priceEnds(api)"
>Price: ≤$50 or ≥$200</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 440px" [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;
customer: string;
product: string;
quantity: number;
price: number;
}
const customers = [
'Harbor Logistics',
'Bluesky Foods',
'Polaris Trading',
'Evergreen Supply',
'Dawn Farms',
'Mode Fashion',
];
const products = [
'Wireless Earbuds',
'Wireless Keyboard',
'Wireless Charger',
'Wired Earbuds',
'Bluetooth Speaker',
'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'customer', title: 'Customer', width: 160 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
product: products[(i * 5) % 6] as string,
quantity: 1 + ((i * 7) % 12),
price: 19 + ((i * 47) % 260),
})),
rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE: Record<string, string> = {
customer: 'Customer',
product: 'Product',
quantity: 'Qty',
price: 'Price',
};
const OP: Record<string, string> = {
contains: 'contains',
notContains: 'does not contain',
equals: 'equals',
notEquals: 'does not equal',
startsWith: 'starts with',
endsWith: 'ends with',
gt: 'greater than',
gte: 'at least',
lt: 'less than',
lte: 'at most',
between: 'between',
in: 'one of',
isEmpty: 'is empty',
isNotEmpty: 'is not empty',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) => {
// Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
const byColumn = new Map<string, string[]>();
for (const i of filterModel?.items ?? []) {
const value =
typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
const text = `${value} ${OP[i.operator] ?? i.operator}`;
byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
}
const parts = [...byColumn].map(([id, texts]) => {
const any = filterModel?.columnMatch?.[id] === 'any';
return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
});
const rows = api.getVisibleRowCount();
log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
});
return () => off();
}
export const actions = {
// The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
both: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'all' },
}),
either: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'product', operator: 'contains', value: 'Wireless' },
{ columnId: 'product', operator: 'contains', value: 'Earbuds' },
],
columnMatch: { product: 'any' },
}),
// Numbers work the same way: $50 or less OR $200 or more
priceEnds: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'price', operator: 'lte', value: 50 },
{ columnId: 'price', operator: 'gte', value: 200 },
],
columnMatch: { price: 'any' },
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};