필터 빌더로 조건을 그리고/또는/아님으로 쌓기Stack conditions with AND, OR and NOT in the filter builder
filterBuilder 옵션을 켜면 필터 팝업 아래에 "고급…" 버튼이 생겨요. 열리는 빌더에서 컬럼·연산자·값 조건을 더하고, 묶음(그룹)을 겹쳐서 "모두" 또는 "하나라도" 만족하게, 묶음 전체를 "아님(NOT)"으로 뒤집을 수 있어요.With the filterBuilder option on, the filter popup gets an "Advanced…" button. In the builder you add column, operator and value conditions, nest groups that must match "all" or "any", and flip a whole group with NOT.
코드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="open">필터 빌더 열기</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 470px"></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('open').addEventListener('click', () => actions.open(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발', '디자인', '영업', '인사'];
// filterBuilder: true — 필터 팝업 아래에 "고급…" 버튼이 생기고, 누르면 조건을 그리고/또는/아님으로 겹쳐 쌓는 필터 빌더가 열려요.
export const options = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 110 },
{ id: 'dept', title: '부서', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
{ id: 'active', title: '재직', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 3600 + ((i * 530) % 4600),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node) => 'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api, log) {
log({
ko: '"필터 빌더 열기"를 눌러 조건을 쌓아 보세요. 적용하면 보이는 줄이 바로 바뀌어요.',
en: 'Press "Open filter builder" and stack some conditions. Applying updates the rows at once.',
});
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
log({
ko: `필터 바뀜: 조건 ${tree === null ? 0 : countConditions(tree)}개 · ${api.getVisibleRowCount()}행`,
en: `Filter changed: ${tree === null ? 0 : countConditions(tree)} conditions · ${api.getVisibleRowCount()} rows`,
});
});
return off;
}
export const actions = {
open: (api) => void api.openFilterBuilder(),
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="open">필터 빌더 열기</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 470px"></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 = ['개발', '디자인', '영업', '인사'];
// filterBuilder: true — 필터 팝업 아래에 "고급…" 버튼이 생기고, 누르면 조건을 그리고/또는/아님으로 겹쳐 쌓는 필터 빌더가 열려요.
const options = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 110 },
{ id: 'dept', title: '부서', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
{ id: 'active', title: '재직', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 3600 + ((i * 530) % 4600),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node) => 'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
function setup(api, log) {
log({
ko: '"필터 빌더 열기"를 눌러 조건을 쌓아 보세요. 적용하면 보이는 줄이 바로 바뀌어요.',
en: 'Press "Open filter builder" and stack some conditions. Applying updates the rows at once.',
});
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
log({
ko: `필터 바뀜: 조건 ${tree === null ? 0 : countConditions(tree)}개 · ${api.getVisibleRowCount()}행`,
en: `Filter changed: ${tree === null ? 0 : countConditions(tree)} conditions · ${api.getVisibleRowCount()} rows`,
});
});
return off;
}
const actions = {
open: (api) => void api.openFilterBuilder(),
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('open').addEventListener('click', () => actions.open(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.open(api)}
>필터 빌더 열기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
</div>
<Grid style={{ height: 470 }} ref={gridRef} options={options} />
</>
);
}import type { FilterNode, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발', '디자인', '영업', '인사'];
// filterBuilder: true — 필터 팝업 아래에 "고급…" 버튼이 생기고, 누르면 조건을 그리고/또는/아님으로 겹쳐 쌓는 필터 빌더가 열려요.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 110 },
{ id: 'dept', title: '부서', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
{ id: 'active', title: '재직', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 3600 + ((i * 530) % 4600),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"필터 빌더 열기"를 눌러 조건을 쌓아 보세요. 적용하면 보이는 줄이 바로 바뀌어요.',
en: 'Press "Open filter builder" and stack some conditions. Applying updates the rows at once.',
});
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
log({
ko: `필터 바뀜: 조건 ${tree === null ? 0 : countConditions(tree)}개 · ${api.getVisibleRowCount()}행`,
en: `Filter changed: ${tree === null ? 0 : countConditions(tree)} conditions · ${api.getVisibleRowCount()} rows`,
});
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
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.open(api)">필터 빌더 열기</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
</div>
<Grid style="height: 470px" :options="options" @ready="onReady" />
</template>import type { FilterNode, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발', '디자인', '영업', '인사'];
// filterBuilder: true — 필터 팝업 아래에 "고급…" 버튼이 생기고, 누르면 조건을 그리고/또는/아님으로 겹쳐 쌓는 필터 빌더가 열려요.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 110 },
{ id: 'dept', title: '부서', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
{ id: 'active', title: '재직', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 3600 + ((i * 530) % 4600),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"필터 빌더 열기"를 눌러 조건을 쌓아 보세요. 적용하면 보이는 줄이 바로 바뀌어요.',
en: 'Press "Open filter builder" and stack some conditions. Applying updates the rows at once.',
});
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
log({
ko: `필터 바뀜: 조건 ${tree === null ? 0 : countConditions(tree)}개 · ${api.getVisibleRowCount()}행`,
en: `Filter changed: ${tree === null ? 0 : countConditions(tree)} conditions · ${api.getVisibleRowCount()} rows`,
});
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
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.open(api)"
>필터 빌더 열기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
</div>
<mx-grid style="height: 470px" [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 { FilterNode, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발', '디자인', '영업', '인사'];
// filterBuilder: true — 필터 팝업 아래에 "고급…" 버튼이 생기고, 누르면 조건을 그리고/또는/아님으로 겹쳐 쌓는 필터 빌더가 열려요.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 110 },
{ id: 'dept', title: '부서', width: 100 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
{ id: 'active', title: '재직', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 3600 + ((i * 530) % 4600),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"필터 빌더 열기"를 눌러 조건을 쌓아 보세요. 적용하면 보이는 줄이 바로 바뀌어요.',
en: 'Press "Open filter builder" and stack some conditions. Applying updates the rows at once.',
});
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
log({
ko: `필터 바뀜: 조건 ${tree === null ? 0 : countConditions(tree)}개 · ${api.getVisibleRowCount()}행`,
en: `Filter changed: ${tree === null ? 0 : countConditions(tree)} conditions · ${api.getVisibleRowCount()} rows`,
});
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
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="open">Open filter builder</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 470px"></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('open').addEventListener('click', () => actions.open(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Sophia Lane',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// filterBuilder: true adds an "Advanced…" button under the filter popup. It opens the filter builder, where you stack conditions with all / any / NOT.
export const options = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 100 },
{
id: 'salary',
title: 'Salary (USD)',
kind: 'number',
width: 140,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{ id: 'active', title: 'Active', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 36000 + ((i * 5300) % 46000),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node) => 'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api, log) {
log('Press "Open filter builder" and stack some conditions. Applying updates the rows at once.');
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
const count = tree === null ? 0 : countConditions(tree);
log(`Filter changed: ${count} ${count === 1 ? 'condition' : 'conditions'} · ${api.getVisibleRowCount()} rows`);
});
return off;
}
export const actions = {
open: (api) => void api.openFilterBuilder(),
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>Stack conditions with AND, OR and NOT in the filter builder</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="open">Open filter builder</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 470px"></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 Brooks',
'Olivia Reed',
'Ethan Hayes',
'Sophia Lane',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// filterBuilder: true adds an "Advanced…" button under the filter popup. It opens the filter builder, where you stack conditions with all / any / NOT.
const options = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 100 },
{
id: 'salary',
title: 'Salary (USD)',
kind: 'number',
width: 140,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{ id: 'active', title: 'Active', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 36000 + ((i * 5300) % 46000),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node) => 'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
function setup(api, log) {
log('Press "Open filter builder" and stack some conditions. Applying updates the rows at once.');
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
const count = tree === null ? 0 : countConditions(tree);
log(`Filter changed: ${count} ${count === 1 ? 'condition' : 'conditions'} · ${api.getVisibleRowCount()} rows`);
});
return off;
}
const actions = {
open: (api) => void api.openFilterBuilder(),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "Stack conditions with AND, OR and NOT in the filter builder";
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('open').addEventListener('click', () => actions.open(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.open(api)}
>Open filter builder</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 470 }} ref={gridRef} options={options} />
</>
);
}import type { FilterNode, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Sophia Lane',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// filterBuilder: true adds an "Advanced…" button under the filter popup. It opens the filter builder, where you stack conditions with all / any / NOT.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 100 },
{
id: 'salary',
title: 'Salary (USD)',
kind: 'number',
width: 140,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{ id: 'active', title: 'Active', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 36000 + ((i * 5300) % 46000),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Press "Open filter builder" and stack some conditions. Applying updates the rows at once.');
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
const count = tree === null ? 0 : countConditions(tree);
log(
`Filter changed: ${count} ${count === 1 ? 'condition' : 'conditions'} · ${api.getVisibleRowCount()} rows`,
);
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
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.open(api)">Open filter builder</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
</div>
<Grid style="height: 470px" :options="options" @ready="onReady" />
</template>import type { FilterNode, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Sophia Lane',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// filterBuilder: true adds an "Advanced…" button under the filter popup. It opens the filter builder, where you stack conditions with all / any / NOT.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 100 },
{
id: 'salary',
title: 'Salary (USD)',
kind: 'number',
width: 140,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{ id: 'active', title: 'Active', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 36000 + ((i * 5300) % 46000),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Press "Open filter builder" and stack some conditions. Applying updates the rows at once.');
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
const count = tree === null ? 0 : countConditions(tree);
log(
`Filter changed: ${count} ${count === 1 ? 'condition' : 'conditions'} · ${api.getVisibleRowCount()} rows`,
);
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
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.open(api)"
>Open filter builder</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 470px" [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 { FilterNode, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
active: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Sophia Lane',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// filterBuilder: true adds an "Advanced…" button under the filter popup. It opens the filter builder, where you stack conditions with all / any / NOT.
export const options: GridOptions<Row> = {
filterBuilder: true,
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 100 },
{
id: 'salary',
title: 'Salary (USD)',
kind: 'number',
width: 140,
align: 'end',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
},
{ id: 'active', title: 'Active', kind: 'boolean', width: 90 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6] as string,
dept: depts[(i * 3) % 4] as string,
salary: 36000 + ((i * 5300) % 46000),
active: i % 5 !== 0,
})),
rowKey: 'id',
};
const countConditions = (node: FilterNode): number =>
'children' in node ? node.children.reduce((sum, child) => sum + countConditions(child), 0) : 1;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Press "Open filter builder" and stack some conditions. Applying updates the rows at once.');
const off = api.on('filterChanged', () => {
const tree = api.getFilterTree();
const count = tree === null ? 0 : countConditions(tree);
log(
`Filter changed: ${count} ${count === 1 ? 'condition' : 'conditions'} · ${api.getVisibleRowCount()} rows`,
);
});
return off;
}
export const actions = {
open: (api: GridApi<Row>) => void api.openFilterBuilder(),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};