필터 팝업을 코드로 열고 컬럼 필터 다루기Open the filter popup and edit one column's filter from code
openFilterMenu, closeFilterMenu로 팝업을 열고 닫고, getColumnFilter, setColumnFilter, clearColumnFilter로 컬럼 하나의 조건만 읽고 바꾸고 지워요. 열림, 닫힘은 filterMenuOpened, filterMenuClosed 이벤트로 알려요.Open and close the popup with openFilterMenu and closeFilterMenu, and read, set or clear the conditions of a single column with getColumnFilter, setColumnFilter and clearColumnFilter. filterMenuOpened and filterMenuClosed report it.
코드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="close">팝업 닫기</button>
<button type="button" id="set">연봉 5,000↑ 걸기</button>
<button type="button" id="clear">연봉 지우기</button>
</div>
<div id="grid" style="height: 480px"></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('close').addEventListener('click', () => actions.close(api));
document.getElementById('set').addEventListener('click', () => actions.set(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 팝업을 코드로 열고 닫고(openFilterMenu, closeFilterMenu, isFilterMenuOpen), 컬럼 하나의 필터를 읽고 쓰고 지워요
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). 열림·닫힘은 이벤트로 알려요.
export const options = {
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 3600 + ((i * 530) % 4600),
})),
rowKey: 'id',
};
export function setup(api, log) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log({ ko: `팝업 열림: ${columnId}`, en: `Popup opened: ${columnId}` })),
api.on('filterMenuClosed', ({ columnId, applied }) => log({
ko: `팝업 닫힘: ${columnId} (${applied ? '필터가 바뀜' : '바뀐 것 없음'})`,
en: `Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`,
})),
api.on('filterChanged', () => log({
ko: `필터 바뀜 · ${api.getVisibleRowCount()}행`,
en: `Filter changed · ${api.getVisibleRowCount()} rows`,
})),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api, value) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok)
throw new Error('openFilterMenu returned false');
},
close: (api) => api.closeFilterMenu(),
set: (api) => api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 5000 }]),
clear: (api) => api.clearColumnFilter('salary'),
};<!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="close">팝업 닫기</button>
<button type="button" id="set">연봉 5,000↑ 걸기</button>
<button type="button" id="clear">연봉 지우기</button>
</div>
<div id="grid" style="height: 480px"></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 = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 팝업을 코드로 열고 닫고(openFilterMenu, closeFilterMenu, isFilterMenuOpen), 컬럼 하나의 필터를 읽고 쓰고 지워요
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). 열림·닫힘은 이벤트로 알려요.
const options = {
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 3600 + ((i * 530) % 4600),
})),
rowKey: 'id',
};
function setup(api, log) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log({ ko: `팝업 열림: ${columnId}`, en: `Popup opened: ${columnId}` })),
api.on('filterMenuClosed', ({ columnId, applied }) => log({
ko: `팝업 닫힘: ${columnId} (${applied ? '필터가 바뀜' : '바뀐 것 없음'})`,
en: `Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`,
})),
api.on('filterChanged', () => log({
ko: `필터 바뀜 · ${api.getVisibleRowCount()}행`,
en: `Filter changed · ${api.getVisibleRowCount()} rows`,
})),
];
return () => offs.forEach((off) => off());
}
const actions = {
open: (api, value) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok)
throw new Error('openFilterMenu returned false');
},
close: (api) => api.closeFilterMenu(),
set: (api) => api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 5000 }]),
clear: (api) => api.clearColumnFilter('salary'),
};
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('close').addEventListener('click', () => actions.close(api));
document.getElementById('set').addEventListener('click', () => actions.set(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.close(api)}
>팝업 닫기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.set(api)}
>연봉 5,000↑ 걸기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>연봉 지우기</button>
</div>
<Grid style={{ height: 480 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 팝업을 코드로 열고 닫고(openFilterMenu, closeFilterMenu, isFilterMenuOpen), 컬럼 하나의 필터를 읽고 쓰고 지워요
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). 열림·닫힘은 이벤트로 알려요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) =>
log({ ko: `팝업 열림: ${columnId}`, en: `Popup opened: ${columnId}` }),
),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log({
ko: `팝업 닫힘: ${columnId} (${applied ? '필터가 바뀜' : '바뀐 것 없음'})`,
en: `Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`,
}),
),
api.on('filterChanged', () =>
log({
ko: `필터 바뀜 · ${api.getVisibleRowCount()}행`,
en: `Filter changed · ${api.getVisibleRowCount()} rows`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 5000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};버튼을 누르면 이 예제의 코드가 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.close(api)">팝업 닫기</button>
<button type="button" :disabled="!api" @click="api && actions.set(api)">연봉 5,000↑ 걸기</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">연봉 지우기</button>
</div>
<Grid style="height: 480px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 팝업을 코드로 열고 닫고(openFilterMenu, closeFilterMenu, isFilterMenuOpen), 컬럼 하나의 필터를 읽고 쓰고 지워요
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). 열림·닫힘은 이벤트로 알려요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) =>
log({ ko: `팝업 열림: ${columnId}`, en: `Popup opened: ${columnId}` }),
),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log({
ko: `팝업 닫힘: ${columnId} (${applied ? '필터가 바뀜' : '바뀐 것 없음'})`,
en: `Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`,
}),
),
api.on('filterChanged', () =>
log({
ko: `필터 바뀜 · ${api.getVisibleRowCount()}행`,
en: `Filter changed · ${api.getVisibleRowCount()} rows`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 5000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};버튼을 누르면 이 예제의 코드가 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.close(api)"
>팝업 닫기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.set(api)"
>연봉 5,000↑ 걸기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>연봉 지우기</button>
</div>
<mx-grid style="height: 480px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// 팝업을 코드로 열고 닫고(openFilterMenu, closeFilterMenu, isFilterMenuOpen), 컬럼 하나의 필터를 읽고 쓰고 지워요
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). 열림·닫힘은 이벤트로 알려요.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: '이름', width: 120 },
{ id: 'dept', title: '부서', width: 130 },
{ id: 'salary', title: '연봉(만원)', kind: 'number', width: 130, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) =>
log({ ko: `팝업 열림: ${columnId}`, en: `Popup opened: ${columnId}` }),
),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log({
ko: `팝업 닫힘: ${columnId} (${applied ? '필터가 바뀜' : '바뀐 것 없음'})`,
en: `Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`,
}),
),
api.on('filterChanged', () =>
log({
ko: `필터 바뀜 · ${api.getVisibleRowCount()}행`,
en: `Filter changed · ${api.getVisibleRowCount()} rows`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 5000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};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 Dept popup</button>
<button type="button" id="close">Close popup</button>
<button type="button" id="set">Set salary $50,000+</button>
<button type="button" id="clear">Clear salary</button>
</div>
<div id="grid" style="height: 480px"></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('close').addEventListener('click', () => actions.close(api));
document.getElementById('set').addEventListener('click', () => actions.set(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// Open and close the popup from code (openFilterMenu, closeFilterMenu, isFilterMenuOpen), and read, write and clear one column's filter
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). Open and close are reported as events.
export const options = {
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 140, align: 'end' },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 36000 + ((i * 5300) % 46000),
})),
rowKey: 'id',
};
export function setup(api, log) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log(`Popup opened: ${columnId}`)),
api.on('filterMenuClosed', ({ columnId, applied }) => log(`Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`)),
api.on('filterChanged', () => log(`Filter changed · ${api.getVisibleRowCount()} rows`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api, value) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok)
throw new Error('openFilterMenu returned false');
},
close: (api) => api.closeFilterMenu(),
set: (api) => api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 50000 }]),
clear: (api) => api.clearColumnFilter('salary'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Open the filter popup and edit one column's filter from code</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="open">Open Dept popup</button>
<button type="button" id="close">Close popup</button>
<button type="button" id="set">Set salary $50,000+</button>
<button type="button" id="clear">Clear salary</button>
</div>
<div id="grid" style="height: 480px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// Open and close the popup from code (openFilterMenu, closeFilterMenu, isFilterMenuOpen), and read, write and clear one column's filter
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). Open and close are reported as events.
const options = {
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 140, align: 'end' },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: names[i % 6],
dept: depts[(i * 3) % 4],
salary: 36000 + ((i * 5300) % 46000),
})),
rowKey: 'id',
};
function setup(api, log) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log(`Popup opened: ${columnId}`)),
api.on('filterMenuClosed', ({ columnId, applied }) => log(`Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`)),
api.on('filterChanged', () => log(`Filter changed · ${api.getVisibleRowCount()} rows`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
open: (api, value) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok)
throw new Error('openFilterMenu returned false');
},
close: (api) => api.closeFilterMenu(),
set: (api) => api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 50000 }]),
clear: (api) => api.clearColumnFilter('salary'),
};
options.ariaLabel = "Open the filter popup and edit one column's filter from code";
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('close').addEventListener('click', () => actions.close(api));
document.getElementById('set').addEventListener('click', () => actions.set(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 Dept popup</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.close(api)}
>Close popup</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.set(api)}
>Set salary $50,000+</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear salary</button>
</div>
<Grid style={{ height: 480 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// Open and close the popup from code (openFilterMenu, closeFilterMenu, isFilterMenuOpen), and read, write and clear one column's filter
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). Open and close are reported as events.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 140, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log(`Popup opened: ${columnId}`)),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log(`Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`),
),
api.on('filterChanged', () => log(`Filter changed · ${api.getVisibleRowCount()} rows`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 50000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};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 Dept popup</button>
<button type="button" :disabled="!api" @click="api && actions.close(api)">Close popup</button>
<button type="button" :disabled="!api" @click="api && actions.set(api)">Set salary $50,000+</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear salary</button>
</div>
<Grid style="height: 480px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// Open and close the popup from code (openFilterMenu, closeFilterMenu, isFilterMenuOpen), and read, write and clear one column's filter
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). Open and close are reported as events.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 140, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log(`Popup opened: ${columnId}`)),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log(`Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`),
),
api.on('filterChanged', () => log(`Filter changed · ${api.getVisibleRowCount()} rows`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 50000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};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 Dept popup</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.close(api)"
>Close popup</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.set(api)"
>Set salary $50,000+</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear salary</button>
</div>
<mx-grid style="height: 480px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
// Open and close the popup from code (openFilterMenu, closeFilterMenu, isFilterMenuOpen), and read, write and clear one column's filter
// (getColumnFilter, setColumnFilter, clearColumnFilter, isColumnFiltered, isFilterActive). Open and close are reported as events.
export const options: GridOptions<Row> = {
filterMenu: true,
columns: [
{ id: 'name', title: 'Name', width: 130 },
{ id: 'dept', title: 'Dept', width: 130 },
{ id: 'salary', title: 'Salary ($)', kind: 'number', width: 140, align: 'end' },
],
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),
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const offs = [
api.on('filterMenuOpened', ({ columnId }) => log(`Popup opened: ${columnId}`)),
api.on('filterMenuClosed', ({ columnId, applied }) =>
log(`Popup closed: ${columnId} (${applied ? 'filter changed' : 'no change'})`),
),
api.on('filterChanged', () => log(`Filter changed · ${api.getVisibleRowCount()} rows`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
const ok = api.openFilterMenu(value ?? 'dept');
if (!ok) throw new Error('openFilterMenu returned false');
},
close: (api: GridApi<Row>) => api.closeFilterMenu(),
set: (api: GridApi<Row>) =>
api.setColumnFilter('salary', [{ columnId: 'salary', operator: 'gte', value: 50000 }]),
clear: (api: GridApi<Row>) => api.clearColumnFilter('salary'),
};