본문으로 건너뛰기Skip to content
예제 첫화면Examples home

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.

활용Intermediate
직접 써 보기Live previewPMS JSON을 변환해 그리기Normalize PMS JSON and draw it

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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);
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

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.

index.html
<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>
main.js
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));
example.js
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);
  },
};