평평한 배열을 트리로 보여 주기Show a flat array as a tree
줄마다 부모의 id만 적어 두면 그리드가 알아서 트리로 만들어요. 배열 순서가 섞여 있어도, 자식이 부모보다 앞에 있어도 괜찮아요.Each row only names its parent id and the grid builds the tree. The array order does not matter, even with children before their 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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="showFlat">배열 모양 보기</button>
<button type="button" id="shuffle">순서 섞기</button>
<button type="button" id="reverse">거꾸로</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 430px"></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('showFlat').addEventListener('click', () => actions.showFlat(api));
document.getElementById('shuffle').addEventListener('click', () => actions.shuffle(api));
document.getElementById('reverse').addEventListener('click', () => actions.reverse(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));// 평평한 배열이에요. 일부러 자식이 부모보다 앞에 나오게 섞어 놓았어요.
// 각 줄이 부모의 id(parentId)만 알고 있으면 그리드가 트리로 만들어 줘요. 누가 누구의 자식인지는 줄 순서와 상관없고, 같은 부모 아래 형제의 순서만 배열 순서를 따라요.
const flat = [
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({
ko: '배열은 섞인 순서 그대로예요. "배열 모양 보기"를 눌러 확인해 보세요.',
en: 'The array stays in its mixed order. Press "Show array shape" to check.',
});
}
const shuffle = (rows) => rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say({
ko: `배열의 앞 4줄 (parentId로 부모를 가리켜요)\n${JSON.stringify(first, null, 2)}`,
en: `First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
});
},
reverse: (api) => {
api.setRows([...api.getRows()].reverse());
say({
ko: '배열을 거꾸로 뒤집어 다시 넣었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
});
},
shuffle: (api) => {
api.setRows(shuffle(api.getRows()));
say({
ko: '배열 순서를 다시 섞었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
});
},
reset: (api) => api.setRows(original),
};<!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="showFlat">배열 모양 보기</button>
<button type="button" id="shuffle">순서 섞기</button>
<button type="button" id="reverse">거꾸로</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 430px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 평평한 배열이에요. 일부러 자식이 부모보다 앞에 나오게 섞어 놓았어요.
// 각 줄이 부모의 id(parentId)만 알고 있으면 그리드가 트리로 만들어 줘요. 누가 누구의 자식인지는 줄 순서와 상관없고, 같은 부모 아래 형제의 순서만 배열 순서를 따라요.
const flat = [
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
const options = {
columns: [
{ id: 'task', title: '작업', width: 220 },
{ id: 'owner', title: '담당자', width: 100 },
{ id: 'start', title: '시작', width: 110 },
{ id: 'end', title: '종료', width: 110 },
],
rows: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
function setup(_api, log) {
say = log;
log({
ko: '배열은 섞인 순서 그대로예요. "배열 모양 보기"를 눌러 확인해 보세요.',
en: 'The array stays in its mixed order. Press "Show array shape" to check.',
});
}
const shuffle = (rows) => rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
const actions = {
showFlat: (api) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say({
ko: `배열의 앞 4줄 (parentId로 부모를 가리켜요)\n${JSON.stringify(first, null, 2)}`,
en: `First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
});
},
reverse: (api) => {
api.setRows([...api.getRows()].reverse());
say({
ko: '배열을 거꾸로 뒤집어 다시 넣었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
});
},
shuffle: (api) => {
api.setRows(shuffle(api.getRows()));
say({
ko: '배열 순서를 다시 섞었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
});
},
reset: (api) => api.setRows(original),
};
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('showFlat').addEventListener('click', () => actions.showFlat(api));
document.getElementById('shuffle').addEventListener('click', () => actions.shuffle(api));
document.getElementById('reverse').addEventListener('click', () => actions.reverse(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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.showFlat(api)}
>배열 모양 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shuffle(api)}
>순서 섞기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reverse(api)}
>거꾸로</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>처음으로</button>
</div>
<Grid style={{ height: 430 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// 평평한 배열이에요. 일부러 자식이 부모보다 앞에 나오게 섞어 놓았어요.
// 각 줄이 부모의 id(parentId)만 알고 있으면 그리드가 트리로 만들어 줘요. 누가 누구의 자식인지는 줄 순서와 상관없고, 같은 부모 아래 형제의 순서만 배열 순서를 따라요.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '배열은 섞인 순서 그대로예요. "배열 모양 보기"를 눌러 확인해 보세요.',
en: 'The array stays in its mixed order. Press "Show array shape" to check.',
});
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say({
ko: `배열의 앞 4줄 (parentId로 부모를 가리켜요)\n${JSON.stringify(first, null, 2)}`,
en: `First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
});
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say({
ko: '배열을 거꾸로 뒤집어 다시 넣었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
});
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say({
ko: '배열 순서를 다시 섞었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
});
},
reset: (api: GridApi<Row>) => api.setRows(original),
};버튼을 누르면 이 예제의 코드가 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.showFlat(api)"
>배열 모양 보기</button>
<button type="button" :disabled="!api" @click="api && actions.shuffle(api)">순서 섞기</button>
<button type="button" :disabled="!api" @click="api && actions.reverse(api)">거꾸로</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">처음으로</button>
</div>
<Grid style="height: 430px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// 평평한 배열이에요. 일부러 자식이 부모보다 앞에 나오게 섞어 놓았어요.
// 각 줄이 부모의 id(parentId)만 알고 있으면 그리드가 트리로 만들어 줘요. 누가 누구의 자식인지는 줄 순서와 상관없고, 같은 부모 아래 형제의 순서만 배열 순서를 따라요.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '배열은 섞인 순서 그대로예요. "배열 모양 보기"를 눌러 확인해 보세요.',
en: 'The array stays in its mixed order. Press "Show array shape" to check.',
});
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say({
ko: `배열의 앞 4줄 (parentId로 부모를 가리켜요)\n${JSON.stringify(first, null, 2)}`,
en: `First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
});
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say({
ko: '배열을 거꾸로 뒤집어 다시 넣었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
});
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say({
ko: '배열 순서를 다시 섞었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
});
},
reset: (api: GridApi<Row>) => api.setRows(original),
};버튼을 누르면 이 예제의 코드가 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.showFlat(api)"
>배열 모양 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shuffle(api)"
>순서 섞기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reverse(api)"
>거꾸로</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>처음으로</button>
</div>
<mx-grid style="height: 430px" [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: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// 평평한 배열이에요. 일부러 자식이 부모보다 앞에 나오게 섞어 놓았어요.
// 각 줄이 부모의 id(parentId)만 알고 있으면 그리드가 트리로 만들어 줘요. 누가 누구의 자식인지는 줄 순서와 상관없고, 같은 부모 아래 형제의 순서만 배열 순서를 따라요.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '배열은 섞인 순서 그대로예요. "배열 모양 보기"를 눌러 확인해 보세요.',
en: 'The array stays in its mixed order. Press "Show array shape" to check.',
});
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say({
ko: `배열의 앞 4줄 (parentId로 부모를 가리켜요)\n${JSON.stringify(first, null, 2)}`,
en: `First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
});
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say({
ko: '배열을 거꾸로 뒤집어 다시 넣었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
});
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say({
ko: '배열 순서를 다시 섞었어요. 부모·자식 관계는 그대로고 형제 순서만 바뀌었어요.',
en: 'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
});
},
reset: (api: GridApi<Row>) => api.setRows(original),
};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="showFlat">Show array</button>
<button type="button" id="shuffle">Shuffle</button>
<button type="button" id="reverse">Reverse</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 430px"></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('showFlat').addEventListener('click', () => actions.showFlat(api));
document.getElementById('shuffle').addEventListener('click', () => actions.shuffle(api));
document.getElementById('reverse').addEventListener('click', () => actions.reverse(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));// A flat array. The children deliberately come before their parents.
// If each row only knows its parent's id (parentId), the grid builds the tree. Who is whose child does not depend on row order; only the order of siblings under one parent follows the array order.
const flat = [
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
say = log;
log('The array stays in its mixed order. Press "Show array" to check.');
}
const shuffle = (rows) => rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say(`First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`);
},
reverse: (api) => {
api.setRows([...api.getRows()].reverse());
say('Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.');
},
shuffle: (api) => {
api.setRows(shuffle(api.getRows()));
say('Shuffled the array again. Parent-child links stay the same; only the sibling order changed.');
},
reset: (api) => api.setRows(original),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Show a flat array as a tree</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="showFlat">Show array</button>
<button type="button" id="shuffle">Shuffle</button>
<button type="button" id="reverse">Reverse</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 430px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// A flat array. The children deliberately come before their parents.
// If each row only knows its parent's id (parentId), the grid builds the tree. Who is whose child does not depend on row order; only the order of siblings under one parent follows the array order.
const flat = [
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
function setup(_api, log) {
say = log;
log('The array stays in its mixed order. Press "Show array" to check.');
}
const shuffle = (rows) => rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
const actions = {
showFlat: (api) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say(`First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`);
},
reverse: (api) => {
api.setRows([...api.getRows()].reverse());
say('Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.');
},
shuffle: (api) => {
api.setRows(shuffle(api.getRows()));
say('Shuffled the array again. Parent-child links stay the same; only the sibling order changed.');
},
reset: (api) => api.setRows(original),
};
options.ariaLabel = "Show a flat array as a tree";
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('showFlat').addEventListener('click', () => actions.showFlat(api));
document.getElementById('shuffle').addEventListener('click', () => actions.shuffle(api));
document.getElementById('reverse').addEventListener('click', () => actions.reverse(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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.showFlat(api)}
>Show array</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shuffle(api)}
>Shuffle</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reverse(api)}
>Reverse</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>Reset</button>
</div>
<Grid style={{ height: 430 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// A flat array. The children deliberately come before their parents.
// If each row only knows its parent's id (parentId), the grid builds the tree. Who is whose child does not depend on row order; only the order of siblings under one parent follows the array order.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('The array stays in its mixed order. Press "Show array" to check.');
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say(
`First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
);
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say(
'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
);
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say(
'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
);
},
reset: (api: GridApi<Row>) => api.setRows(original),
};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.showFlat(api)"
>Show array</button>
<button type="button" :disabled="!api" @click="api && actions.shuffle(api)">Shuffle</button>
<button type="button" :disabled="!api" @click="api && actions.reverse(api)">Reverse</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">Reset</button>
</div>
<Grid style="height: 430px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// A flat array. The children deliberately come before their parents.
// If each row only knows its parent's id (parentId), the grid builds the tree. Who is whose child does not depend on row order; only the order of siblings under one parent follows the array order.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('The array stays in its mixed order. Press "Show array" to check.');
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say(
`First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
);
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say(
'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
);
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say(
'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
);
},
reset: (api: GridApi<Row>) => api.setRows(original),
};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.showFlat(api)"
>Show array</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shuffle(api)"
>Shuffle</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reverse(api)"
>Reverse</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>Reset</button>
</div>
<mx-grid style="height: 430px" [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: string;
parentId: string | null;
task: string;
owner: string;
start: string;
end: string;
}
// A flat array. The children deliberately come before their parents.
// If each row only knows its parent's id (parentId), the grid builds the tree. Who is whose child does not depend on row order; only the order of siblings under one parent follows the array order.
const flat: Row[] = [
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
];
const original = [...flat];
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: flat,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('The array stays in its mixed order. Press "Show array" to check.');
}
const shuffle = (rows: readonly Row[]): Row[] =>
rows
.map((row, i) => ({ row, sort: (i * 7 + 3) % rows.length }))
.sort((a, b) => a.sort - b.sort)
.map((x) => x.row);
export const actions = {
showFlat: (api: GridApi<Row>) => {
const first = api
.getRows()
.slice(0, 4)
.map(({ id, parentId, task }) => ({ id, parentId, task }));
say(
`First 4 rows of the array (parentId points to the parent)\n${JSON.stringify(first, null, 2)}`,
);
},
reverse: (api: GridApi<Row>) => {
api.setRows([...api.getRows()].reverse());
say(
'Reversed the array and loaded it again. Parent-child links stay the same; only the sibling order changed.',
);
},
shuffle: (api: GridApi<Row>) => {
api.setRows(shuffle(api.getRows()));
say(
'Shuffled the array again. Parent-child links stay the same; only the sibling order changed.',
);
},
reset: (api: GridApi<Row>) => api.setRows(original),
};