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

달력이 다른 작업과 휴일 음영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.

활용Intermediate
직접 써 보기Live preview달력이 다른 작업과 휴일 음영Tasks on different calendars and holiday shading

코드Code

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

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

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

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

index.html
<div id="app">
  <div id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
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();
  };
}

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.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
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();
  };
}