차트 이벤트를 기록으로 보기Watch the chart events in the log
행 선택, 작업 열기, 보이는 구간 변경, 접기 이벤트를 기록 패널에 남겨요.Log row selection, task open, viewport change and collapse toggles in the log panel.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/gantt로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 460px"></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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T = [
['1', null, '모바일 앱 개편', '이준호', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', '기획', '박민지', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', '요구사항 수집', '이준호', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', '경쟁 서비스 조사', '박민지', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', '범위 확정', '이준호', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', '디자인', '최하은', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', '와이어프레임', '최하은', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', '화면 디자인', '최하은', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', '디자인 시스템', '한지우', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', '디자인 검토', '최하은', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', '백엔드', '김도윤', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API 설계', '김도윤', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', '데이터베이스 설계', '김도윤', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', '인증 서비스', '정우진', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', '주문 서비스', '정우진', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', '프런트엔드', '오세훈', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', '앱 기본 틀', '오세훈', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', '로그인 화면', '오세훈', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', '상품 목록', '윤서아', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', '결제 화면', '윤서아', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', '푸시 알림', '정우진', '', '', 0, 'TODO'],
['23', '11', '기능 개발 완료', '김도윤', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', '테스트', '한지우', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', '테스트 계획', '한지우', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', '통합 테스트', '이준호', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', '성능 테스트', '이준호', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', '버그 수정', '오세훈', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', '테스트 승인', '한지우', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', '출시', '박민지', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', '릴리스 노트', '박민지', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', '스토어 제출', '박민지', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', '단계별 배포', '김도윤', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', '출시일', '박민지', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', '운영 준비', '정우진', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', '모니터링 구성', '정우진', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', '고객지원 교육', '윤서아', '', '', 0, 'TODO'],
['38', '35', '마케팅', '윤서아', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', '랜딩 페이지', '한지우', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', '보도 자료', '박민지', '', '', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: '성탄절' },
{ date: '2027-01-01', working: false, note: '신정' },
],
},
],
};
export const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// 좁은 컨테이너(600px 미만)에서는 앞의 열만 남겨 차트 자리를 확보해요. 넓어지면 열이 돌아와요.
const fitColumns = () => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress'])
api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// 연결을 풀고 표를 원래 자리로 돌려놔요.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api, log) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// 차트가 보내는 이벤트 네 가지를 모두 기록해요.
const offs = [
view.gantt.on('row-select', (e) => log({ ko: `행 선택: ${e.taskId ?? '없음'}`, en: `Row selected: ${e.taskId ?? 'none'}` })),
view.gantt.on('task-open', (e) => log({
ko: `작업 열기(더블클릭): ${e.taskId}`,
en: `Task opened (double-click): ${e.taskId}`,
})),
view.gantt.on('toggle-collapse', (e) => log({
ko: `${e.taskId}번 ${e.collapsed ? '접힘' : '펼침'}`,
en: `Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`,
})),
view.gantt.on('viewport-change', (e) => log({
ko: `보이는 구간: ${e.zoom} 단계, ${e.from} ~ ${e.to}`,
en: `Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`,
})),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// 접기 이벤트를 쉽게 보도록 버튼으로 표 트리를 접고 펴요.
export const actions = {
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!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="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 460px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<link rel="stylesheet" href="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.css" />
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.min.js"></script>
<script>
const { createGantt, createSplitView } = MaxGridGantt;
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T = [
['1', null, '모바일 앱 개편', '이준호', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', '기획', '박민지', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', '요구사항 수집', '이준호', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', '경쟁 서비스 조사', '박민지', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', '범위 확정', '이준호', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', '디자인', '최하은', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', '와이어프레임', '최하은', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', '화면 디자인', '최하은', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', '디자인 시스템', '한지우', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', '디자인 검토', '최하은', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', '백엔드', '김도윤', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API 설계', '김도윤', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', '데이터베이스 설계', '김도윤', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', '인증 서비스', '정우진', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', '주문 서비스', '정우진', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', '프런트엔드', '오세훈', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', '앱 기본 틀', '오세훈', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', '로그인 화면', '오세훈', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', '상품 목록', '윤서아', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', '결제 화면', '윤서아', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', '푸시 알림', '정우진', '', '', 0, 'TODO'],
['23', '11', '기능 개발 완료', '김도윤', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', '테스트', '한지우', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', '테스트 계획', '한지우', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', '통합 테스트', '이준호', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', '성능 테스트', '이준호', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', '버그 수정', '오세훈', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', '테스트 승인', '한지우', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', '출시', '박민지', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', '릴리스 노트', '박민지', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', '스토어 제출', '박민지', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', '단계별 배포', '김도윤', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', '출시일', '박민지', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', '운영 준비', '정우진', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', '모니터링 구성', '정우진', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', '고객지원 교육', '윤서아', '', '', 0, 'TODO'],
['38', '35', '마케팅', '윤서아', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', '랜딩 페이지', '한지우', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', '보도 자료', '박민지', '', '', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: '성탄절' },
{ date: '2027-01-01', working: false, note: '신정' },
],
},
],
};
const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// 좁은 컨테이너(600px 미만)에서는 앞의 열만 남겨 차트 자리를 확보해요. 넓어지면 열이 돌아와요.
const fitColumns = () => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress'])
api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// 연결을 풀고 표를 원래 자리로 돌려놔요.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
function setup(api, log) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// 차트가 보내는 이벤트 네 가지를 모두 기록해요.
const offs = [
view.gantt.on('row-select', (e) => log({ ko: `행 선택: ${e.taskId ?? '없음'}`, en: `Row selected: ${e.taskId ?? 'none'}` })),
view.gantt.on('task-open', (e) => log({
ko: `작업 열기(더블클릭): ${e.taskId}`,
en: `Task opened (double-click): ${e.taskId}`,
})),
view.gantt.on('toggle-collapse', (e) => log({
ko: `${e.taskId}번 ${e.collapsed ? '접힘' : '펼침'}`,
en: `Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`,
})),
view.gantt.on('viewport-change', (e) => log({
ko: `보이는 구간: ${e.zoom} 단계, ${e.from} ~ ${e.to}`,
en: `Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`,
})),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// 접기 이벤트를 쉽게 보도록 버튼으로 표 트리를 접고 펴요.
const actions = {
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/gantt로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.expandAll(api)}
>모두 펼치기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>모두 접기</button>
</div>
<Grid style={{ height: 460 }} ref={gridRef} options={options} />
</>
);
}import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '모바일 앱 개편', '이준호', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', '기획', '박민지', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', '요구사항 수집', '이준호', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', '경쟁 서비스 조사', '박민지', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', '범위 확정', '이준호', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', '디자인', '최하은', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', '와이어프레임', '최하은', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', '화면 디자인', '최하은', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', '디자인 시스템', '한지우', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', '디자인 검토', '최하은', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', '백엔드', '김도윤', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API 설계', '김도윤', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', '데이터베이스 설계', '김도윤', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', '인증 서비스', '정우진', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', '주문 서비스', '정우진', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', '프런트엔드', '오세훈', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', '앱 기본 틀', '오세훈', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', '로그인 화면', '오세훈', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', '상품 목록', '윤서아', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', '결제 화면', '윤서아', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', '푸시 알림', '정우진', '', '', 0, 'TODO'],
['23', '11', '기능 개발 완료', '김도윤', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', '테스트', '한지우', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', '테스트 계획', '한지우', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', '통합 테스트', '이준호', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', '성능 테스트', '이준호', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', '버그 수정', '오세훈', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', '테스트 승인', '한지우', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', '출시', '박민지', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', '릴리스 노트', '박민지', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', '스토어 제출', '박민지', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', '단계별 배포', '김도윤', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', '출시일', '박민지', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', '운영 준비', '정우진', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', '모니터링 구성', '정우진', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', '고객지원 교육', '윤서아', '', '', 0, 'TODO'],
['38', '35', '마케팅', '윤서아', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', '랜딩 페이지', '한지우', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', '보도 자료', '박민지', '', '', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: '성탄절' },
{ date: '2027-01-01', working: false, note: '신정' },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// 좁은 컨테이너(600px 미만)에서는 앞의 열만 남겨 차트 자리를 확보해요. 넓어지면 열이 돌아와요.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// 연결을 풀고 표를 원래 자리로 돌려놔요.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// 차트가 보내는 이벤트 네 가지를 모두 기록해요.
const offs = [
view.gantt.on('row-select', (e) =>
log({ ko: `행 선택: ${e.taskId ?? '없음'}`, en: `Row selected: ${e.taskId ?? 'none'}` }),
),
view.gantt.on('task-open', (e) =>
log({
ko: `작업 열기(더블클릭): ${e.taskId}`,
en: `Task opened (double-click): ${e.taskId}`,
}),
),
view.gantt.on('toggle-collapse', (e) =>
log({
ko: `${e.taskId}번 ${e.collapsed ? '접힘' : '펼침'}`,
en: `Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`,
}),
),
view.gantt.on('viewport-change', (e) =>
log({
ko: `보이는 구간: ${e.zoom} 단계, ${e.from} ~ ${e.to}`,
en: `Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`,
}),
),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// 접기 이벤트를 쉽게 보도록 버튼으로 표 트리를 접고 펴요.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/gantt로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<Grid style="height: 460px" :options="options" @ready="onReady" />
</template>import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '모바일 앱 개편', '이준호', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', '기획', '박민지', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', '요구사항 수집', '이준호', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', '경쟁 서비스 조사', '박민지', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', '범위 확정', '이준호', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', '디자인', '최하은', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', '와이어프레임', '최하은', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', '화면 디자인', '최하은', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', '디자인 시스템', '한지우', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', '디자인 검토', '최하은', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', '백엔드', '김도윤', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API 설계', '김도윤', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', '데이터베이스 설계', '김도윤', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', '인증 서비스', '정우진', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', '주문 서비스', '정우진', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', '프런트엔드', '오세훈', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', '앱 기본 틀', '오세훈', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', '로그인 화면', '오세훈', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', '상품 목록', '윤서아', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', '결제 화면', '윤서아', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', '푸시 알림', '정우진', '', '', 0, 'TODO'],
['23', '11', '기능 개발 완료', '김도윤', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', '테스트', '한지우', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', '테스트 계획', '한지우', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', '통합 테스트', '이준호', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', '성능 테스트', '이준호', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', '버그 수정', '오세훈', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', '테스트 승인', '한지우', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', '출시', '박민지', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', '릴리스 노트', '박민지', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', '스토어 제출', '박민지', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', '단계별 배포', '김도윤', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', '출시일', '박민지', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', '운영 준비', '정우진', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', '모니터링 구성', '정우진', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', '고객지원 교육', '윤서아', '', '', 0, 'TODO'],
['38', '35', '마케팅', '윤서아', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', '랜딩 페이지', '한지우', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', '보도 자료', '박민지', '', '', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: '성탄절' },
{ date: '2027-01-01', working: false, note: '신정' },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// 좁은 컨테이너(600px 미만)에서는 앞의 열만 남겨 차트 자리를 확보해요. 넓어지면 열이 돌아와요.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// 연결을 풀고 표를 원래 자리로 돌려놔요.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// 차트가 보내는 이벤트 네 가지를 모두 기록해요.
const offs = [
view.gantt.on('row-select', (e) =>
log({ ko: `행 선택: ${e.taskId ?? '없음'}`, en: `Row selected: ${e.taskId ?? 'none'}` }),
),
view.gantt.on('task-open', (e) =>
log({
ko: `작업 열기(더블클릭): ${e.taskId}`,
en: `Task opened (double-click): ${e.taskId}`,
}),
),
view.gantt.on('toggle-collapse', (e) =>
log({
ko: `${e.taskId}번 ${e.collapsed ? '접힘' : '펼침'}`,
en: `Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`,
}),
),
view.gantt.on('viewport-change', (e) =>
log({
ko: `보이는 구간: ${e.zoom} 단계, ${e.from} ~ ${e.to}`,
en: `Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`,
}),
),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// 접기 이벤트를 쉽게 보도록 버튼으로 표 트리를 접고 펴요.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/gantt로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<mx-grid style="height: 460px" [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 { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '모바일 앱 개편', '이준호', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', '기획', '박민지', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', '요구사항 수집', '이준호', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', '경쟁 서비스 조사', '박민지', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', '범위 확정', '이준호', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', '디자인', '최하은', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', '와이어프레임', '최하은', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', '화면 디자인', '최하은', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', '디자인 시스템', '한지우', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', '디자인 검토', '최하은', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', '백엔드', '김도윤', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API 설계', '김도윤', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', '데이터베이스 설계', '김도윤', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', '인증 서비스', '정우진', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', '주문 서비스', '정우진', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', '프런트엔드', '오세훈', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', '앱 기본 틀', '오세훈', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', '로그인 화면', '오세훈', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', '상품 목록', '윤서아', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', '결제 화면', '윤서아', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', '푸시 알림', '정우진', '', '', 0, 'TODO'],
['23', '11', '기능 개발 완료', '김도윤', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', '테스트', '한지우', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', '테스트 계획', '한지우', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', '통합 테스트', '이준호', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', '성능 테스트', '이준호', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', '버그 수정', '오세훈', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', '테스트 승인', '한지우', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', '출시', '박민지', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', '릴리스 노트', '박민지', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', '스토어 제출', '박민지', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', '단계별 배포', '김도윤', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', '출시일', '박민지', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', '운영 준비', '정우진', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', '모니터링 구성', '정우진', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', '고객지원 교육', '윤서아', '', '', 0, 'TODO'],
['38', '35', '마케팅', '윤서아', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', '랜딩 페이지', '한지우', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', '보도 자료', '박민지', '', '', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: '성탄절' },
{ date: '2027-01-01', working: false, note: '신정' },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// 좁은 컨테이너(600px 미만)에서는 앞의 열만 남겨 차트 자리를 확보해요. 넓어지면 열이 돌아와요.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// 연결을 풀고 표를 원래 자리로 돌려놔요.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// 차트가 보내는 이벤트 네 가지를 모두 기록해요.
const offs = [
view.gantt.on('row-select', (e) =>
log({ ko: `행 선택: ${e.taskId ?? '없음'}`, en: `Row selected: ${e.taskId ?? 'none'}` }),
),
view.gantt.on('task-open', (e) =>
log({
ko: `작업 열기(더블클릭): ${e.taskId}`,
en: `Task opened (double-click): ${e.taskId}`,
}),
),
view.gantt.on('toggle-collapse', (e) =>
log({
ko: `${e.taskId}번 ${e.collapsed ? '접힘' : '펼침'}`,
en: `Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`,
}),
),
view.gantt.on('viewport-change', (e) =>
log({
ko: `보이는 구간: ${e.zoom} 단계, ${e.from} ~ ${e.to}`,
en: `Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`,
}),
),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// 접기 이벤트를 쉽게 보도록 버튼으로 표 트리를 접고 펴요.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
}; This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/gantt.
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="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 460px"></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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, parent, task, assignee, start, end, progress, status]. Empty dates = unscheduled; start = end = milestone.
const T = [
['1', null, 'Mobile app renewal', 'Liam Carter', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', 'Planning', 'Emma Stone', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', 'Requirements gathering', 'Liam Carter', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', 'Competitor research', 'Emma Stone', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', 'Scope sign-off', 'Liam Carter', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', 'Design', 'Olivia Hart', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', 'Wireframes', 'Olivia Hart', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', 'UI design', 'Olivia Hart', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', 'Design system', 'Sophia Lane', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', 'Design review', 'Olivia Hart', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', 'Development', 'Noah Reed', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', 'Backend', 'Noah Reed', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API design', 'Noah Reed', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', 'Database schema', 'Noah Reed', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', 'Auth service', 'Ethan Brooks', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', 'Order service', 'Ethan Brooks', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', 'Frontend', 'Mason Clark', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', 'App shell', 'Mason Clark', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', 'Login screens', 'Mason Clark', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', 'Product list', 'Ava Moore', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', 'Checkout', 'Ava Moore', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', 'Push notifications', 'Ethan Brooks', '', '', 0, 'TODO'],
['23', '11', 'Feature complete', 'Noah Reed', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', 'Testing', 'Sophia Lane', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', 'Test plan', 'Sophia Lane', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', 'Integration tests', 'Liam Carter', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', 'Performance tests', 'Liam Carter', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', 'Bug fixing', 'Mason Clark', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', 'Test sign-off', 'Sophia Lane', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', 'Launch', 'Emma Stone', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', 'Release notes', 'Emma Stone', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', 'Store submission', 'Emma Stone', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', 'Staged rollout', 'Noah Reed', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', 'Launch day', 'Emma Stone', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', 'Operations', 'Ethan Brooks', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', 'Monitoring setup', 'Ethan Brooks', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', 'Support training', 'Ava Moore', '', '', 0, 'TODO'],
['38', '35', 'Marketing', 'Ava Moore', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', 'Landing page', 'Sophia Lane', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', 'Press kit', 'Emma Stone', '', '', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// The order inside a parent (sortNo) and the WBS code are derived from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (the tree is built from the parent id).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the dates as given and never schedules.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: 'Standard (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: 'Christmas Day' },
{ date: '2027-01-01', working: false, note: "New Year's Day" },
],
},
],
};
export const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Row and header heights must match the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// Narrow container (< 600 px): only the first columns stay so the chart keeps room; the rest come back when it widens.
const fitColumns = () => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress'])
api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// Unlink and put the grid back where it was.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api, log) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// Log all four events the chart emits.
const offs = [
view.gantt.on('row-select', (e) => log(`Row selected: ${e.taskId ?? 'none'}`)),
view.gantt.on('task-open', (e) => log(`Task opened (double-click): ${e.taskId}`)),
view.gantt.on('toggle-collapse', (e) => log(`Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`)),
view.gantt.on('viewport-change', (e) => log(`Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`)),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// Buttons to collapse and expand the grid tree, so the toggle events are easy to see.
export const actions = {
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};This HTML also loads an extra bundle (the extra script tag above) and uses it as a global. No install is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Watch the chart events in the log</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 460px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<link rel="stylesheet" href="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.css" />
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.min.js"></script>
<script>
const { createGantt, createSplitView } = MaxGridGantt;
// [id, parent, task, assignee, start, end, progress, status]. Empty dates = unscheduled; start = end = milestone.
const T = [
['1', null, 'Mobile app renewal', 'Liam Carter', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', 'Planning', 'Emma Stone', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', 'Requirements gathering', 'Liam Carter', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', 'Competitor research', 'Emma Stone', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', 'Scope sign-off', 'Liam Carter', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', 'Design', 'Olivia Hart', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', 'Wireframes', 'Olivia Hart', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', 'UI design', 'Olivia Hart', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', 'Design system', 'Sophia Lane', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', 'Design review', 'Olivia Hart', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', 'Development', 'Noah Reed', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', 'Backend', 'Noah Reed', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API design', 'Noah Reed', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', 'Database schema', 'Noah Reed', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', 'Auth service', 'Ethan Brooks', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', 'Order service', 'Ethan Brooks', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', 'Frontend', 'Mason Clark', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', 'App shell', 'Mason Clark', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', 'Login screens', 'Mason Clark', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', 'Product list', 'Ava Moore', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', 'Checkout', 'Ava Moore', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', 'Push notifications', 'Ethan Brooks', '', '', 0, 'TODO'],
['23', '11', 'Feature complete', 'Noah Reed', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', 'Testing', 'Sophia Lane', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', 'Test plan', 'Sophia Lane', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', 'Integration tests', 'Liam Carter', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', 'Performance tests', 'Liam Carter', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', 'Bug fixing', 'Mason Clark', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', 'Test sign-off', 'Sophia Lane', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', 'Launch', 'Emma Stone', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', 'Release notes', 'Emma Stone', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', 'Store submission', 'Emma Stone', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', 'Staged rollout', 'Noah Reed', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', 'Launch day', 'Emma Stone', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', 'Operations', 'Ethan Brooks', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', 'Monitoring setup', 'Ethan Brooks', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', 'Support training', 'Ava Moore', '', '', 0, 'TODO'],
['38', '35', 'Marketing', 'Ava Moore', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', 'Landing page', 'Sophia Lane', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', 'Press kit', 'Emma Stone', '', '', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// The order inside a parent (sortNo) and the WBS code are derived from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (the tree is built from the parent id).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the dates as given and never schedules.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: 'Standard (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: 'Christmas Day' },
{ date: '2027-01-01', working: false, note: "New Year's Day" },
],
},
],
};
const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Row and header heights must match the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// Narrow container (< 600 px): only the first columns stay so the chart keeps room; the rest come back when it widens.
const fitColumns = () => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress'])
api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// Unlink and put the grid back where it was.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
function setup(api, log) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// Log all four events the chart emits.
const offs = [
view.gantt.on('row-select', (e) => log(`Row selected: ${e.taskId ?? 'none'}`)),
view.gantt.on('task-open', (e) => log(`Task opened (double-click): ${e.taskId}`)),
view.gantt.on('toggle-collapse', (e) => log(`Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`)),
view.gantt.on('viewport-change', (e) => log(`Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`)),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// Buttons to collapse and expand the grid tree, so the toggle events are easy to see.
const actions = {
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "Watch the chart events in the log";
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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/gantt.
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.expandAll(api)}
>Expand all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>Collapse all</button>
</div>
<Grid style={{ height: 460 }} ref={gridRef} options={options} />
</>
);
}import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, parent, task, assignee, start, end, progress, status]. Empty dates = unscheduled; start = end = milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Mobile app renewal', 'Liam Carter', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', 'Planning', 'Emma Stone', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', 'Requirements gathering', 'Liam Carter', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', 'Competitor research', 'Emma Stone', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', 'Scope sign-off', 'Liam Carter', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', 'Design', 'Olivia Hart', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', 'Wireframes', 'Olivia Hart', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', 'UI design', 'Olivia Hart', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', 'Design system', 'Sophia Lane', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', 'Design review', 'Olivia Hart', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', 'Development', 'Noah Reed', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', 'Backend', 'Noah Reed', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API design', 'Noah Reed', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', 'Database schema', 'Noah Reed', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', 'Auth service', 'Ethan Brooks', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', 'Order service', 'Ethan Brooks', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', 'Frontend', 'Mason Clark', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', 'App shell', 'Mason Clark', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', 'Login screens', 'Mason Clark', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', 'Product list', 'Ava Moore', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', 'Checkout', 'Ava Moore', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', 'Push notifications', 'Ethan Brooks', '', '', 0, 'TODO'],
['23', '11', 'Feature complete', 'Noah Reed', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', 'Testing', 'Sophia Lane', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', 'Test plan', 'Sophia Lane', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', 'Integration tests', 'Liam Carter', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', 'Performance tests', 'Liam Carter', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', 'Bug fixing', 'Mason Clark', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', 'Test sign-off', 'Sophia Lane', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', 'Launch', 'Emma Stone', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', 'Release notes', 'Emma Stone', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', 'Store submission', 'Emma Stone', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', 'Staged rollout', 'Noah Reed', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', 'Launch day', 'Emma Stone', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', 'Operations', 'Ethan Brooks', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', 'Monitoring setup', 'Ethan Brooks', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', 'Support training', 'Ava Moore', '', '', 0, 'TODO'],
['38', '35', 'Marketing', 'Ava Moore', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', 'Landing page', 'Sophia Lane', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', 'Press kit', 'Emma Stone', '', '', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// The order inside a parent (sortNo) and the WBS code are derived from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (the tree is built from the parent id).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the dates as given and never schedules.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: 'Standard (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: 'Christmas Day' },
{ date: '2027-01-01', working: false, note: "New Year's Day" },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Row and header heights must match the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// Narrow container (< 600 px): only the first columns stay so the chart keeps room; the rest come back when it widens.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// Unlink and put the grid back where it was.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// Log all four events the chart emits.
const offs = [
view.gantt.on('row-select', (e) => log(`Row selected: ${e.taskId ?? 'none'}`)),
view.gantt.on('task-open', (e) => log(`Task opened (double-click): ${e.taskId}`)),
view.gantt.on('toggle-collapse', (e) =>
log(`Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`),
),
view.gantt.on('viewport-change', (e) => log(`Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`)),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// Buttons to collapse and expand the grid tree, so the toggle events are easy to see.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/gantt.
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.expandAll(api)"
>Expand all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<Grid style="height: 460px" :options="options" @ready="onReady" />
</template>import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, parent, task, assignee, start, end, progress, status]. Empty dates = unscheduled; start = end = milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Mobile app renewal', 'Liam Carter', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', 'Planning', 'Emma Stone', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', 'Requirements gathering', 'Liam Carter', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', 'Competitor research', 'Emma Stone', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', 'Scope sign-off', 'Liam Carter', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', 'Design', 'Olivia Hart', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', 'Wireframes', 'Olivia Hart', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', 'UI design', 'Olivia Hart', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', 'Design system', 'Sophia Lane', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', 'Design review', 'Olivia Hart', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', 'Development', 'Noah Reed', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', 'Backend', 'Noah Reed', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API design', 'Noah Reed', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', 'Database schema', 'Noah Reed', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', 'Auth service', 'Ethan Brooks', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', 'Order service', 'Ethan Brooks', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', 'Frontend', 'Mason Clark', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', 'App shell', 'Mason Clark', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', 'Login screens', 'Mason Clark', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', 'Product list', 'Ava Moore', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', 'Checkout', 'Ava Moore', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', 'Push notifications', 'Ethan Brooks', '', '', 0, 'TODO'],
['23', '11', 'Feature complete', 'Noah Reed', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', 'Testing', 'Sophia Lane', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', 'Test plan', 'Sophia Lane', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', 'Integration tests', 'Liam Carter', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', 'Performance tests', 'Liam Carter', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', 'Bug fixing', 'Mason Clark', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', 'Test sign-off', 'Sophia Lane', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', 'Launch', 'Emma Stone', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', 'Release notes', 'Emma Stone', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', 'Store submission', 'Emma Stone', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', 'Staged rollout', 'Noah Reed', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', 'Launch day', 'Emma Stone', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', 'Operations', 'Ethan Brooks', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', 'Monitoring setup', 'Ethan Brooks', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', 'Support training', 'Ava Moore', '', '', 0, 'TODO'],
['38', '35', 'Marketing', 'Ava Moore', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', 'Landing page', 'Sophia Lane', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', 'Press kit', 'Emma Stone', '', '', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// The order inside a parent (sortNo) and the WBS code are derived from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (the tree is built from the parent id).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the dates as given and never schedules.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: 'Standard (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: 'Christmas Day' },
{ date: '2027-01-01', working: false, note: "New Year's Day" },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Row and header heights must match the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// Narrow container (< 600 px): only the first columns stay so the chart keeps room; the rest come back when it widens.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// Unlink and put the grid back where it was.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// Log all four events the chart emits.
const offs = [
view.gantt.on('row-select', (e) => log(`Row selected: ${e.taskId ?? 'none'}`)),
view.gantt.on('task-open', (e) => log(`Task opened (double-click): ${e.taskId}`)),
view.gantt.on('toggle-collapse', (e) =>
log(`Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`),
),
view.gantt.on('viewport-change', (e) => log(`Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`)),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// Buttons to collapse and expand the grid tree, so the toggle events are easy to see.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/gantt.
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.expandAll(api)"
>Expand all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<mx-grid style="height: 460px" [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 { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED';
// [id, parent, task, assignee, start, end, progress, status]. Empty dates = unscheduled; start = end = milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Mobile app renewal', 'Liam Carter', '2026-10-05', '2027-02-12', 45, 'IN_PROGRESS'],
['2', '1', 'Planning', 'Emma Stone', '2026-10-05', '2026-10-23', 100, 'DONE'],
['3', '2', 'Requirements gathering', 'Liam Carter', '2026-10-05', '2026-10-16', 100, 'DONE'],
['4', '2', 'Competitor research', 'Emma Stone', '2026-10-12', '2026-10-21', 100, 'DONE'],
['5', '2', 'Scope sign-off', 'Liam Carter', '2026-10-23', '2026-10-23', 100, 'DONE'],
['6', '1', 'Design', 'Olivia Hart', '2026-10-26', '2026-11-27', 85, 'IN_PROGRESS'],
['7', '6', 'Wireframes', 'Olivia Hart', '2026-10-26', '2026-11-06', 100, 'DONE'],
['8', '6', 'UI design', 'Olivia Hart', '2026-11-02', '2026-11-20', 100, 'DONE'],
['9', '6', 'Design system', 'Sophia Lane', '2026-11-09', '2026-11-24', 70, 'IN_PROGRESS'],
['10', '6', 'Design review', 'Olivia Hart', '2026-11-27', '2026-11-27', 0, 'TODO'],
['11', '1', 'Development', 'Noah Reed', '2026-11-09', '2027-01-22', 25, 'IN_PROGRESS'],
['12', '11', 'Backend', 'Noah Reed', '2026-11-09', '2027-01-08', 35, 'IN_PROGRESS'],
['13', '12', 'API design', 'Noah Reed', '2026-11-09', '2026-11-20', 100, 'DONE'],
['14', '12', 'Database schema', 'Noah Reed', '2026-11-16', '2026-11-25', 100, 'DONE'],
['15', '12', 'Auth service', 'Ethan Brooks', '2026-11-23', '2026-12-11', 40, 'IN_PROGRESS'],
['16', '12', 'Order service', 'Ethan Brooks', '2026-12-07', '2027-01-08', 0, 'TODO'],
['17', '11', 'Frontend', 'Mason Clark', '2026-11-30', '2027-01-22', 8, 'IN_PROGRESS'],
['18', '17', 'App shell', 'Mason Clark', '2026-11-30', '2026-12-11', 40, 'IN_PROGRESS'],
['19', '17', 'Login screens', 'Mason Clark', '2026-12-07', '2026-12-18', 0, 'TODO'],
['20', '17', 'Product list', 'Ava Moore', '2026-12-14', '2027-01-08', 0, 'TODO'],
['21', '17', 'Checkout', 'Ava Moore', '2027-01-04', '2027-01-22', 0, 'TODO'],
['22', '11', 'Push notifications', 'Ethan Brooks', '', '', 0, 'TODO'],
['23', '11', 'Feature complete', 'Noah Reed', '2027-01-22', '2027-01-22', 0, 'TODO'],
['24', '1', 'Testing', 'Sophia Lane', '2026-12-14', '2027-01-29', 5, 'TODO'],
['25', '24', 'Test plan', 'Sophia Lane', '2026-12-14', '2026-12-23', 30, 'IN_PROGRESS'],
['26', '24', 'Integration tests', 'Liam Carter', '2027-01-11', '2027-01-22', 0, 'TODO'],
['27', '24', 'Performance tests', 'Liam Carter', '2027-01-18', '2027-01-27', 10, 'ON_HOLD'],
['28', '24', 'Bug fixing', 'Mason Clark', '2027-01-18', '2027-01-29', 0, 'TODO'],
['29', '24', 'Test sign-off', 'Sophia Lane', '2027-01-29', '2027-01-29', 0, 'TODO'],
['30', '1', 'Launch', 'Emma Stone', '2027-02-01', '2027-02-12', 0, 'TODO'],
['31', '30', 'Release notes', 'Emma Stone', '2027-02-01', '2027-02-04', 0, 'TODO'],
['32', '30', 'Store submission', 'Emma Stone', '2027-02-01', '2027-02-05', 0, 'TODO'],
['33', '30', 'Staged rollout', 'Noah Reed', '2027-02-08', '2027-02-12', 0, 'TODO'],
['34', '30', 'Launch day', 'Emma Stone', '2027-02-12', '2027-02-12', 0, 'TODO'],
['35', '1', 'Operations', 'Ethan Brooks', '2027-01-11', '2027-02-05', 0, 'TODO'],
['36', '35', 'Monitoring setup', 'Ethan Brooks', '2027-01-25', '2027-02-05', 0, 'TODO'],
['37', '35', 'Support training', 'Ava Moore', '', '', 0, 'TODO'],
['38', '35', 'Marketing', 'Ava Moore', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['39', '38', 'Landing page', 'Sophia Lane', '2027-01-11', '2027-01-29', 0, 'CANCELED'],
['40', '38', 'Press kit', 'Emma Stone', '', '', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 5],
['8', '9', 'SS', 5],
['8', '10', 'FS', 5],
['9', '10', 'FF', 0],
['7', '13', 'FS', 0],
['13', '14', 'SS', 5],
['14', '15', 'SS', 5],
['15', '16', 'SS', 10],
['8', '18', 'FS', 4],
['18', '19', 'SS', 5],
['19', '20', 'SS', 5],
['20', '21', 'FF', 10],
['16', '23', 'FS', 9],
['21', '23', 'FF', 0],
['20', '26', 'FS', 0],
['25', '26', 'FS', 10],
['26', '27', 'SS', 5],
['26', '28', 'SS', 5],
['27', '29', 'FF', 2],
['28', '29', 'FF', 0],
['29', '31', 'FS', 0],
['29', '32', 'FS', 0],
['31', '32', 'SS', 0],
['32', '33', 'FS', 0],
['33', '34', 'FF', 0],
['23', '36', 'FS', 0],
['36', '34', 'SF', 0],
];
// The order inside a parent (sortNo) and the WBS code are derived from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (the tree is built from the parent id).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the dates as given and never schedules.
const data = {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
calendars: [
{
id: 'std',
name: 'Standard (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [
{ date: '2026-12-25', working: false, note: 'Christmas Day' },
{ date: '2027-01-01', working: false, note: "New Year's Day" },
],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Row and header heights must match the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 2 },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
// Narrow container (< 600 px): only the first columns stay so the chart keeps room; the rest come back when it widens.
const fitColumns = (): void => {
const narrow = box.clientWidth < 600;
for (const id of ['assignee', 'start', 'end', 'progress']) api.setColumnVisible(id, !narrow);
api.resizeColumn('wbs', narrow ? 58 : 70);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
box,
right,
// Unlink and put the grid back where it was.
destroy() {
gantt.destroy();
fitObserver.disconnect();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const view = mountGantt(api);
view.gantt.setData(data);
const unlink = view.gantt.attachGrid(api);
// Log all four events the chart emits.
const offs = [
view.gantt.on('row-select', (e) => log(`Row selected: ${e.taskId ?? 'none'}`)),
view.gantt.on('task-open', (e) => log(`Task opened (double-click): ${e.taskId}`)),
view.gantt.on('toggle-collapse', (e) =>
log(`Task ${e.taskId} ${e.collapsed ? 'collapsed' : 'expanded'}`),
),
view.gantt.on('viewport-change', (e) => log(`Viewport: ${e.zoom} zoom, ${e.from} to ${e.to}`)),
];
return () => {
offs.forEach((off) => off());
unlink();
view.destroy();
};
}
// Buttons to collapse and expand the grid tree, so the toggle events are easy to see.
export const actions = {
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};