PMS JSON을 변환해 그리기Normalize PMS JSON and draw it
snake_case PMS 데이터를 normalizePmsData로 바꿔 표와 차트에 넣고 개수를 비교해요.Convert snake_case PMS data with normalizePmsData, load it into grid and chart and compare the counts.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="another">다른 샘플 불러오기</button>
</div>
<div id="grid" style="height: 440px"></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('another').addEventListener('click', () => actions.another(api));import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
const pms = (id, parent, no, wbs, name, who, status, start, end, pct, more) => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id, name) => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: '성탄절' }],
});
// 샘플 두 개. 일부러 깨진 항목(id 없음, null)과 숫자 id를 섞었어요. 변환기는 깨진 항목을 건너뛰고 id를 모두 글자로 바꿔요.
const SAMPLES = [
{
tasks: [
pms('1001', null, 1, '1', '웹사이트 개편', '이준호', 'IN_PROGRESS', '2026-11-02', '2026-12-18', 40, { has_children: true }),
pms('1002', '1001', 1, '1.1', '요구사항 정리', '박민지', 'DONE', '2026-11-02', '2026-11-06', 100, {}),
pms('1003', '1001', 2, '1.2', '화면 설계', '최하은', 'IN_PROGRESS', '2026-11-09', '2026-11-20', 60, {}),
pms('1004', '1001', 3, '1.3', '개발', '김도윤', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', '오픈', '이준호', 'TODO', '2026-12-18', '2026-12-18', 0, {
is_milestone: true,
}),
pms('1006', '1001', 5, '1.5', '사후 점검', '', 'TODO', null, null, 0, {}),
{ name: 'id 없는 항목' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, '표준(월-금)')],
},
{
tasks: [
pms('9007199254740993', null, 1, '1', '물류 센터 이전', '정우진', 'IN_PROGRESS', '2026-12-01', '2027-01-29', 30, { has_children: true, calendar_id: 7 }),
pms('9007199254740994', '9007199254740993', 1, '1.1', '재고 조사', '윤서아', 'DONE', '2026-12-01', '2026-12-11', 100, { calendar_id: 7 }),
pms('9007199254740995', '9007199254740993', 2, '1.2', '설비 이전', '오세훈', 'IN_PROGRESS', '2026-12-14', '2027-01-15', 20, { calendar_id: 7 }),
pms('9007199254740996', '9007199254740993', 3, '1.3', '가동 시험', '정우진', 'TODO', '2027-01-18', '2027-01-29', 0, { calendar_id: 7 }),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, '물류 달력')],
},
];
// 간트 작업을 표 행으로 바꿔요.
function toRow(t) {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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();
},
};
}
let view = null;
let say = () => { };
let current = 0;
// 원본 -> normalizePmsData -> 표와 차트. 원본·변환 뒤 개수를 기록해요.
function load(api, index) {
const raw = SAMPLES[index];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say({
ko: `샘플 ${index + 1}: 원본 작업 ${raw.tasks.length}개·의존 ${raw.dependencies.length}개 -> 변환 뒤 작업 ${data.tasks.length}개·의존 ${data.dependencies.length}개 (id는 모두 글자)`,
en: `Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
});
}
export function setup(api, log) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>PMS JSON을 변환해 그리기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="another">다른 샘플 불러오기</button>
</div>
<div id="grid" style="height: 440px"></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;
const { normalizePmsData } = MaxGridGantt;
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
const pms = (id, parent, no, wbs, name, who, status, start, end, pct, more) => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id, name) => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: '성탄절' }],
});
// 샘플 두 개. 일부러 깨진 항목(id 없음, null)과 숫자 id를 섞었어요. 변환기는 깨진 항목을 건너뛰고 id를 모두 글자로 바꿔요.
const SAMPLES = [
{
tasks: [
pms('1001', null, 1, '1', '웹사이트 개편', '이준호', 'IN_PROGRESS', '2026-11-02', '2026-12-18', 40, { has_children: true }),
pms('1002', '1001', 1, '1.1', '요구사항 정리', '박민지', 'DONE', '2026-11-02', '2026-11-06', 100, {}),
pms('1003', '1001', 2, '1.2', '화면 설계', '최하은', 'IN_PROGRESS', '2026-11-09', '2026-11-20', 60, {}),
pms('1004', '1001', 3, '1.3', '개발', '김도윤', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', '오픈', '이준호', 'TODO', '2026-12-18', '2026-12-18', 0, {
is_milestone: true,
}),
pms('1006', '1001', 5, '1.5', '사후 점검', '', 'TODO', null, null, 0, {}),
{ name: 'id 없는 항목' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, '표준(월-금)')],
},
{
tasks: [
pms('9007199254740993', null, 1, '1', '물류 센터 이전', '정우진', 'IN_PROGRESS', '2026-12-01', '2027-01-29', 30, { has_children: true, calendar_id: 7 }),
pms('9007199254740994', '9007199254740993', 1, '1.1', '재고 조사', '윤서아', 'DONE', '2026-12-01', '2026-12-11', 100, { calendar_id: 7 }),
pms('9007199254740995', '9007199254740993', 2, '1.2', '설비 이전', '오세훈', 'IN_PROGRESS', '2026-12-14', '2027-01-15', 20, { calendar_id: 7 }),
pms('9007199254740996', '9007199254740993', 3, '1.3', '가동 시험', '정우진', 'TODO', '2027-01-18', '2027-01-29', 0, { calendar_id: 7 }),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, '물류 달력')],
},
];
// 간트 작업을 표 행으로 바꿔요.
function toRow(t) {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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();
},
};
}
let view = null;
let say = () => { };
let current = 0;
// 원본 -> normalizePmsData -> 표와 차트. 원본·변환 뒤 개수를 기록해요.
function load(api, index) {
const raw = SAMPLES[index];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say({
ko: `샘플 ${index + 1}: 원본 작업 ${raw.tasks.length}개·의존 ${raw.dependencies.length}개 -> 변환 뒤 작업 ${data.tasks.length}개·의존 ${data.dependencies.length}개 (id는 모두 글자)`,
en: `Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
});
}
function setup(api, log) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
const actions = {
another: (api) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
};
options.ariaLabel = "PMS JSON을 변환해 그리기";
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('another').addEventListener('click', () => actions.another(api));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.another(api)}
>다른 샘플 불러오기</button>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// PMS 서버가 주는 JSON 모양(snake_case)이에요. 아래 pms()는 한 작업을 그 모양으로 만들어 줘요.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: '성탄절' }],
});
// 샘플 두 개. 일부러 깨진 항목(id 없음, null)과 숫자 id를 섞었어요. 변환기는 깨진 항목을 건너뛰고 id를 모두 글자로 바꿔요.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'웹사이트 개편',
'이준호',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'요구사항 정리',
'박민지',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'화면 설계',
'최하은',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms('1004', '1001', 3, '1.3', '개발', '김도윤', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', '오픈', '이준호', 'TODO', '2026-12-18', '2026-12-18', 0, {
is_milestone: true,
}),
pms('1006', '1001', 5, '1.5', '사후 점검', '', 'TODO', null, null, 0, {}),
{ name: 'id 없는 항목' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, '표준(월-금)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'물류 센터 이전',
'정우진',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'재고 조사',
'윤서아',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'설비 이전',
'오세훈',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'가동 시험',
'정우진',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, '물류 달력')],
},
];
// 간트 작업을 표 행으로 바꿔요.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// 원본 -> normalizePmsData -> 표와 차트. 원본·변환 뒤 개수를 기록해요.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say({
ko: `샘플 ${index + 1}: 원본 작업 ${raw.tasks.length}개·의존 ${raw.dependencies.length}개 -> 변환 뒤 작업 ${data.tasks.length}개·의존 ${data.dependencies.length}개 (id는 모두 글자)`,
en: `Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.another(api)">다른 샘플 불러오기</button>
</div>
<Grid style="height: 440px" :options="options" @ready="onReady" />
</template>import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// PMS 서버가 주는 JSON 모양(snake_case)이에요. 아래 pms()는 한 작업을 그 모양으로 만들어 줘요.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: '성탄절' }],
});
// 샘플 두 개. 일부러 깨진 항목(id 없음, null)과 숫자 id를 섞었어요. 변환기는 깨진 항목을 건너뛰고 id를 모두 글자로 바꿔요.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'웹사이트 개편',
'이준호',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'요구사항 정리',
'박민지',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'화면 설계',
'최하은',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms('1004', '1001', 3, '1.3', '개발', '김도윤', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', '오픈', '이준호', 'TODO', '2026-12-18', '2026-12-18', 0, {
is_milestone: true,
}),
pms('1006', '1001', 5, '1.5', '사후 점검', '', 'TODO', null, null, 0, {}),
{ name: 'id 없는 항목' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, '표준(월-금)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'물류 센터 이전',
'정우진',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'재고 조사',
'윤서아',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'설비 이전',
'오세훈',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'가동 시험',
'정우진',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, '물류 달력')],
},
];
// 간트 작업을 표 행으로 바꿔요.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// 원본 -> normalizePmsData -> 표와 차트. 원본·변환 뒤 개수를 기록해요.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say({
ko: `샘플 ${index + 1}: 원본 작업 ${raw.tasks.length}개·의존 ${raw.dependencies.length}개 -> 변환 뒤 작업 ${data.tasks.length}개·의존 ${data.dependencies.length}개 (id는 모두 글자)`,
en: `Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 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.another(api)"
>다른 샘플 불러오기</button>
</div>
<mx-grid style="height: 440px" [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 { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// PMS 서버가 주는 JSON 모양(snake_case)이에요. 아래 pms()는 한 작업을 그 모양으로 만들어 줘요.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: '성탄절' }],
});
// 샘플 두 개. 일부러 깨진 항목(id 없음, null)과 숫자 id를 섞었어요. 변환기는 깨진 항목을 건너뛰고 id를 모두 글자로 바꿔요.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'웹사이트 개편',
'이준호',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'요구사항 정리',
'박민지',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'화면 설계',
'최하은',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms('1004', '1001', 3, '1.3', '개발', '김도윤', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', '오픈', '이준호', 'TODO', '2026-12-18', '2026-12-18', 0, {
is_milestone: true,
}),
pms('1006', '1001', 5, '1.5', '사후 점검', '', 'TODO', null, null, 0, {}),
{ name: 'id 없는 항목' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, '표준(월-금)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'물류 센터 이전',
'정우진',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'재고 조사',
'윤서아',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'설비 이전',
'오세훈',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'가동 시험',
'정우진',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, '물류 달력')],
},
];
// 간트 작업을 표 행으로 바꿔요.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// 원본 -> normalizePmsData -> 표와 차트. 원본·변환 뒤 개수를 기록해요.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say({
ko: `샘플 ${index + 1}: 원본 작업 ${raw.tasks.length}개·의존 ${raw.dependencies.length}개 -> 변환 뒤 작업 ${data.tasks.length}개·의존 ${data.dependencies.length}개 (id는 모두 글자)`,
en: `Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/gantt @maxgrid/gantt-core.
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="another">Load another sample</button>
</div>
<div id="grid" style="height: 440px"></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('another').addEventListener('click', () => actions.another(api));import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
const pms = (id, parent, no, wbs, name, who, status, start, end, pct, more) => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id, name) => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: 'Christmas Day' }],
});
// Two samples. They deliberately mix in broken items (no id, null) and numeric ids. The normalizer skips broken items and turns every id into a string.
const SAMPLES = [
{
tasks: [
pms('1001', null, 1, '1', 'Website redesign', 'Liam Carter', 'IN_PROGRESS', '2026-11-02', '2026-12-18', 40, { has_children: true }),
pms('1002', '1001', 1, '1.1', 'Requirements', 'Emma Stone', 'DONE', '2026-11-02', '2026-11-06', 100, {}),
pms('1003', '1001', 2, '1.2', 'Page design', 'Olivia Hart', 'IN_PROGRESS', '2026-11-09', '2026-11-20', 60, {}),
pms('1004', '1001', 3, '1.3', 'Development', 'Noah Reed', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', 'Go live', 'Liam Carter', 'TODO', '2026-12-18', '2026-12-18', 0, { is_milestone: true }),
pms('1006', '1001', 5, '1.5', 'Follow-up', '', 'TODO', null, null, 0, {}),
{ name: 'item without id' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, 'Standard (Mon-Fri)')],
},
{
tasks: [
pms('9007199254740993', null, 1, '1', 'Warehouse move', 'Ethan Brooks', 'IN_PROGRESS', '2026-12-01', '2027-01-29', 30, { has_children: true, calendar_id: 7 }),
pms('9007199254740994', '9007199254740993', 1, '1.1', 'Stock count', 'Ava Moore', 'DONE', '2026-12-01', '2026-12-11', 100, { calendar_id: 7 }),
pms('9007199254740995', '9007199254740993', 2, '1.2', 'Equipment move', 'Mason Clark', 'IN_PROGRESS', '2026-12-14', '2027-01-15', 20, { calendar_id: 7 }),
pms('9007199254740996', '9007199254740993', 3, '1.3', 'Trial run', 'Ethan Brooks', 'TODO', '2027-01-18', '2027-01-29', 0, { calendar_id: 7 }),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, 'Warehouse calendar')],
},
];
// Turn a Gantt task into a grid row.
function toRow(t) {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 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();
},
};
}
let view = null;
let say = () => { };
let current = 0;
// raw -> normalizePmsData -> grid and chart. Log the counts before and after.
function load(api, index) {
const raw = SAMPLES[index];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say(`Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`);
}
export function setup(api, log) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
};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>Normalize PMS JSON and draw it</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="another">Load another sample</button>
</div>
<div id="grid" style="height: 440px"></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;
const { normalizePmsData } = MaxGridGantt;
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
const pms = (id, parent, no, wbs, name, who, status, start, end, pct, more) => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id, name) => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: 'Christmas Day' }],
});
// Two samples. They deliberately mix in broken items (no id, null) and numeric ids. The normalizer skips broken items and turns every id into a string.
const SAMPLES = [
{
tasks: [
pms('1001', null, 1, '1', 'Website redesign', 'Liam Carter', 'IN_PROGRESS', '2026-11-02', '2026-12-18', 40, { has_children: true }),
pms('1002', '1001', 1, '1.1', 'Requirements', 'Emma Stone', 'DONE', '2026-11-02', '2026-11-06', 100, {}),
pms('1003', '1001', 2, '1.2', 'Page design', 'Olivia Hart', 'IN_PROGRESS', '2026-11-09', '2026-11-20', 60, {}),
pms('1004', '1001', 3, '1.3', 'Development', 'Noah Reed', 'TODO', '2026-11-23', '2026-12-11', 0, {}),
pms('1005', '1001', 4, '1.4', 'Go live', 'Liam Carter', 'TODO', '2026-12-18', '2026-12-18', 0, { is_milestone: true }),
pms('1006', '1001', 5, '1.5', 'Follow-up', '', 'TODO', null, null, 0, {}),
{ name: 'item without id' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, 'Standard (Mon-Fri)')],
},
{
tasks: [
pms('9007199254740993', null, 1, '1', 'Warehouse move', 'Ethan Brooks', 'IN_PROGRESS', '2026-12-01', '2027-01-29', 30, { has_children: true, calendar_id: 7 }),
pms('9007199254740994', '9007199254740993', 1, '1.1', 'Stock count', 'Ava Moore', 'DONE', '2026-12-01', '2026-12-11', 100, { calendar_id: 7 }),
pms('9007199254740995', '9007199254740993', 2, '1.2', 'Equipment move', 'Mason Clark', 'IN_PROGRESS', '2026-12-14', '2027-01-15', 20, { calendar_id: 7 }),
pms('9007199254740996', '9007199254740993', 3, '1.3', 'Trial run', 'Ethan Brooks', 'TODO', '2027-01-18', '2027-01-29', 0, { calendar_id: 7 }),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, 'Warehouse calendar')],
},
];
// Turn a Gantt task into a grid row.
function toRow(t) {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 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();
},
};
}
let view = null;
let say = () => { };
let current = 0;
// raw -> normalizePmsData -> grid and chart. Log the counts before and after.
function load(api, index) {
const raw = SAMPLES[index];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say(`Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`);
}
function setup(api, log) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
const actions = {
another: (api) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
};
options.ariaLabel = "Normalize PMS JSON and draw it";
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('another').addEventListener('click', () => actions.another(api));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/gantt @maxgrid/gantt-core.
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.another(api)}
>Load another sample</button>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// The JSON shape a PMS server sends (snake_case). pms() below builds one task in that shape.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: 'Christmas Day' }],
});
// Two samples. They deliberately mix in broken items (no id, null) and numeric ids. The normalizer skips broken items and turns every id into a string.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'Website redesign',
'Liam Carter',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'Requirements',
'Emma Stone',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'Page design',
'Olivia Hart',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms(
'1004',
'1001',
3,
'1.3',
'Development',
'Noah Reed',
'TODO',
'2026-11-23',
'2026-12-11',
0,
{},
),
pms(
'1005',
'1001',
4,
'1.4',
'Go live',
'Liam Carter',
'TODO',
'2026-12-18',
'2026-12-18',
0,
{ is_milestone: true },
),
pms('1006', '1001', 5, '1.5', 'Follow-up', '', 'TODO', null, null, 0, {}),
{ name: 'item without id' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, 'Standard (Mon-Fri)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'Warehouse move',
'Ethan Brooks',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'Stock count',
'Ava Moore',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'Equipment move',
'Mason Clark',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'Trial run',
'Ethan Brooks',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, 'Warehouse calendar')],
},
];
// Turn a Gantt task into a grid row.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// raw -> normalizePmsData -> grid and chart. Log the counts before and after.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say(
`Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/gantt @maxgrid/gantt-core.
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.another(api)">Load another sample</button>
</div>
<Grid style="height: 440px" :options="options" @ready="onReady" />
</template>import { createGantt, createSplitView } from '@maxgrid/gantt';
import { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// The JSON shape a PMS server sends (snake_case). pms() below builds one task in that shape.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: 'Christmas Day' }],
});
// Two samples. They deliberately mix in broken items (no id, null) and numeric ids. The normalizer skips broken items and turns every id into a string.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'Website redesign',
'Liam Carter',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'Requirements',
'Emma Stone',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'Page design',
'Olivia Hart',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms(
'1004',
'1001',
3,
'1.3',
'Development',
'Noah Reed',
'TODO',
'2026-11-23',
'2026-12-11',
0,
{},
),
pms(
'1005',
'1001',
4,
'1.4',
'Go live',
'Liam Carter',
'TODO',
'2026-12-18',
'2026-12-18',
0,
{ is_milestone: true },
),
pms('1006', '1001', 5, '1.5', 'Follow-up', '', 'TODO', null, null, 0, {}),
{ name: 'item without id' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, 'Standard (Mon-Fri)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'Warehouse move',
'Ethan Brooks',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'Stock count',
'Ava Moore',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'Equipment move',
'Mason Clark',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'Trial run',
'Ethan Brooks',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, 'Warehouse calendar')],
},
];
// Turn a Gantt task into a grid row.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// raw -> normalizePmsData -> grid and chart. Log the counts before and after.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say(
`Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/gantt @maxgrid/gantt-core.
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.another(api)"
>Load another sample</button>
</div>
<mx-grid style="height: 440px" [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 { normalizePmsData } from '@maxgrid/gantt-core';
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;
}
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',
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// The JSON shape a PMS server sends (snake_case). pms() below builds one task in that shape.
type Raw = Record<string, unknown>;
const pms = (
id: string,
parent: string | null,
no: number,
wbs: string,
name: string,
who: string,
status: string,
start: string | null,
end: string | null,
pct: number,
more: Raw,
): Raw => ({
id,
parent_id: parent,
sort_no: no,
wbs_code: wbs,
name,
assignee_name: who,
status,
planned_start: start,
planned_end: end,
progress_pct: pct,
is_milestone: false,
has_children: false,
calendar_id: null,
version: 3,
...more,
});
const calendar = (id: number, name: string): Raw => ({
id,
name,
work_days: 31,
is_default: true,
hours_per_day: 8,
exceptions: [{ date: '2026-12-25', working: false, note: 'Christmas Day' }],
});
// Two samples. They deliberately mix in broken items (no id, null) and numeric ids. The normalizer skips broken items and turns every id into a string.
const SAMPLES: Array<{ tasks: unknown[]; dependencies: unknown[]; calendars: unknown[] }> = [
{
tasks: [
pms(
'1001',
null,
1,
'1',
'Website redesign',
'Liam Carter',
'IN_PROGRESS',
'2026-11-02',
'2026-12-18',
40,
{ has_children: true },
),
pms(
'1002',
'1001',
1,
'1.1',
'Requirements',
'Emma Stone',
'DONE',
'2026-11-02',
'2026-11-06',
100,
{},
),
pms(
'1003',
'1001',
2,
'1.2',
'Page design',
'Olivia Hart',
'IN_PROGRESS',
'2026-11-09',
'2026-11-20',
60,
{},
),
pms(
'1004',
'1001',
3,
'1.3',
'Development',
'Noah Reed',
'TODO',
'2026-11-23',
'2026-12-11',
0,
{},
),
pms(
'1005',
'1001',
4,
'1.4',
'Go live',
'Liam Carter',
'TODO',
'2026-12-18',
'2026-12-18',
0,
{ is_milestone: true },
),
pms('1006', '1001', 5, '1.5', 'Follow-up', '', 'TODO', null, null, 0, {}),
{ name: 'item without id' },
null,
],
dependencies: [
{ id: 1, predecessor_id: 1002, successor_id: 1003, dep_type: 'FS', lag_days: 0 },
{ id: 2, predecessor_id: 1003, successor_id: 1004, dep_type: 'FS', lag_days: 2 },
{ id: 3, predecessor_id: 1004, successor_id: 1005, dep_type: 'FF', lag_days: 0 },
{ id: 4, predecessor_id: 1004 },
],
calendars: [calendar(1, 'Standard (Mon-Fri)')],
},
{
tasks: [
pms(
'9007199254740993',
null,
1,
'1',
'Warehouse move',
'Ethan Brooks',
'IN_PROGRESS',
'2026-12-01',
'2027-01-29',
30,
{ has_children: true, calendar_id: 7 },
),
pms(
'9007199254740994',
'9007199254740993',
1,
'1.1',
'Stock count',
'Ava Moore',
'DONE',
'2026-12-01',
'2026-12-11',
100,
{ calendar_id: 7 },
),
pms(
'9007199254740995',
'9007199254740993',
2,
'1.2',
'Equipment move',
'Mason Clark',
'IN_PROGRESS',
'2026-12-14',
'2027-01-15',
20,
{ calendar_id: 7 },
),
pms(
'9007199254740996',
'9007199254740993',
3,
'1.3',
'Trial run',
'Ethan Brooks',
'TODO',
'2027-01-18',
'2027-01-29',
0,
{ calendar_id: 7 },
),
],
dependencies: [
{
id: 11,
predecessor_id: '9007199254740994',
successor_id: '9007199254740995',
dep_type: 'FS',
lag_days: 0,
},
{
id: 12,
predecessor_id: '9007199254740995',
successor_id: '9007199254740996',
dep_type: 'SS',
lag_days: 10,
},
],
calendars: [calendar(7, 'Warehouse calendar')],
},
];
// Turn a Gantt task into a grid row.
function toRow(t: {
id: string;
parentId: string | null;
wbsCode?: string;
name: string;
assigneeName?: string;
plannedStart: string | null;
plannedEnd: string | null;
progressPct: number;
}): Row {
return {
id: t.id,
parentId: t.parentId,
wbs: t.wbsCode ?? '',
name: t.name,
assignee: t.assigneeName ?? '',
start: t.plannedStart ?? '',
end: t.plannedEnd ?? '',
progress: t.progressPct,
};
}
// 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();
},
};
}
let view: ReturnType<typeof mountGantt> | null = null;
let say: (message: LogText) => void = () => {};
let current = 0;
// raw -> normalizePmsData -> grid and chart. Log the counts before and after.
function load(api: GridApi<Row>, index: number) {
const raw = SAMPLES[index] as (typeof SAMPLES)[number];
const data = normalizePmsData(raw);
api.setRows(data.tasks.map(toRow));
view?.gantt.setData(data);
say(
`Sample ${index + 1}: raw ${raw.tasks.length} tasks, ${raw.dependencies.length} dependencies -> normalized ${data.tasks.length} tasks, ${data.dependencies.length} dependencies (all ids are strings)`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
view = mountGantt(api);
load(api, current);
const unlink = view.gantt.attachGrid(api);
return () => {
unlink();
view?.destroy();
view = null;
};
}
export const actions = {
another: (api: GridApi<Row>) => {
current = (current + 1) % SAMPLES.length;
load(api, current);
},
};