작업을 단계별로 펼쳐 보는 일정표A project schedule you can open level by level
겹쳐 있는 데이터(하위 항목이 안에 든 JSON)를 한 번 펴서 넣으면 단계가 있는 표가 돼요. 화살표로 가지를 열고 닫고, 보이는 단계도 한 번에 고를 수 있어요.Flatten nested JSON (children) once and pass it in to get a table with levels. Open and close branches with the arrow, or pick how many levels to show at once.
코드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">
<select aria-label="보이는 단계" id="depth">
<option value="1">1단계만</option>
<option value="2">2단계까지</option>
<option value="3" selected>3단계까지</option>
<option value="all">모두 (4단계)</option>
</select>
<button type="button" id="expandAll">모두 열기</button>
<button type="button" id="collapseAll">모두 닫기</button>
<button type="button" id="toggleDev">"개발" 가지만 열고 닫기</button>
</div>
<div id="grid" style="height: 490px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('toggleDev').addEventListener('click', () => actions.toggleDev(api));// 서버가 이렇게 children으로 겹쳐 놓은 JSON을 준다고 해 봐요.
const nested = [
{
id: 'T1',
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{ id: 'T12', task: '화면 설계', owner: '박민지', start: '2026-11-09', end: '2026-11-13' },
],
},
{
id: 'T20',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// 그리드에는 "부모 키를 가진 평평한 배열"을 넣어요. 겹친 JSON은 이 함수로 한 번 펴 주면 돼요.
function flatten(nodes, parentId = null) {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey가 부모를 가리키는 컬럼이에요. column은 펼침 화살표를 붙일 컬럼이고, expandDepth: 2는 위에서 두 단계를 열어 세 단계까지 보여 줘요.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api, value) => {
if (value === 'all')
api.expandAll();
else
api.expandToDepth(Number(value ?? 3) - 1); // n단계까지 보이려면 위에서 n-1 단계를 열어요.
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
// 특정 가지(개발, T20) 하나만 열고 닫아요.
toggleDev: (api) => api.toggleRow('T20'),
};<!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">
<select aria-label="보이는 단계" id="depth">
<option value="1">1단계만</option>
<option value="2">2단계까지</option>
<option value="3" selected>3단계까지</option>
<option value="all">모두 (4단계)</option>
</select>
<button type="button" id="expandAll">모두 열기</button>
<button type="button" id="collapseAll">모두 닫기</button>
<button type="button" id="toggleDev">"개발" 가지만 열고 닫기</button>
</div>
<div id="grid" style="height: 490px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 서버가 이렇게 children으로 겹쳐 놓은 JSON을 준다고 해 봐요.
const nested = [
{
id: 'T1',
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{ id: 'T12', task: '화면 설계', owner: '박민지', start: '2026-11-09', end: '2026-11-13' },
],
},
{
id: 'T20',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// 그리드에는 "부모 키를 가진 평평한 배열"을 넣어요. 겹친 JSON은 이 함수로 한 번 펴 주면 돼요.
function flatten(nodes, parentId = null) {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
const options = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey가 부모를 가리키는 컬럼이에요. column은 펼침 화살표를 붙일 컬럼이고, expandDepth: 2는 위에서 두 단계를 열어 세 단계까지 보여 줘요.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
const actions = {
depth: (api, value) => {
if (value === 'all')
api.expandAll();
else
api.expandToDepth(Number(value ?? 3) - 1); // n단계까지 보이려면 위에서 n-1 단계를 열어요.
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
// 특정 가지(개발, T20) 하나만 열고 닫아요.
toggleDev: (api) => api.toggleRow('T20'),
};
options.ariaLabel = "작업을 단계별로 펼쳐 보는 일정표";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('toggleDev').addEventListener('click', () => actions.toggleDev(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="보이는 단계"
disabled={!api}
onChange={(event) => api && actions.depth(api, event.target.value)}
>
<option value="1">1단계만</option>
<option value="2">2단계까지</option>
<option value="3">3단계까지</option>
<option value="all">모두 (4단계)</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>모두 열기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>모두 닫기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.toggleDev(api)}
>"개발" 가지만 열고 닫기</button>
</div>
<Grid style={{ height: 490 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// 서버가 이렇게 children으로 겹쳐 놓은 JSON을 준다고 해 봐요.
const nested: Node[] = [
{
id: 'T1',
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{ id: 'T12', task: '화면 설계', owner: '박민지', start: '2026-11-09', end: '2026-11-13' },
],
},
{
id: 'T20',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// 그리드에는 "부모 키를 가진 평평한 배열"을 넣어요. 겹친 JSON은 이 함수로 한 번 펴 주면 돼요.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey가 부모를 가리키는 컬럼이에요. column은 펼침 화살표를 붙일 컬럼이고, expandDepth: 2는 위에서 두 단계를 열어 세 단계까지 보여 줘요.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // n단계까지 보이려면 위에서 n-1 단계를 열어요.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// 특정 가지(개발, T20) 하나만 열고 닫아요.
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="보이는 단계"
:disabled="!api"
@change="api && actions.depth(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1">1단계만</option>
<option value="2">2단계까지</option>
<option value="3" selected>3단계까지</option>
<option value="all">모두 (4단계)</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>모두 열기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>모두 닫기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.toggleDev(api)"
>"개발" 가지만 열고 닫기</button>
</div>
<Grid style="height: 490px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// 서버가 이렇게 children으로 겹쳐 놓은 JSON을 준다고 해 봐요.
const nested: Node[] = [
{
id: 'T1',
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{ id: 'T12', task: '화면 설계', owner: '박민지', start: '2026-11-09', end: '2026-11-13' },
],
},
{
id: 'T20',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// 그리드에는 "부모 키를 가진 평평한 배열"을 넣어요. 겹친 JSON은 이 함수로 한 번 펴 주면 돼요.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey가 부모를 가리키는 컬럼이에요. column은 펼침 화살표를 붙일 컬럼이고, expandDepth: 2는 위에서 두 단계를 열어 세 단계까지 보여 줘요.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // n단계까지 보이려면 위에서 n-1 단계를 열어요.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// 특정 가지(개발, T20) 하나만 열고 닫아요.
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="보이는 단계"
[disabled]="!api"
(change)="api && actions.depth(api, $any($event.target).value)"
>
<option value="1">1단계만</option>
<option value="2">2단계까지</option>
<option value="3" selected>3단계까지</option>
<option value="all">모두 (4단계)</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>모두 열기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>모두 닫기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.toggleDev(api)"
>"개발" 가지만 열고 닫기</button>
</div>
<mx-grid style="height: 490px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// 서버가 이렇게 children으로 겹쳐 놓은 JSON을 준다고 해 봐요.
const nested: Node[] = [
{
id: 'T1',
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{ id: 'T12', task: '화면 설계', owner: '박민지', start: '2026-11-09', end: '2026-11-13' },
],
},
{
id: 'T20',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// 그리드에는 "부모 키를 가진 평평한 배열"을 넣어요. 겹친 JSON은 이 함수로 한 번 펴 주면 돼요.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey가 부모를 가리키는 컬럼이에요. column은 펼침 화살표를 붙일 컬럼이고, expandDepth: 2는 위에서 두 단계를 열어 세 단계까지 보여 줘요.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // n단계까지 보이려면 위에서 n-1 단계를 열어요.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// 특정 가지(개발, T20) 하나만 열고 닫아요.
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Levels shown" id="depth">
<option value="1">Level 1 only</option>
<option value="2">Up to level 2</option>
<option value="3" selected>Up to level 3</option>
<option value="all">All (4 levels)</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
<button type="button" id="toggleDev">Toggle the "Development" branch</button>
</div>
<div id="grid" style="height: 490px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('toggleDev').addEventListener('click', () => actions.toggleDev(api));// Imagine the server gives us JSON nested with children like this.
const nested = [
{
id: 'T1',
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
],
},
{
id: 'T20',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// The grid takes a flat array whose rows carry a parent key. Flatten the nested JSON once with this function.
function flatten(nodes, parentId = null) {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options = {
columns: [
{ id: 'task', title: 'Task', width: 220 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'start', title: 'Start', width: 110 },
{ id: 'end', title: 'End', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey is the column that points to the parent. column is where the expand arrow goes, and expandDepth: 2 opens the top two levels so three levels show.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api, value) => {
if (value === 'all')
api.expandAll();
else
api.expandToDepth(Number(value ?? 3) - 1); // To show n levels, open the top n-1 levels.
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
// Open or close just one branch (Development, T20).
toggleDev: (api) => api.toggleRow('T20'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A project schedule you can open level by level</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Levels shown" id="depth">
<option value="1">Level 1 only</option>
<option value="2">Up to level 2</option>
<option value="3" selected>Up to level 3</option>
<option value="all">All (4 levels)</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
<button type="button" id="toggleDev">Toggle the "Development" branch</button>
</div>
<div id="grid" style="height: 490px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// Imagine the server gives us JSON nested with children like this.
const nested = [
{
id: 'T1',
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
],
},
{
id: 'T20',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// The grid takes a flat array whose rows carry a parent key. Flatten the nested JSON once with this function.
function flatten(nodes, parentId = null) {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
const options = {
columns: [
{ id: 'task', title: 'Task', width: 220 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'start', title: 'Start', width: 110 },
{ id: 'end', title: 'End', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey is the column that points to the parent. column is where the expand arrow goes, and expandDepth: 2 opens the top two levels so three levels show.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
const actions = {
depth: (api, value) => {
if (value === 'all')
api.expandAll();
else
api.expandToDepth(Number(value ?? 3) - 1); // To show n levels, open the top n-1 levels.
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
// Open or close just one branch (Development, T20).
toggleDev: (api) => api.toggleRow('T20'),
};
options.ariaLabel = "A project schedule you can open level by level";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('depth').addEventListener('change', (event) => actions.depth(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('toggleDev').addEventListener('click', () => actions.toggleDev(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Levels shown"
disabled={!api}
onChange={(event) => api && actions.depth(api, event.target.value)}
>
<option value="1">Level 1 only</option>
<option value="2">Up to level 2</option>
<option value="3">Up to level 3</option>
<option value="all">All (4 levels)</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>Expand all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>Collapse all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.toggleDev(api)}
>Toggle the "Development" branch</button>
</div>
<Grid style={{ height: 490 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// Imagine the server gives us JSON nested with children like this.
const nested: Node[] = [
{
id: 'T1',
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
],
},
{
id: 'T20',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// The grid takes a flat array whose rows carry a parent key. Flatten the nested JSON once with this function.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 220 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'start', title: 'Start', width: 110 },
{ id: 'end', title: 'End', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey is the column that points to the parent. column is where the expand arrow goes, and expandDepth: 2 opens the top two levels so three levels show.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // To show n levels, open the top n-1 levels.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// Open or close just one branch (Development, T20).
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Levels shown"
:disabled="!api"
@change="api && actions.depth(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1">Level 1 only</option>
<option value="2">Up to level 2</option>
<option value="3" selected>Up to level 3</option>
<option value="all">All (4 levels)</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>Collapse all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.toggleDev(api)"
>Toggle the "Development" branch</button>
</div>
<Grid style="height: 490px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// Imagine the server gives us JSON nested with children like this.
const nested: Node[] = [
{
id: 'T1',
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
],
},
{
id: 'T20',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// The grid takes a flat array whose rows carry a parent key. Flatten the nested JSON once with this function.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 220 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'start', title: 'Start', width: 110 },
{ id: 'end', title: 'End', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey is the column that points to the parent. column is where the expand arrow goes, and expandDepth: 2 opens the top two levels so three levels show.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // To show n levels, open the top n-1 levels.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// Open or close just one branch (Development, T20).
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Levels shown"
[disabled]="!api"
(change)="api && actions.depth(api, $any($event.target).value)"
>
<option value="1">Level 1 only</option>
<option value="2">Up to level 2</option>
<option value="3" selected>Up to level 3</option>
<option value="all">All (4 levels)</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>Collapse all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.toggleDev(api)"
>Toggle the "Development" branch</button>
</div>
<mx-grid style="height: 490px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
interface Node {
id: string;
task: string;
owner: string;
start: string;
end: string;
children?: Node[];
}
// Imagine the server gives us JSON nested with children like this.
const nested: Node[] = [
{
id: 'T1',
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
children: [
{
id: 'T10',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
children: [
{
id: 'T11',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
],
},
{
id: 'T20',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T21',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
children: [
{
id: 'T211',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
],
},
{
id: 'T22',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
children: [
{
id: 'T221',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
],
},
],
},
{
id: 'T30',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
children: [
{
id: 'T31',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
{
id: 'T2',
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
children: [
{
id: 'T40',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
children: [
{
id: 'T411',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
],
},
],
},
];
// The grid takes a flat array whose rows carry a parent key. Flatten the nested JSON once with this function.
function flatten(nodes: Node[], parentId: string | null = null): Row[] {
return nodes.flatMap(({ children, ...node }) => [
{ ...node, parentId },
...flatten(children ?? [], node.id),
]);
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 220 },
{ id: 'owner', title: 'Owner', width: 120 },
{ id: 'start', title: 'Start', width: 110 },
{ id: 'end', title: 'End', width: 110 },
],
rows: flatten(nested),
rowKey: 'id',
// parentKey is the column that points to the parent. column is where the expand arrow goes, and expandDepth: 2 opens the top two levels so three levels show.
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
export const actions = {
depth: (api: GridApi<Row>, value?: string) => {
if (value === 'all') api.expandAll();
else api.expandToDepth(Number(value ?? 3) - 1); // To show n levels, open the top n-1 levels.
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
// Open or close just one branch (Development, T20).
toggleDev: (api: GridApi<Row>) => api.toggleRow('T20'),
};