선택한 줄의 부모·자식·조상·자손 찾기Find the parent, children, ancestors and descendants
줄을 하나 골라 두고 버튼을 누르면 그 줄의 부모, 자식, 조상, 자손을 찾아서 펼쳐 보여 주고 선택해 줘요. 평평한 목록이라 "어느 줄의 하위인지" 값만 따라가면 돼요.Pick a row and press a button to find its parent, children, ancestors or descendants; they are revealed and selected. With a flat array you just follow parentId.
코드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="parent">부모 찾기</button>
<button type="button" id="children">자식 찾기</button>
<button type="button" id="ancestors">조상 찾기</button>
<button type="button" id="descendants">자손 찾기</button>
<button type="button" id="self">내 줄만 선택</button>
</div>
<div id="grid" style="height: 490px"></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('parent').addEventListener('click', () => actions.parent(api));
document.getElementById('children').addEventListener('click', () => actions.children(api));
document.getElementById('ancestors').addEventListener('click', () => actions.ancestors(api));
document.getElementById('descendants').addEventListener('click', () => actions.descendants(api));
document.getElementById('self').addEventListener('click', () => actions.self(api));const rows = [
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
];
// 평평한 배열이라서 가족 관계는 parentId만 따라가면 바로 구해져요.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id) => rows.filter((row) => row.parentId === id);
const parentOf = (id) => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId)] : [];
};
const ancestorsOf = (id) => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id) => childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // 기준이 되는 줄(마지막으로 직접 고른 줄)
let busy = false;
let say = () => { };
export function setup(api, log) {
say = log;
api.setSelectedKeys([base]);
log({
ko: '"백엔드"를 골라 두었어요. 다른 줄을 눌러 기준을 바꿀 수 있어요.',
en: '"백엔드" is selected. Click another row to change the reference.',
});
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined)
base = String(last);
});
}
// 찾은 줄들을 펼쳐서 보이게 하고 선택해 줘요(숨어 있던 안쪽 줄도 조상을 열어서 보여 줘요).
function show(api, label, found) {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say({ ko: `"${name}"의 ${label[0]}: 없어요.`, en: `No ${label[1]} for "${name}".` });
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say({
ko: `"${name}"의 ${label[0]} ${found.length}개: ${found.map((row) => row.task).join(', ')}`,
en: `${found.length} ${label[1]} of "${name}": ${found.map((row) => row.task).join(', ')}`,
});
}
export const actions = {
parent: (api) => show(api, ['부모', 'parent'], parentOf(base)),
children: (api) => show(api, ['자식', 'children'], childrenOf(base)),
ancestors: (api) => show(api, ['조상', 'ancestors'], ancestorsOf(base)),
descendants: (api) => show(api, ['자손', 'descendants'], descendantsOf(base)),
self: (api) => api.setSelectedKeys([base]),
};<!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="parent">부모 찾기</button>
<button type="button" id="children">자식 찾기</button>
<button type="button" id="ancestors">조상 찾기</button>
<button type="button" id="descendants">자손 찾기</button>
<button type="button" id="self">내 줄만 선택</button>
</div>
<div id="grid" style="height: 490px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
];
// 평평한 배열이라서 가족 관계는 parentId만 따라가면 바로 구해져요.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id) => rows.filter((row) => row.parentId === id);
const parentOf = (id) => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId)] : [];
};
const ancestorsOf = (id) => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id) => childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // 기준이 되는 줄(마지막으로 직접 고른 줄)
let busy = false;
let say = () => { };
function setup(api, log) {
say = log;
api.setSelectedKeys([base]);
log({
ko: '"백엔드"를 골라 두었어요. 다른 줄을 눌러 기준을 바꿀 수 있어요.',
en: '"백엔드" is selected. Click another row to change the reference.',
});
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined)
base = String(last);
});
}
// 찾은 줄들을 펼쳐서 보이게 하고 선택해 줘요(숨어 있던 안쪽 줄도 조상을 열어서 보여 줘요).
function show(api, label, found) {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say({ ko: `"${name}"의 ${label[0]}: 없어요.`, en: `No ${label[1]} for "${name}".` });
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say({
ko: `"${name}"의 ${label[0]} ${found.length}개: ${found.map((row) => row.task).join(', ')}`,
en: `${found.length} ${label[1]} of "${name}": ${found.map((row) => row.task).join(', ')}`,
});
}
const actions = {
parent: (api) => show(api, ['부모', 'parent'], parentOf(base)),
children: (api) => show(api, ['자식', 'children'], childrenOf(base)),
ancestors: (api) => show(api, ['조상', 'ancestors'], ancestorsOf(base)),
descendants: (api) => show(api, ['자손', 'descendants'], descendantsOf(base)),
self: (api) => api.setSelectedKeys([base]),
};
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('parent').addEventListener('click', () => actions.parent(api));
document.getElementById('children').addEventListener('click', () => actions.children(api));
document.getElementById('ancestors').addEventListener('click', () => actions.ancestors(api));
document.getElementById('descendants').addEventListener('click', () => actions.descendants(api));
document.getElementById('self').addEventListener('click', () => actions.self(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.parent(api)}
>부모 찾기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.children(api)}
>자식 찾기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ancestors(api)}
>조상 찾기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.descendants(api)}
>자손 찾기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.self(api)}
>내 줄만 선택</button>
</div>
<Grid style={{ height: 490 }} 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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
];
// 평평한 배열이라서 가족 관계는 parentId만 따라가면 바로 구해져요.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // 기준이 되는 줄(마지막으로 직접 고른 줄)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log({
ko: '"백엔드"를 골라 두었어요. 다른 줄을 눌러 기준을 바꿀 수 있어요.',
en: '"백엔드" is selected. Click another row to change the reference.',
});
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// 찾은 줄들을 펼쳐서 보이게 하고 선택해 줘요(숨어 있던 안쪽 줄도 조상을 열어서 보여 줘요).
function show(api: GridApi<Row>, label: [string, string], found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say({ ko: `"${name}"의 ${label[0]}: 없어요.`, en: `No ${label[1]} for "${name}".` });
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say({
ko: `"${name}"의 ${label[0]} ${found.length}개: ${found.map((row) => row.task).join(', ')}`,
en: `${found.length} ${label[1]} of "${name}": ${found.map((row) => row.task).join(', ')}`,
});
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, ['부모', 'parent'], parentOf(base)),
children: (api: GridApi<Row>) => show(api, ['자식', 'children'], childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, ['조상', 'ancestors'], ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, ['자손', 'descendants'], descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};버튼을 누르면 이 예제의 코드가 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.parent(api)">부모 찾기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.children(api)"
>자식 찾기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ancestors(api)"
>조상 찾기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.descendants(api)"
>자손 찾기</button>
<button type="button" :disabled="!api" @click="api && actions.self(api)">내 줄만 선택</button>
</div>
<Grid style="height: 490px" :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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
];
// 평평한 배열이라서 가족 관계는 parentId만 따라가면 바로 구해져요.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // 기준이 되는 줄(마지막으로 직접 고른 줄)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log({
ko: '"백엔드"를 골라 두었어요. 다른 줄을 눌러 기준을 바꿀 수 있어요.',
en: '"백엔드" is selected. Click another row to change the reference.',
});
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// 찾은 줄들을 펼쳐서 보이게 하고 선택해 줘요(숨어 있던 안쪽 줄도 조상을 열어서 보여 줘요).
function show(api: GridApi<Row>, label: [string, string], found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say({ ko: `"${name}"의 ${label[0]}: 없어요.`, en: `No ${label[1]} for "${name}".` });
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say({
ko: `"${name}"의 ${label[0]} ${found.length}개: ${found.map((row) => row.task).join(', ')}`,
en: `${found.length} ${label[1]} of "${name}": ${found.map((row) => row.task).join(', ')}`,
});
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, ['부모', 'parent'], parentOf(base)),
children: (api: GridApi<Row>) => show(api, ['자식', 'children'], childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, ['조상', 'ancestors'], ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, ['자손', 'descendants'], descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};버튼을 누르면 이 예제의 코드가 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.parent(api)"
>부모 찾기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.children(api)"
>자식 찾기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ancestors(api)"
>조상 찾기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.descendants(api)"
>자손 찾기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.self(api)"
>내 줄만 선택</button>
</div>
<mx-grid style="height: 490px" [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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: '출시 준비',
owner: '김서연',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: '기획',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: '요구사항 정리',
owner: '이준호',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: '화면 설계',
owner: '박민지',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: '개발',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: '프런트엔드',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: '로그인 화면',
owner: '정하은',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: '목록 화면',
owner: '강지후',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: '백엔드',
owner: '최도윤',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API 설계',
owner: '최도윤',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: '데이터베이스 구성',
owner: '윤서아',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: '테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: '기능 테스트',
owner: '박민지',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: '성능 테스트',
owner: '임태민',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: '운영 준비',
owner: '김서연',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: '교육 자료 작성',
owner: '한지우',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: '배포 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: '서버 점검',
owner: '오세훈',
start: '2026-12-14',
end: '2026-12-18',
},
];
// 평평한 배열이라서 가족 관계는 parentId만 따라가면 바로 구해져요.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // 기준이 되는 줄(마지막으로 직접 고른 줄)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log({
ko: '"백엔드"를 골라 두었어요. 다른 줄을 눌러 기준을 바꿀 수 있어요.',
en: '"백엔드" is selected. Click another row to change the reference.',
});
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// 찾은 줄들을 펼쳐서 보이게 하고 선택해 줘요(숨어 있던 안쪽 줄도 조상을 열어서 보여 줘요).
function show(api: GridApi<Row>, label: [string, string], found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say({ ko: `"${name}"의 ${label[0]}: 없어요.`, en: `No ${label[1]} for "${name}".` });
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say({
ko: `"${name}"의 ${label[0]} ${found.length}개: ${found.map((row) => row.task).join(', ')}`,
en: `${found.length} ${label[1]} of "${name}": ${found.map((row) => row.task).join(', ')}`,
});
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, ['부모', 'parent'], parentOf(base)),
children: (api: GridApi<Row>) => show(api, ['자식', 'children'], childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, ['조상', 'ancestors'], ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, ['자손', 'descendants'], descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};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="parent">Parent</button>
<button type="button" id="children">Children</button>
<button type="button" id="ancestors">Ancestors</button>
<button type="button" id="descendants">Descendants</button>
<button type="button" id="self">Only my row</button>
</div>
<div id="grid" style="height: 490px"></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('parent').addEventListener('click', () => actions.parent(api));
document.getElementById('children').addEventListener('click', () => actions.children(api));
document.getElementById('ancestors').addEventListener('click', () => actions.ancestors(api));
document.getElementById('descendants').addEventListener('click', () => actions.descendants(api));
document.getElementById('self').addEventListener('click', () => actions.self(api));const rows = [
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
];
// With a flat array, family relations come straight from following parentId.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id) => rows.filter((row) => row.parentId === id);
const parentOf = (id) => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId)] : [];
};
const ancestorsOf = (id) => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id) => childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // The reference row (the one you picked last by hand)
let busy = false;
let say = () => { };
export function setup(api, log) {
say = log;
api.setSelectedKeys([base]);
log('"Backend" is selected. Click another row to change the reference.');
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined)
base = String(last);
});
}
// Reveal the found rows and select them (hidden inner rows are shown by opening their ancestors).
function show(api, label, found) {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say(`No ${label} for "${name}".`);
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say(`${found.length} ${label} of "${name}": ${found.map((row) => row.task).join(', ')}`);
}
export const actions = {
parent: (api) => show(api, 'parent', parentOf(base)),
children: (api) => show(api, 'children', childrenOf(base)),
ancestors: (api) => show(api, 'ancestors', ancestorsOf(base)),
descendants: (api) => show(api, 'descendants', descendantsOf(base)),
self: (api) => api.setSelectedKeys([base]),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Find the parent, children, ancestors and descendants</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="parent">Parent</button>
<button type="button" id="children">Children</button>
<button type="button" id="ancestors">Ancestors</button>
<button type="button" id="descendants">Descendants</button>
<button type="button" id="self">Only my row</button>
</div>
<div id="grid" style="height: 490px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
];
// With a flat array, family relations come straight from following parentId.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id) => rows.filter((row) => row.parentId === id);
const parentOf = (id) => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId)] : [];
};
const ancestorsOf = (id) => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id) => childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // The reference row (the one you picked last by hand)
let busy = false;
let say = () => { };
function setup(api, log) {
say = log;
api.setSelectedKeys([base]);
log('"Backend" is selected. Click another row to change the reference.');
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined)
base = String(last);
});
}
// Reveal the found rows and select them (hidden inner rows are shown by opening their ancestors).
function show(api, label, found) {
const name = byId.get(base)?.task ?? base;
if (!found.length)
return say(`No ${label} for "${name}".`);
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say(`${found.length} ${label} of "${name}": ${found.map((row) => row.task).join(', ')}`);
}
const actions = {
parent: (api) => show(api, 'parent', parentOf(base)),
children: (api) => show(api, 'children', childrenOf(base)),
ancestors: (api) => show(api, 'ancestors', ancestorsOf(base)),
descendants: (api) => show(api, 'descendants', descendantsOf(base)),
self: (api) => api.setSelectedKeys([base]),
};
options.ariaLabel = "Find the parent, children, ancestors and descendants";
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('parent').addEventListener('click', () => actions.parent(api));
document.getElementById('children').addEventListener('click', () => actions.children(api));
document.getElementById('ancestors').addEventListener('click', () => actions.ancestors(api));
document.getElementById('descendants').addEventListener('click', () => actions.descendants(api));
document.getElementById('self').addEventListener('click', () => actions.self(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.parent(api)}
>Parent</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.children(api)}
>Children</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ancestors(api)}
>Ancestors</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.descendants(api)}
>Descendants</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.self(api)}
>Only my row</button>
</div>
<Grid style={{ height: 490 }} 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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
];
// With a flat array, family relations come straight from following parentId.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // The reference row (the one you picked last by hand)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log('"Backend" is selected. Click another row to change the reference.');
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// Reveal the found rows and select them (hidden inner rows are shown by opening their ancestors).
function show(api: GridApi<Row>, label: string, found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length) return say(`No ${label} for "${name}".`);
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say(`${found.length} ${label} of "${name}": ${found.map((row) => row.task).join(', ')}`);
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, 'parent', parentOf(base)),
children: (api: GridApi<Row>) => show(api, 'children', childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, 'ancestors', ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, 'descendants', descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};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.parent(api)">Parent</button>
<button
type="button"
:disabled="!api"
@click="api && actions.children(api)"
>Children</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ancestors(api)"
>Ancestors</button>
<button
type="button"
:disabled="!api"
@click="api && actions.descendants(api)"
>Descendants</button>
<button type="button" :disabled="!api" @click="api && actions.self(api)">Only my row</button>
</div>
<Grid style="height: 490px" :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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
];
// With a flat array, family relations come straight from following parentId.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // The reference row (the one you picked last by hand)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log('"Backend" is selected. Click another row to change the reference.');
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// Reveal the found rows and select them (hidden inner rows are shown by opening their ancestors).
function show(api: GridApi<Row>, label: string, found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length) return say(`No ${label} for "${name}".`);
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say(`${found.length} ${label} of "${name}": ${found.map((row) => row.task).join(', ')}`);
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, 'parent', parentOf(base)),
children: (api: GridApi<Row>) => show(api, 'children', childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, 'ancestors', ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, 'descendants', descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};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.parent(api)"
>Parent</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.children(api)"
>Children</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ancestors(api)"
>Ancestors</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.descendants(api)"
>Descendants</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.self(api)"
>Only my row</button>
</div>
<mx-grid style="height: 490px" [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;
}
const rows: Row[] = [
{
id: 'T1',
parentId: null,
task: 'Release',
owner: 'Emma Stone',
start: '2026-11-02',
end: '2026-12-18',
},
{
id: 'T10',
parentId: 'T1',
task: 'Planning',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-13',
},
{
id: 'T11',
parentId: 'T10',
task: 'Gather requirements',
owner: 'Liam Carter',
start: '2026-11-02',
end: '2026-11-06',
},
{
id: 'T12',
parentId: 'T10',
task: 'Screen design',
owner: 'Mia Parker',
start: '2026-11-09',
end: '2026-11-13',
},
{
id: 'T20',
parentId: 'T1',
task: 'Development',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T21',
parentId: 'T20',
task: 'Frontend',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-27',
},
{
id: 'T211',
parentId: 'T21',
task: 'Login screen',
owner: 'Ava Moore',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T212',
parentId: 'T21',
task: 'List screen',
owner: 'Jack Reed',
start: '2026-11-23',
end: '2026-11-27',
},
{
id: 'T22',
parentId: 'T20',
task: 'Backend',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-12-04',
},
{
id: 'T221',
parentId: 'T22',
task: 'API design',
owner: 'Noah Davis',
start: '2026-11-16',
end: '2026-11-20',
},
{
id: 'T222',
parentId: 'T22',
task: 'Database setup',
owner: 'Chloe Young',
start: '2026-11-23',
end: '2026-12-04',
},
{
id: 'T30',
parentId: 'T1',
task: 'Testing',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-18',
},
{
id: 'T31',
parentId: 'T30',
task: 'Functional test',
owner: 'Mia Parker',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T32',
parentId: 'T30',
task: 'Performance test',
owner: 'Ethan Lee',
start: '2026-12-14',
end: '2026-12-18',
},
{
id: 'T2',
parentId: null,
task: 'Operations prep',
owner: 'Emma Stone',
start: '2026-12-07',
end: '2026-12-23',
},
{
id: 'T40',
parentId: 'T2',
task: 'Write training materials',
owner: 'Grace Hall',
start: '2026-12-07',
end: '2026-12-11',
},
{
id: 'T41',
parentId: 'T2',
task: 'Deployment check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-23',
},
{
id: 'T411',
parentId: 'T41',
task: 'Server check',
owner: 'Henry Ford',
start: '2026-12-14',
end: '2026-12-18',
},
];
// With a flat array, family relations come straight from following parentId.
const byId = new Map(rows.map((row) => [row.id, row]));
const childrenOf = (id: string): Row[] => rows.filter((row) => row.parentId === id);
const parentOf = (id: string): Row[] => {
const parentId = byId.get(id)?.parentId;
return parentId ? [byId.get(parentId) as Row] : [];
};
const ancestorsOf = (id: string): Row[] => parentOf(id).flatMap((p) => [...ancestorsOf(p.id), p]);
const descendantsOf = (id: string): Row[] =>
childrenOf(id).flatMap((child) => [child, ...descendantsOf(child.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,
rowKey: 'id',
selection: 'multiple',
tree: { parentKey: 'parentId', column: 'task', expandDepth: 2 },
};
let base = 'T22'; // The reference row (the one you picked last by hand)
let busy = false;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
api.setSelectedKeys([base]);
log('"Backend" is selected. Click another row to change the reference.');
return api.on('selectionChanged', ({ selectedKeys }) => {
const last = selectedKeys[selectedKeys.length - 1];
if (!busy && last !== undefined) base = String(last);
});
}
// Reveal the found rows and select them (hidden inner rows are shown by opening their ancestors).
function show(api: GridApi<Row>, label: string, found: Row[]): void {
const name = byId.get(base)?.task ?? base;
if (!found.length) return say(`No ${label} for "${name}".`);
busy = true;
found.forEach((row) => api.revealRow(row.id));
api.setSelectedKeys(found.map((row) => row.id));
api.scrollToRow(found[0].id);
busy = false;
say(`${found.length} ${label} of "${name}": ${found.map((row) => row.task).join(', ')}`);
}
export const actions = {
parent: (api: GridApi<Row>) => show(api, 'parent', parentOf(base)),
children: (api: GridApi<Row>) => show(api, 'children', childrenOf(base)),
ancestors: (api: GridApi<Row>) => show(api, 'ancestors', ancestorsOf(base)),
descendants: (api: GridApi<Row>) => show(api, 'descendants', descendantsOf(base)),
self: (api: GridApi<Row>) => api.setSelectedKeys([base]),
};