달력이 다른 작업과 휴일 음영Tasks on different calendars and holiday shading
달력 3개(월-금, 월-토, 일-목)와 휴일을 넣고, 주말·휴일 음영과 툴팁의 작업일 수를 봐요.Use three calendars (Mon-Fri, Mon-Sat, Sun-Thu) with holidays and see the weekend and holiday shading and the working days in the tooltip.
코드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 id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, 부모, 작업, 담당자, 달력 id, 시작, 종료, 진행률, 상태]. 달력 id가 비면 기본 달력이에요.
const T = [
['1', null, '연말 릴리스', '이준호', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['2', '1', '표준 달력 팀(월-금)', '이준호', '', '2026-12-07', '2027-01-08', 30, 'IN_PROGRESS'],
['3', '2', '디자인 초안', '이준호', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', '검토', '이준호', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', '수정', '이준호', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
['6', '1', '6일 근무 팀(월-토)', '박민지', '', '2026-12-07', '2027-01-09', 25, 'IN_PROGRESS'],
['7', '6', '제작', '박민지', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', '조립', '박민지', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', '검수', '박민지', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
['10', '1', '주말이 다른 팀(일-목)', '김도윤', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['11', '10', '준비', '김도윤', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', '운영', '김도윤', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', '인수인계', '김도윤', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류]
const D = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = { std: '표준(월-금)', six: '6일 근무(월-토)', shift: '주말 이동(일-목)' };
const rows = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// 달력 3개. workDays는 월=1, 화=2, 수=4, 목=8, 금=16, 토=32, 일=64를 더한 값이에요.
const holiday = { date: '2026-12-25', working: false, note: '성탄절' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: '신정' },
{ date: '2026-12-12', working: true, note: '토요 근무' },
],
},
{ id: 'six', name: CAL.six, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options = {
columns: [
{ id: 'name', title: '작업', width: 230 },
{ id: 'assignee', title: '담당자', width: 100 },
{ id: 'calendar', title: '달력', width: 150 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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', 'calendar', 'start', 'end'])
api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// 음영(주말·휴일)은 기본 달력 기준이고, 막대 위에 올리면 뜨는 툴팁의 작업일 수는 그 작업의 달력 기준이에요.
log({
ko: `막대 위에 마우스를 올려 보세요. 툴팁의 작업일 수는 작업의 달력으로 세요(휴일·토요 근무 반영)`,
en: `Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
});
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log({
ko: `${task.name}: ${CAL[task.calendarId ?? ''] ?? '기본 달력'}`,
en: `${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`,
});
});
return () => {
off();
unlink();
view.destroy();
};
} 이 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 id="grid" style="height: 420px"></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, 부모, 작업, 담당자, 달력 id, 시작, 종료, 진행률, 상태]. 달력 id가 비면 기본 달력이에요.
const T = [
['1', null, '연말 릴리스', '이준호', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['2', '1', '표준 달력 팀(월-금)', '이준호', '', '2026-12-07', '2027-01-08', 30, 'IN_PROGRESS'],
['3', '2', '디자인 초안', '이준호', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', '검토', '이준호', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', '수정', '이준호', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
['6', '1', '6일 근무 팀(월-토)', '박민지', '', '2026-12-07', '2027-01-09', 25, 'IN_PROGRESS'],
['7', '6', '제작', '박민지', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', '조립', '박민지', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', '검수', '박민지', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
['10', '1', '주말이 다른 팀(일-목)', '김도윤', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['11', '10', '준비', '김도윤', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', '운영', '김도윤', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', '인수인계', '김도윤', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류]
const D = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = { std: '표준(월-금)', six: '6일 근무(월-토)', shift: '주말 이동(일-목)' };
const rows = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// 달력 3개. workDays는 월=1, 화=2, 수=4, 목=8, 금=16, 토=32, 일=64를 더한 값이에요.
const holiday = { date: '2026-12-25', working: false, note: '성탄절' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: '신정' },
{ date: '2026-12-12', working: true, note: '토요 근무' },
],
},
{ id: 'six', name: CAL.six, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
const options = {
columns: [
{ id: 'name', title: '작업', width: 230 },
{ id: 'assignee', title: '담당자', width: 100 },
{ id: 'calendar', title: '달력', width: 150 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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', 'calendar', 'start', 'end'])
api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// 음영(주말·휴일)은 기본 달력 기준이고, 막대 위에 올리면 뜨는 툴팁의 작업일 수는 그 작업의 달력 기준이에요.
log({
ko: `막대 위에 마우스를 올려 보세요. 툴팁의 작업일 수는 작업의 달력으로 세요(휴일·토요 근무 반영)`,
en: `Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
});
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log({
ko: `${task.name}: ${CAL[task.calendarId ?? ''] ?? '기본 달력'}`,
en: `${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`,
});
});
return () => {
off();
unlink();
view.destroy();
};
}
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);
});
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/gantt로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 420 }} 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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, 부모, 작업, 담당자, 달력 id, 시작, 종료, 진행률, 상태]. 달력 id가 비면 기본 달력이에요.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, '연말 릴리스', '이준호', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['2', '1', '표준 달력 팀(월-금)', '이준호', '', '2026-12-07', '2027-01-08', 30, 'IN_PROGRESS'],
['3', '2', '디자인 초안', '이준호', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', '검토', '이준호', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', '수정', '이준호', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
['6', '1', '6일 근무 팀(월-토)', '박민지', '', '2026-12-07', '2027-01-09', 25, 'IN_PROGRESS'],
['7', '6', '제작', '박민지', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', '조립', '박민지', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', '검수', '박민지', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
['10', '1', '주말이 다른 팀(일-목)', '김도윤', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['11', '10', '준비', '김도윤', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', '운영', '김도윤', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', '인수인계', '김도윤', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = { std: '표준(월-금)', six: '6일 근무(월-토)', shift: '주말 이동(일-목)' } as Record<
string,
string
>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// 달력 3개. workDays는 월=1, 화=2, 수=4, 목=8, 금=16, 토=32, 일=64를 더한 값이에요.
const holiday = { date: '2026-12-25', working: false, note: '성탄절' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: '신정' },
{ date: '2026-12-12', working: true, note: '토요 근무' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '작업', width: 230 },
{ id: 'assignee', title: '담당자', width: 100 },
{ id: 'calendar', title: '달력', width: 150 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// 음영(주말·휴일)은 기본 달력 기준이고, 막대 위에 올리면 뜨는 툴팁의 작업일 수는 그 작업의 달력 기준이에요.
log({
ko: `막대 위에 마우스를 올려 보세요. 툴팁의 작업일 수는 작업의 달력으로 세요(휴일·토요 근무 반영)`,
en: `Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
});
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log({
ko: `${task.name}: ${CAL[task.calendarId ?? ''] ?? '기본 달력'}`,
en: `${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`,
});
});
return () => {
off();
unlink();
view.destroy();
};
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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 { 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>
<Grid style="height: 420px" :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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, 부모, 작업, 담당자, 달력 id, 시작, 종료, 진행률, 상태]. 달력 id가 비면 기본 달력이에요.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, '연말 릴리스', '이준호', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['2', '1', '표준 달력 팀(월-금)', '이준호', '', '2026-12-07', '2027-01-08', 30, 'IN_PROGRESS'],
['3', '2', '디자인 초안', '이준호', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', '검토', '이준호', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', '수정', '이준호', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
['6', '1', '6일 근무 팀(월-토)', '박민지', '', '2026-12-07', '2027-01-09', 25, 'IN_PROGRESS'],
['7', '6', '제작', '박민지', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', '조립', '박민지', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', '검수', '박민지', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
['10', '1', '주말이 다른 팀(일-목)', '김도윤', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['11', '10', '준비', '김도윤', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', '운영', '김도윤', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', '인수인계', '김도윤', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = { std: '표준(월-금)', six: '6일 근무(월-토)', shift: '주말 이동(일-목)' } as Record<
string,
string
>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// 달력 3개. workDays는 월=1, 화=2, 수=4, 목=8, 금=16, 토=32, 일=64를 더한 값이에요.
const holiday = { date: '2026-12-25', working: false, note: '성탄절' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: '신정' },
{ date: '2026-12-12', working: true, note: '토요 근무' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '작업', width: 230 },
{ id: 'assignee', title: '담당자', width: 100 },
{ id: 'calendar', title: '달력', width: 150 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// 음영(주말·휴일)은 기본 달력 기준이고, 막대 위에 올리면 뜨는 툴팁의 작업일 수는 그 작업의 달력 기준이에요.
log({
ko: `막대 위에 마우스를 올려 보세요. 툴팁의 작업일 수는 작업의 달력으로 세요(휴일·토요 근무 반영)`,
en: `Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
});
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log({
ko: `${task.name}: ${CAL[task.calendarId ?? ''] ?? '기본 달력'}`,
en: `${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`,
});
});
return () => {
off();
unlink();
view.destroy();
};
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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 { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 420px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, 부모, 작업, 담당자, 달력 id, 시작, 종료, 진행률, 상태]. 달력 id가 비면 기본 달력이에요.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, '연말 릴리스', '이준호', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['2', '1', '표준 달력 팀(월-금)', '이준호', '', '2026-12-07', '2027-01-08', 30, 'IN_PROGRESS'],
['3', '2', '디자인 초안', '이준호', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', '검토', '이준호', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', '수정', '이준호', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
['6', '1', '6일 근무 팀(월-토)', '박민지', '', '2026-12-07', '2027-01-09', 25, 'IN_PROGRESS'],
['7', '6', '제작', '박민지', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', '조립', '박민지', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', '검수', '박민지', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
['10', '1', '주말이 다른 팀(일-목)', '김도윤', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
['11', '10', '준비', '김도윤', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', '운영', '김도윤', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', '인수인계', '김도윤', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = { std: '표준(월-금)', six: '6일 근무(월-토)', shift: '주말 이동(일-목)' } as Record<
string,
string
>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// 달력 3개. workDays는 월=1, 화=2, 수=4, 목=8, 금=16, 토=32, 일=64를 더한 값이에요.
const holiday = { date: '2026-12-25', working: false, note: '성탄절' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: '신정' },
{ date: '2026-12-12', working: true, note: '토요 근무' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '작업', width: 230 },
{ id: 'assignee', title: '담당자', width: 100 },
{ id: 'calendar', title: '달력', width: 150 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// 음영(주말·휴일)은 기본 달력 기준이고, 막대 위에 올리면 뜨는 툴팁의 작업일 수는 그 작업의 달력 기준이에요.
log({
ko: `막대 위에 마우스를 올려 보세요. 툴팁의 작업일 수는 작업의 달력으로 세요(휴일·토요 근무 반영)`,
en: `Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
});
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log({
ko: `${task.name}: ${CAL[task.calendarId ?? ''] ?? '기본 달력'}`,
en: `${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`,
});
});
return () => {
off();
unlink();
view.destroy();
};
} 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 id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, parent, task, assignee, calendar id, start, end, progress, status]. Empty calendar id = the default calendar.
const T = [
['1', null, 'Year-end release', 'Liam Carter', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
[
'2',
'1',
'Standard team (Mon-Fri)',
'Liam Carter',
'',
'2026-12-07',
'2027-01-08',
30,
'IN_PROGRESS',
],
['3', '2', 'Design draft', 'Liam Carter', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', 'Review', 'Liam Carter', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', 'Revise', 'Liam Carter', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
[
'6',
'1',
'Six-day team (Mon-Sat)',
'Emma Stone',
'',
'2026-12-07',
'2027-01-09',
25,
'IN_PROGRESS',
],
['7', '6', 'Fabrication', 'Emma Stone', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', 'Assembly', 'Emma Stone', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', 'Inspection', 'Emma Stone', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
[
'10',
'1',
'Shifted-weekend team (Sun-Thu)',
'Noah Reed',
'',
'2026-12-06',
'2027-01-14',
20,
'IN_PROGRESS',
],
['11', '10', 'Setup', 'Noah Reed', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', 'Run', 'Noah Reed', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', 'Handover', 'Noah Reed', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [predecessor, successor, type]
const D = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = {
std: 'Standard (Mon-Fri)',
six: 'Six-day (Mon-Sat)',
shift: 'Shifted weekend (Sun-Thu)',
};
const rows = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// Three calendars. workDays adds Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64.
const holiday = { date: '2026-12-25', working: false, note: 'Christmas Day' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: "New Year's Day" },
{ date: '2026-12-12', working: true, note: 'Saturday shift' },
],
},
{ id: 'six', name: CAL.six, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'assignee', title: 'Assignee', width: 100 },
{ id: 'calendar', title: 'Calendar', width: 150 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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', 'calendar', 'start', 'end'])
api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// The shading (weekends, holidays) follows the default calendar; the working days in the bar tooltip follow the task calendar.
log(`Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`);
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log(`${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`);
});
return () => {
off();
unlink();
view.destroy();
};
}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>Tasks on different calendars and holiday shading</title>
</head>
<body>
<div id="grid" style="height: 420px"></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, calendar id, start, end, progress, status]. Empty calendar id = the default calendar.
const T = [
['1', null, 'Year-end release', 'Liam Carter', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
[
'2',
'1',
'Standard team (Mon-Fri)',
'Liam Carter',
'',
'2026-12-07',
'2027-01-08',
30,
'IN_PROGRESS',
],
['3', '2', 'Design draft', 'Liam Carter', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', 'Review', 'Liam Carter', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', 'Revise', 'Liam Carter', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
[
'6',
'1',
'Six-day team (Mon-Sat)',
'Emma Stone',
'',
'2026-12-07',
'2027-01-09',
25,
'IN_PROGRESS',
],
['7', '6', 'Fabrication', 'Emma Stone', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', 'Assembly', 'Emma Stone', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', 'Inspection', 'Emma Stone', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
[
'10',
'1',
'Shifted-weekend team (Sun-Thu)',
'Noah Reed',
'',
'2026-12-06',
'2027-01-14',
20,
'IN_PROGRESS',
],
['11', '10', 'Setup', 'Noah Reed', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', 'Run', 'Noah Reed', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', 'Handover', 'Noah Reed', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [predecessor, successor, type]
const D = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = {
std: 'Standard (Mon-Fri)',
six: 'Six-day (Mon-Sat)',
shift: 'Shifted weekend (Sun-Thu)',
};
const rows = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// Three calendars. workDays adds Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64.
const holiday = { date: '2026-12-25', working: false, note: 'Christmas Day' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: "New Year's Day" },
{ date: '2026-12-12', working: true, note: 'Saturday shift' },
],
},
{ id: 'six', name: CAL.six, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
const options = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'assignee', title: 'Assignee', width: 100 },
{ id: 'calendar', title: 'Calendar', width: 150 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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', 'calendar', 'start', 'end'])
api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// The shading (weekends, holidays) follows the default calendar; the working days in the bar tooltip follow the task calendar.
log(`Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`);
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task)
log(`${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`);
});
return () => {
off();
unlink();
view.destroy();
};
}
options.ariaLabel = "Tasks on different calendars and holiday shading";
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);
});
</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 { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 420 }} 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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, parent, task, assignee, calendar id, start, end, progress, status]. Empty calendar id = the default calendar.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, 'Year-end release', 'Liam Carter', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
[
'2',
'1',
'Standard team (Mon-Fri)',
'Liam Carter',
'',
'2026-12-07',
'2027-01-08',
30,
'IN_PROGRESS',
],
['3', '2', 'Design draft', 'Liam Carter', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', 'Review', 'Liam Carter', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', 'Revise', 'Liam Carter', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
[
'6',
'1',
'Six-day team (Mon-Sat)',
'Emma Stone',
'',
'2026-12-07',
'2027-01-09',
25,
'IN_PROGRESS',
],
['7', '6', 'Fabrication', 'Emma Stone', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', 'Assembly', 'Emma Stone', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', 'Inspection', 'Emma Stone', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
[
'10',
'1',
'Shifted-weekend team (Sun-Thu)',
'Noah Reed',
'',
'2026-12-06',
'2027-01-14',
20,
'IN_PROGRESS',
],
['11', '10', 'Setup', 'Noah Reed', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', 'Run', 'Noah Reed', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', 'Handover', 'Noah Reed', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [predecessor, successor, type]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = {
std: 'Standard (Mon-Fri)',
six: 'Six-day (Mon-Sat)',
shift: 'Shifted weekend (Sun-Thu)',
} as Record<string, string>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// Three calendars. workDays adds Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64.
const holiday = { date: '2026-12-25', working: false, note: 'Christmas Day' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: "New Year's Day" },
{ date: '2026-12-12', working: true, note: 'Saturday shift' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'assignee', title: 'Assignee', width: 100 },
{ id: 'calendar', title: 'Calendar', width: 150 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// The shading (weekends, holidays) follows the default calendar; the working days in the bar tooltip follow the task calendar.
log(
`Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
);
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task) log(`${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`);
});
return () => {
off();
unlink();
view.destroy();
};
} 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 { 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>
<Grid style="height: 420px" :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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, parent, task, assignee, calendar id, start, end, progress, status]. Empty calendar id = the default calendar.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, 'Year-end release', 'Liam Carter', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
[
'2',
'1',
'Standard team (Mon-Fri)',
'Liam Carter',
'',
'2026-12-07',
'2027-01-08',
30,
'IN_PROGRESS',
],
['3', '2', 'Design draft', 'Liam Carter', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', 'Review', 'Liam Carter', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', 'Revise', 'Liam Carter', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
[
'6',
'1',
'Six-day team (Mon-Sat)',
'Emma Stone',
'',
'2026-12-07',
'2027-01-09',
25,
'IN_PROGRESS',
],
['7', '6', 'Fabrication', 'Emma Stone', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', 'Assembly', 'Emma Stone', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', 'Inspection', 'Emma Stone', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
[
'10',
'1',
'Shifted-weekend team (Sun-Thu)',
'Noah Reed',
'',
'2026-12-06',
'2027-01-14',
20,
'IN_PROGRESS',
],
['11', '10', 'Setup', 'Noah Reed', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', 'Run', 'Noah Reed', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', 'Handover', 'Noah Reed', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [predecessor, successor, type]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = {
std: 'Standard (Mon-Fri)',
six: 'Six-day (Mon-Sat)',
shift: 'Shifted weekend (Sun-Thu)',
} as Record<string, string>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// Three calendars. workDays adds Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64.
const holiday = { date: '2026-12-25', working: false, note: 'Christmas Day' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: "New Year's Day" },
{ date: '2026-12-12', working: true, note: 'Saturday shift' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'assignee', title: 'Assignee', width: 100 },
{ id: 'calendar', title: 'Calendar', width: 150 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// The shading (weekends, holidays) follows the default calendar; the working days in the bar tooltip follow the task calendar.
log(
`Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
);
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task) log(`${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`);
});
return () => {
off();
unlink();
view.destroy();
};
} 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 { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 420px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
name: string;
assignee: string;
calendar: string;
start: string;
end: string;
}
type Status = 'TODO' | 'IN_PROGRESS';
// [id, parent, task, assignee, calendar id, start, end, progress, status]. Empty calendar id = the default calendar.
const T: Array<[string, string | null, string, string, string, string, string, number, Status]> = [
['1', null, 'Year-end release', 'Liam Carter', '', '2026-12-06', '2027-01-14', 20, 'IN_PROGRESS'],
[
'2',
'1',
'Standard team (Mon-Fri)',
'Liam Carter',
'',
'2026-12-07',
'2027-01-08',
30,
'IN_PROGRESS',
],
['3', '2', 'Design draft', 'Liam Carter', 'std', '2026-12-07', '2026-12-18', 80, 'IN_PROGRESS'],
['4', '2', 'Review', 'Liam Carter', 'std', '2026-12-21', '2026-12-31', 0, 'TODO'],
['5', '2', 'Revise', 'Liam Carter', 'std', '2027-01-04', '2027-01-08', 0, 'TODO'],
[
'6',
'1',
'Six-day team (Mon-Sat)',
'Emma Stone',
'',
'2026-12-07',
'2027-01-09',
25,
'IN_PROGRESS',
],
['7', '6', 'Fabrication', 'Emma Stone', 'six', '2026-12-07', '2026-12-19', 60, 'IN_PROGRESS'],
['8', '6', 'Assembly', 'Emma Stone', 'six', '2026-12-21', '2027-01-02', 0, 'TODO'],
['9', '6', 'Inspection', 'Emma Stone', 'six', '2027-01-04', '2027-01-09', 0, 'TODO'],
[
'10',
'1',
'Shifted-weekend team (Sun-Thu)',
'Noah Reed',
'',
'2026-12-06',
'2027-01-14',
20,
'IN_PROGRESS',
],
['11', '10', 'Setup', 'Noah Reed', 'shift', '2026-12-06', '2026-12-17', 70, 'IN_PROGRESS'],
['12', '10', 'Run', 'Noah Reed', 'shift', '2026-12-20', '2027-01-07', 0, 'TODO'],
['13', '10', 'Handover', 'Noah Reed', 'shift', '2027-01-10', '2027-01-14', 0, 'TODO'],
];
// [predecessor, successor, type]
const D: Array<[string, string, 'FS' | 'FF']> = [
['3', '4', 'FS'],
['4', '5', 'FS'],
['7', '8', 'FS'],
['8', '9', 'FS'],
['11', '12', 'FS'],
['12', '13', 'FS'],
['9', '13', 'FS'],
['5', '9', 'FF'],
];
const parents = new Set(T.map((r) => r[1]));
const CAL = {
std: 'Standard (Mon-Fri)',
six: 'Six-day (Mon-Sat)',
shift: 'Shifted weekend (Sun-Thu)',
} as Record<string, string>;
const rows: Row[] = T.map(([id, parentId, name, assignee, calendar, start, end]) => ({
id,
parentId,
name,
assignee,
calendar: CAL[calendar] ?? '',
start,
end,
}));
// Three calendars. workDays adds Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64.
const holiday = { date: '2026-12-25', working: false, note: 'Christmas Day' };
const data = {
tasks: T.map(([id, parentId, name, assignee, calendar, start, end, progressPct, status], n) => ({
id,
parentId,
sortNo: n + 1,
name,
status,
plannedStart: start,
plannedEnd: end,
progressPct,
isMilestone: false,
hasChildren: parents.has(id),
calendarId: calendar || null,
assigneeName: assignee,
version: 1,
})),
dependencies: D.map(([predecessorId, successorId, depType], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays: 0,
})),
calendars: [
{
id: 'std',
name: CAL.std as string,
workDays: 31,
isDefault: true,
exceptions: [
holiday,
{ date: '2027-01-01', working: false, note: "New Year's Day" },
{ date: '2026-12-12', working: true, note: 'Saturday shift' },
],
},
{ id: 'six', name: CAL.six as string, workDays: 63, isDefault: false, exceptions: [holiday] },
{
id: 'shift',
name: CAL.shift as string,
workDays: 79,
isDefault: false,
exceptions: [holiday],
},
],
};
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Task', width: 230 },
{ id: 'assignee', title: 'Assignee', width: 100 },
{ id: 'calendar', title: 'Calendar', width: 150 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
],
rows,
rowKey: 'id',
rowHeight: 40,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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', 'calendar', 'start', 'end']) api.setColumnVisible(id, !narrow);
};
fitColumns();
const fitObserver = new ResizeObserver(fitColumns);
fitObserver.observe(box);
const gantt = createGantt(right, {
rowHeight: 40,
barHeight: 24,
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);
// The shading (weekends, holidays) follows the default calendar; the working days in the bar tooltip follow the task calendar.
log(
`Hover a bar: the tooltip counts working days on the task calendar (holidays and the extra Saturday included)`,
);
const off = view.gantt.on('row-select', (e) => {
const task = data.tasks.find((x) => x.id === e.taskId);
if (task) log(`${task.name}: ${CAL[task.calendarId ?? ''] ?? 'default calendar'}`);
});
return () => {
off();
unlink();
view.destroy();
};
}