본문으로 건너뛰기Skip to content
예제 첫화면Examples home

트리 표에서 걸러도 부모는 남아요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.

활용Intermediate
직접 써 보기Live preview트리 표에서 걸러도 부모는 남아요Filtering a tree keeps the parents

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
// 예제 틀이 알려 주는 페이지 언어(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(),
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
// 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(),
};