트리 표에서 걸러도 부모는 남아요Filtering a tree keeps the parents
프로젝트 단계와 작업처럼 부모·자식이 있는 표를 필터해도, 조건에 맞는 작업 위의 부모는 함께 남아서 어디에 속한 작업인지 알 수 있어요. 펼치고 접는 것도 필터와 따로 할 수 있어요.Filtering a parent-child table keeps the ancestors of every match, so you still see where a task belongs. Expanding and collapsing is independent of the filter.
코드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="parkOnly">박지호 담당만</button>
<button type="button" id="planned">예정인 작업만</button>
<button type="button" id="clear">필터 지우기</button>
<select aria-label="펼침 상태" id="depth">
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<div id="grid" style="height: 420px"></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('parkOnly').addEventListener('click', () => actions.parkOnly(api));
document.getElementById('planned').addEventListener('click', () => actions.planned(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
// 프로젝트 계획표: 단계 아래에 작업이 달려 있어요(부모 키로 이은 트리).
export const options = {
filterRow: true,
columns: [
{
id: 'task',
title: '작업',
width: 220,
filter: { placeholder: L('작업 이름…', 'Task name…') },
},
{ id: 'owner', title: '담당', kind: 'select', width: 110 },
{ id: 'status', title: '상태', kind: 'select', width: 110 },
{ id: 'hours', title: '공수(시간)', kind: 'number', width: 120, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: '기획', owner: '이서연', status: '완료', hours: 40 },
{ id: 2, parentId: 1, task: '사용자 인터뷰', owner: '이서연', status: '완료', hours: 24 },
{ id: 3, parentId: 1, task: '요구사항 정리', owner: '박지호', status: '완료', hours: 16 },
{ id: 4, parentId: null, task: '개발', owner: '김민준', status: '진행', hours: 160 },
{ id: 5, parentId: 4, task: '서버 API', owner: '김민준', status: '진행', hours: 80 },
{ id: 6, parentId: 4, task: '화면 구현', owner: '최유나', status: '진행', hours: 60 },
{ id: 7, parentId: 4, task: '리포트 기능', owner: '박지호', status: '예정', hours: 20 },
{ id: 8, parentId: null, task: '출시', owner: '최유나', status: '예정', hours: 30 },
{ id: 9, parentId: 8, task: '사용자 교육', owner: '최유나', status: '예정', hours: 18 },
{ id: 10, parentId: 8, task: '서비스 오픈', owner: '김민준', status: '예정', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// 트리에서 필터는 "조건에 맞는 행과 그 부모들"을 남겨요. 맞는 작업이 부모 없이 떠 있지 않게요.
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api, log) {
const off = api.on('filterChanged', () => log({
ko: `보이는 행 ${api.getVisibleRowCount()}개`,
en: `${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
export const actions = {
// 박지호 담당 작업만: 부모(기획, 개발)는 함께 남아요.
parkOnly: (api) => show(api, [{ columnId: 'owner', operator: 'equals', value: '박지호' }]),
// 예정인 작업만
planned: (api) => show(api, [{ columnId: 'status', operator: 'equals', value: '예정' }]),
clear: (api) => api.setFilterModel(null),
// 펼침 상태는 필터와 따로 바꿀 수 있어요.
depth: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};<!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="parkOnly">박지호 담당만</button>
<button type="button" id="planned">예정인 작업만</button>
<button type="button" id="clear">필터 지우기</button>
<select aria-label="펼침 상태" id="depth">
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
// 프로젝트 계획표: 단계 아래에 작업이 달려 있어요(부모 키로 이은 트리).
const options = {
filterRow: true,
columns: [
{
id: 'task',
title: '작업',
width: 220,
filter: { placeholder: L('작업 이름…', 'Task name…') },
},
{ id: 'owner', title: '담당', kind: 'select', width: 110 },
{ id: 'status', title: '상태', kind: 'select', width: 110 },
{ id: 'hours', title: '공수(시간)', kind: 'number', width: 120, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: '기획', owner: '이서연', status: '완료', hours: 40 },
{ id: 2, parentId: 1, task: '사용자 인터뷰', owner: '이서연', status: '완료', hours: 24 },
{ id: 3, parentId: 1, task: '요구사항 정리', owner: '박지호', status: '완료', hours: 16 },
{ id: 4, parentId: null, task: '개발', owner: '김민준', status: '진행', hours: 160 },
{ id: 5, parentId: 4, task: '서버 API', owner: '김민준', status: '진행', hours: 80 },
{ id: 6, parentId: 4, task: '화면 구현', owner: '최유나', status: '진행', hours: 60 },
{ id: 7, parentId: 4, task: '리포트 기능', owner: '박지호', status: '예정', hours: 20 },
{ id: 8, parentId: null, task: '출시', owner: '최유나', status: '예정', hours: 30 },
{ id: 9, parentId: 8, task: '사용자 교육', owner: '최유나', status: '예정', hours: 18 },
{ id: 10, parentId: 8, task: '서비스 오픈', owner: '김민준', status: '예정', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// 트리에서 필터는 "조건에 맞는 행과 그 부모들"을 남겨요. 맞는 작업이 부모 없이 떠 있지 않게요.
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
function setup(api, log) {
const off = api.on('filterChanged', () => log({
ko: `보이는 행 ${api.getVisibleRowCount()}개`,
en: `${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
const actions = {
// 박지호 담당 작업만: 부모(기획, 개발)는 함께 남아요.
parkOnly: (api) => show(api, [{ columnId: 'owner', operator: 'equals', value: '박지호' }]),
// 예정인 작업만
planned: (api) => show(api, [{ columnId: 'status', operator: 'equals', value: '예정' }]),
clear: (api) => api.setFilterModel(null),
// 펼침 상태는 필터와 따로 바꿀 수 있어요.
depth: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};
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('parkOnly').addEventListener('click', () => actions.parkOnly(api));
document.getElementById('planned').addEventListener('click', () => actions.planned(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
</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.parkOnly(api)}
>박지호 담당만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.planned(api)}
>예정인 작업만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
<select
aria-label="펼침 상태"
disabled={!api}
onChange={(event) => api && actions.depth(api, event.target.value)}
>
<option value="all">모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// 프로젝트 계획표: 단계 아래에 작업이 달려 있어요(부모 키로 이은 트리).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: '작업',
width: 220,
filter: { placeholder: L('작업 이름…', 'Task name…') },
},
{ id: 'owner', title: '담당', kind: 'select', width: 110 },
{ id: 'status', title: '상태', kind: 'select', width: 110 },
{ id: 'hours', title: '공수(시간)', kind: 'number', width: 120, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: '기획', owner: '이서연', status: '완료', hours: 40 },
{ id: 2, parentId: 1, task: '사용자 인터뷰', owner: '이서연', status: '완료', hours: 24 },
{ id: 3, parentId: 1, task: '요구사항 정리', owner: '박지호', status: '완료', hours: 16 },
{ id: 4, parentId: null, task: '개발', owner: '김민준', status: '진행', hours: 160 },
{ id: 5, parentId: 4, task: '서버 API', owner: '김민준', status: '진행', hours: 80 },
{ id: 6, parentId: 4, task: '화면 구현', owner: '최유나', status: '진행', hours: 60 },
{ id: 7, parentId: 4, task: '리포트 기능', owner: '박지호', status: '예정', hours: 20 },
{ id: 8, parentId: null, task: '출시', owner: '최유나', status: '예정', hours: 30 },
{ id: 9, parentId: 8, task: '사용자 교육', owner: '최유나', status: '예정', hours: 18 },
{ id: 10, parentId: 8, task: '서비스 오픈', owner: '김민준', status: '예정', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// 트리에서 필터는 "조건에 맞는 행과 그 부모들"을 남겨요. 맞는 작업이 부모 없이 떠 있지 않게요.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()}개`,
en: `${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 박지호 담당 작업만: 부모(기획, 개발)는 함께 남아요.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: '박지호' }]),
// 예정인 작업만
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: '예정' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// 펼침 상태는 필터와 따로 바꿀 수 있어요.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};버튼을 누르면 이 예제의 코드가 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.parkOnly(api)"
>박지호 담당만</button>
<button type="button" :disabled="!api" @click="api && actions.planned(api)">예정인 작업만</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
<select
aria-label="펼침 상태"
:disabled="!api"
@change="api && actions.depth(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// 프로젝트 계획표: 단계 아래에 작업이 달려 있어요(부모 키로 이은 트리).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: '작업',
width: 220,
filter: { placeholder: L('작업 이름…', 'Task name…') },
},
{ id: 'owner', title: '담당', kind: 'select', width: 110 },
{ id: 'status', title: '상태', kind: 'select', width: 110 },
{ id: 'hours', title: '공수(시간)', kind: 'number', width: 120, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: '기획', owner: '이서연', status: '완료', hours: 40 },
{ id: 2, parentId: 1, task: '사용자 인터뷰', owner: '이서연', status: '완료', hours: 24 },
{ id: 3, parentId: 1, task: '요구사항 정리', owner: '박지호', status: '완료', hours: 16 },
{ id: 4, parentId: null, task: '개발', owner: '김민준', status: '진행', hours: 160 },
{ id: 5, parentId: 4, task: '서버 API', owner: '김민준', status: '진행', hours: 80 },
{ id: 6, parentId: 4, task: '화면 구현', owner: '최유나', status: '진행', hours: 60 },
{ id: 7, parentId: 4, task: '리포트 기능', owner: '박지호', status: '예정', hours: 20 },
{ id: 8, parentId: null, task: '출시', owner: '최유나', status: '예정', hours: 30 },
{ id: 9, parentId: 8, task: '사용자 교육', owner: '최유나', status: '예정', hours: 18 },
{ id: 10, parentId: 8, task: '서비스 오픈', owner: '김민준', status: '예정', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// 트리에서 필터는 "조건에 맞는 행과 그 부모들"을 남겨요. 맞는 작업이 부모 없이 떠 있지 않게요.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()}개`,
en: `${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 박지호 담당 작업만: 부모(기획, 개발)는 함께 남아요.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: '박지호' }]),
// 예정인 작업만
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: '예정' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// 펼침 상태는 필터와 따로 바꿀 수 있어요.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};버튼을 누르면 이 예제의 코드가 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.parkOnly(api)"
>박지호 담당만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.planned(api)"
>예정인 작업만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
<select
aria-label="펼침 상태"
[disabled]="!api"
(change)="api && actions.depth(api, $any($event.target).value)"
>
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<mx-grid style="height: 420px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// 프로젝트 계획표: 단계 아래에 작업이 달려 있어요(부모 키로 이은 트리).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: '작업',
width: 220,
filter: { placeholder: L('작업 이름…', 'Task name…') },
},
{ id: 'owner', title: '담당', kind: 'select', width: 110 },
{ id: 'status', title: '상태', kind: 'select', width: 110 },
{ id: 'hours', title: '공수(시간)', kind: 'number', width: 120, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: '기획', owner: '이서연', status: '완료', hours: 40 },
{ id: 2, parentId: 1, task: '사용자 인터뷰', owner: '이서연', status: '완료', hours: 24 },
{ id: 3, parentId: 1, task: '요구사항 정리', owner: '박지호', status: '완료', hours: 16 },
{ id: 4, parentId: null, task: '개발', owner: '김민준', status: '진행', hours: 160 },
{ id: 5, parentId: 4, task: '서버 API', owner: '김민준', status: '진행', hours: 80 },
{ id: 6, parentId: 4, task: '화면 구현', owner: '최유나', status: '진행', hours: 60 },
{ id: 7, parentId: 4, task: '리포트 기능', owner: '박지호', status: '예정', hours: 20 },
{ id: 8, parentId: null, task: '출시', owner: '최유나', status: '예정', hours: 30 },
{ id: 9, parentId: 8, task: '사용자 교육', owner: '최유나', status: '예정', hours: 18 },
{ id: 10, parentId: 8, task: '서비스 오픈', owner: '김민준', status: '예정', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// 트리에서 필터는 "조건에 맞는 행과 그 부모들"을 남겨요. 맞는 작업이 부모 없이 떠 있지 않게요.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () =>
log({
ko: `보이는 행 ${api.getVisibleRowCount()}개`,
en: `${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 박지호 담당 작업만: 부모(기획, 개발)는 함께 남아요.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: '박지호' }]),
// 예정인 작업만
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: '예정' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// 펼침 상태는 필터와 따로 바꿀 수 있어요.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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="parkOnly">Owner: Noah Kim</button>
<button type="button" id="planned">Planned only</button>
<button type="button" id="clear">Clear filter</button>
<select aria-label="Expansion" id="depth">
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<div id="grid" style="height: 420px"></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('parkOnly').addEventListener('click', () => actions.parkOnly(api));
document.getElementById('planned').addEventListener('click', () => actions.planned(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));// A project plan: tasks hang under phases (a tree linked by a parent key).
export const options = {
filterRow: true,
columns: [
{
id: 'task',
title: 'Task',
width: 220,
filter: { placeholder: 'Task name…' },
},
{ id: 'owner', title: 'Owner', kind: 'select', width: 130 },
{ id: 'status', title: 'Status', kind: 'select', width: 120 },
{ id: 'hours', title: 'Effort (hours)', kind: 'number', width: 140, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: 'Planning', owner: 'Emma Stone', status: 'Done', hours: 40 },
{ id: 2, parentId: 1, task: 'User interviews', owner: 'Emma Stone', status: 'Done', hours: 24 },
{ id: 3, parentId: 1, task: 'Requirements', owner: 'Noah Kim', status: 'Done', hours: 16 },
{
id: 4,
parentId: null,
task: 'Development',
owner: 'Liam Carter',
status: 'In progress',
hours: 160,
},
{
id: 5,
parentId: 4,
task: 'Server API',
owner: 'Liam Carter',
status: 'In progress',
hours: 80,
},
{
id: 6,
parentId: 4,
task: 'UI implementation',
owner: 'Olivia Park',
status: 'In progress',
hours: 60,
},
{ id: 7, parentId: 4, task: 'Reports', owner: 'Noah Kim', status: 'Planned', hours: 20 },
{ id: 8, parentId: null, task: 'Launch', owner: 'Olivia Park', status: 'Planned', hours: 30 },
{
id: 9,
parentId: 8,
task: 'User training',
owner: 'Olivia Park',
status: 'Planned',
hours: 18,
},
{ id: 10, parentId: 8, task: 'Go live', owner: 'Liam Carter', status: 'Planned', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// In a tree, a filter keeps "the matching rows and their parents", so a matching task never floats without its parent.
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api, log) {
const off = api.on('filterChanged', () => log(`${api.getVisibleRowCount()} rows visible`));
return () => off();
}
export const actions = {
// Only tasks owned by Noah Kim: the parents (Planning, Development) stay with them.
parkOnly: (api) => show(api, [{ columnId: 'owner', operator: 'equals', value: 'Noah Kim' }]),
// Only planned tasks
planned: (api) => show(api, [{ columnId: 'status', operator: 'equals', value: 'Planned' }]),
clear: (api) => api.setFilterModel(null),
// The expanded state can be changed separately from the filter.
depth: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Filtering a tree keeps the parents</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="parkOnly">Owner: Noah Kim</button>
<button type="button" id="planned">Planned only</button>
<button type="button" id="clear">Clear filter</button>
<select aria-label="Expansion" id="depth">
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// A project plan: tasks hang under phases (a tree linked by a parent key).
const options = {
filterRow: true,
columns: [
{
id: 'task',
title: 'Task',
width: 220,
filter: { placeholder: 'Task name…' },
},
{ id: 'owner', title: 'Owner', kind: 'select', width: 130 },
{ id: 'status', title: 'Status', kind: 'select', width: 120 },
{ id: 'hours', title: 'Effort (hours)', kind: 'number', width: 140, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: 'Planning', owner: 'Emma Stone', status: 'Done', hours: 40 },
{ id: 2, parentId: 1, task: 'User interviews', owner: 'Emma Stone', status: 'Done', hours: 24 },
{ id: 3, parentId: 1, task: 'Requirements', owner: 'Noah Kim', status: 'Done', hours: 16 },
{
id: 4,
parentId: null,
task: 'Development',
owner: 'Liam Carter',
status: 'In progress',
hours: 160,
},
{
id: 5,
parentId: 4,
task: 'Server API',
owner: 'Liam Carter',
status: 'In progress',
hours: 80,
},
{
id: 6,
parentId: 4,
task: 'UI implementation',
owner: 'Olivia Park',
status: 'In progress',
hours: 60,
},
{ id: 7, parentId: 4, task: 'Reports', owner: 'Noah Kim', status: 'Planned', hours: 20 },
{ id: 8, parentId: null, task: 'Launch', owner: 'Olivia Park', status: 'Planned', hours: 30 },
{
id: 9,
parentId: 8,
task: 'User training',
owner: 'Olivia Park',
status: 'Planned',
hours: 18,
},
{ id: 10, parentId: 8, task: 'Go live', owner: 'Liam Carter', status: 'Planned', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// In a tree, a filter keeps "the matching rows and their parents", so a matching task never floats without its parent.
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
function setup(api, log) {
const off = api.on('filterChanged', () => log(`${api.getVisibleRowCount()} rows visible`));
return () => off();
}
const actions = {
// Only tasks owned by Noah Kim: the parents (Planning, Development) stay with them.
parkOnly: (api) => show(api, [{ columnId: 'owner', operator: 'equals', value: 'Noah Kim' }]),
// Only planned tasks
planned: (api) => show(api, [{ columnId: 'status', operator: 'equals', value: 'Planned' }]),
clear: (api) => api.setFilterModel(null),
// The expanded state can be changed separately from the filter.
depth: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};
options.ariaLabel = "Filtering a tree keeps the parents";
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('parkOnly').addEventListener('click', () => actions.parkOnly(api));
document.getElementById('planned').addEventListener('click', () => actions.planned(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
</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.parkOnly(api)}
>Owner: Noah Kim</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.planned(api)}
>Planned only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
<select
aria-label="Expansion"
disabled={!api}
onChange={(event) => api && actions.depth(api, event.target.value)}
>
<option value="all">Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// A project plan: tasks hang under phases (a tree linked by a parent key).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: 'Task',
width: 220,
filter: { placeholder: 'Task name…' },
},
{ id: 'owner', title: 'Owner', kind: 'select', width: 130 },
{ id: 'status', title: 'Status', kind: 'select', width: 120 },
{ id: 'hours', title: 'Effort (hours)', kind: 'number', width: 140, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: 'Planning', owner: 'Emma Stone', status: 'Done', hours: 40 },
{ id: 2, parentId: 1, task: 'User interviews', owner: 'Emma Stone', status: 'Done', hours: 24 },
{ id: 3, parentId: 1, task: 'Requirements', owner: 'Noah Kim', status: 'Done', hours: 16 },
{
id: 4,
parentId: null,
task: 'Development',
owner: 'Liam Carter',
status: 'In progress',
hours: 160,
},
{
id: 5,
parentId: 4,
task: 'Server API',
owner: 'Liam Carter',
status: 'In progress',
hours: 80,
},
{
id: 6,
parentId: 4,
task: 'UI implementation',
owner: 'Olivia Park',
status: 'In progress',
hours: 60,
},
{ id: 7, parentId: 4, task: 'Reports', owner: 'Noah Kim', status: 'Planned', hours: 20 },
{ id: 8, parentId: null, task: 'Launch', owner: 'Olivia Park', status: 'Planned', hours: 30 },
{
id: 9,
parentId: 8,
task: 'User training',
owner: 'Olivia Park',
status: 'Planned',
hours: 18,
},
{ id: 10, parentId: 8, task: 'Go live', owner: 'Liam Carter', status: 'Planned', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// In a tree, a filter keeps "the matching rows and their parents", so a matching task never floats without its parent.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () => log(`${api.getVisibleRowCount()} rows visible`));
return () => off();
}
export const actions = {
// Only tasks owned by Noah Kim: the parents (Planning, Development) stay with them.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: 'Noah Kim' }]),
// Only planned tasks
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: 'Planned' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// The expanded state can be changed separately from the filter.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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.parkOnly(api)"
>Owner: Noah Kim</button>
<button type="button" :disabled="!api" @click="api && actions.planned(api)">Planned only</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
<select
aria-label="Expansion"
:disabled="!api"
@change="api && actions.depth(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// A project plan: tasks hang under phases (a tree linked by a parent key).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: 'Task',
width: 220,
filter: { placeholder: 'Task name…' },
},
{ id: 'owner', title: 'Owner', kind: 'select', width: 130 },
{ id: 'status', title: 'Status', kind: 'select', width: 120 },
{ id: 'hours', title: 'Effort (hours)', kind: 'number', width: 140, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: 'Planning', owner: 'Emma Stone', status: 'Done', hours: 40 },
{ id: 2, parentId: 1, task: 'User interviews', owner: 'Emma Stone', status: 'Done', hours: 24 },
{ id: 3, parentId: 1, task: 'Requirements', owner: 'Noah Kim', status: 'Done', hours: 16 },
{
id: 4,
parentId: null,
task: 'Development',
owner: 'Liam Carter',
status: 'In progress',
hours: 160,
},
{
id: 5,
parentId: 4,
task: 'Server API',
owner: 'Liam Carter',
status: 'In progress',
hours: 80,
},
{
id: 6,
parentId: 4,
task: 'UI implementation',
owner: 'Olivia Park',
status: 'In progress',
hours: 60,
},
{ id: 7, parentId: 4, task: 'Reports', owner: 'Noah Kim', status: 'Planned', hours: 20 },
{ id: 8, parentId: null, task: 'Launch', owner: 'Olivia Park', status: 'Planned', hours: 30 },
{
id: 9,
parentId: 8,
task: 'User training',
owner: 'Olivia Park',
status: 'Planned',
hours: 18,
},
{ id: 10, parentId: 8, task: 'Go live', owner: 'Liam Carter', status: 'Planned', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// In a tree, a filter keeps "the matching rows and their parents", so a matching task never floats without its parent.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () => log(`${api.getVisibleRowCount()} rows visible`));
return () => off();
}
export const actions = {
// Only tasks owned by Noah Kim: the parents (Planning, Development) stay with them.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: 'Noah Kim' }]),
// Only planned tasks
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: 'Planned' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// The expanded state can be changed separately from the filter.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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.parkOnly(api)"
>Owner: Noah Kim</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.planned(api)"
>Planned only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
<select
aria-label="Expansion"
[disabled]="!api"
(change)="api && actions.depth(api, $any($event.target).value)"
>
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<mx-grid style="height: 420px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
parentId: number | null;
task: string;
owner: string;
status: string;
hours: number;
}
// A project plan: tasks hang under phases (a tree linked by a parent key).
export const options: GridOptions<Row> = {
filterRow: true,
columns: [
{
id: 'task',
title: 'Task',
width: 220,
filter: { placeholder: 'Task name…' },
},
{ id: 'owner', title: 'Owner', kind: 'select', width: 130 },
{ id: 'status', title: 'Status', kind: 'select', width: 120 },
{ id: 'hours', title: 'Effort (hours)', kind: 'number', width: 140, align: 'end' },
],
rows: [
{ id: 1, parentId: null, task: 'Planning', owner: 'Emma Stone', status: 'Done', hours: 40 },
{ id: 2, parentId: 1, task: 'User interviews', owner: 'Emma Stone', status: 'Done', hours: 24 },
{ id: 3, parentId: 1, task: 'Requirements', owner: 'Noah Kim', status: 'Done', hours: 16 },
{
id: 4,
parentId: null,
task: 'Development',
owner: 'Liam Carter',
status: 'In progress',
hours: 160,
},
{
id: 5,
parentId: 4,
task: 'Server API',
owner: 'Liam Carter',
status: 'In progress',
hours: 80,
},
{
id: 6,
parentId: 4,
task: 'UI implementation',
owner: 'Olivia Park',
status: 'In progress',
hours: 60,
},
{ id: 7, parentId: 4, task: 'Reports', owner: 'Noah Kim', status: 'Planned', hours: 20 },
{ id: 8, parentId: null, task: 'Launch', owner: 'Olivia Park', status: 'Planned', hours: 30 },
{
id: 9,
parentId: 8,
task: 'User training',
owner: 'Olivia Park',
status: 'Planned',
hours: 18,
},
{ id: 10, parentId: 8, task: 'Go live', owner: 'Liam Carter', status: 'Planned', hours: 12 },
],
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
// In a tree, a filter keeps "the matching rows and their parents", so a matching task never floats without its parent.
const show = (api: GridApi<Row>, items: FilterItem[]): void =>
api.setFilterModel(items.length ? { match: 'all', items } : null);
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', () => log(`${api.getVisibleRowCount()} rows visible`));
return () => off();
}
export const actions = {
// Only tasks owned by Noah Kim: the parents (Planning, Development) stay with them.
parkOnly: (api: GridApi<Row>) =>
show(api, [{ columnId: 'owner', operator: 'equals', value: 'Noah Kim' }]),
// Only planned tasks
planned: (api: GridApi<Row>) =>
show(api, [{ columnId: 'status', operator: 'equals', value: 'Planned' }]),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
// The expanded state can be changed separately from the filter.
depth: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};