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

작업 5,000개를 가상 스크롤로 그리기Draw 5,000 tasks with virtual scrolling

시험용 작업 1,000개 또는 5,000개를 불러오고 걸린 시간을 기록에서 봐요.Load 1,000 or 5,000 fixture tasks and read the load time in the log.

활용Intermediate
직접 써 보기Live preview작업 5,000개를 가상 스크롤로 그리기Draw 5,000 tasks with virtual scrolling

코드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">
    <select aria-label="작업 수" id="count">
      <option value="1000">1,000개</option>
      <option value="5000" selected>5,000개</option>
    </select>
  </div>
  <div id="grid" style="height: 480px"></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('count').addEventListener('change', (event) => actions.count(api, event.target.value));
example.js
import { createGantt, createSplitView } from '@maxgrid/gantt';
import { makeFixture } from '@maxgrid/gantt-core';
export const options = {
  columns: [
    { id: 'wbs', title: 'WBS', width: 140 },
    { id: 'name', title: '작업', width: 300 },
    { id: 'assignee', title: '담당자', width: 110 },
    { id: 'start', title: '시작', width: 100 },
    { id: 'end', title: '종료', width: 100 },
    {
      id: 'progress',
      title: '진행률(%)',
      kind: 'number',
      width: 90,
      align: 'center',
      cellRenderer: 'progressRing',
    },
  ],
  rows: [],
  rowKey: 'id',
  rowHeight: 40,
  headerHeight: 48,
  verticalScroll: 'external',
  selection: 'single',
  tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 간트 작업을 표 행으로 바꿔요.
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();
  // 깊이 18까지 이름이 읽히도록 들여쓰기 폭을 줄여요(기본 16px는 깊이 18에서 288px라 이름 칸을 다 채워요).
  gridEl.style.setProperty('--mxg-indent', '6px');
  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: 40,
    barHeight: 24,
    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 = () => { };
// 시험용 작업을 만들어 표와 차트에 넣고 걸린 시간을 적어요. 작업 id가 같아서 두 쪽이 행 키로 짝지어져요.
function load(api, count) {
  if (!view)
    return;
  const t0 = performance.now();
  const data = makeFixture({
    tasks: count,
    dependencies: Math.round(count * 1.2),
    seed: 1,
    startDate: '2026-10-05',
  });
  const t1 = performance.now();
  api.setRows([...data.tasks].sort((a, b) => a.sortNo - b.sortNo).map(toRow));
  const t2 = performance.now();
  view.gantt.setData(data);
  const t3 = performance.now();
  say({
    ko: `작업 ${count.toLocaleString('ko-KR')}개: 데이터 만들기 ${Math.round(t1 - t0)}ms · 표 ${Math.round(t2 - t1)}ms · gantt.setData ${Math.round(t3 - t2)}ms`,
    en: `${count.toLocaleString('en-US')} tasks: build ${Math.round(t1 - t0)} ms · grid ${Math.round(t2 - t1)} ms · gantt.setData ${Math.round(t3 - t2)} ms`,
  });
}
export function setup(api, log) {
  say = log;
  view = mountGantt(api);
  load(api, 5000);
  const unlink = view.gantt.attachGrid(api);
  return () => {
    unlink();
    view?.destroy();
    view = null;
  };
}
export const actions = {
  count: (api, value) => load(api, Number(value) || 5000),
};

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">
    <select aria-label="Task count" id="count">
      <option value="1000">1,000</option>
      <option value="5000" selected>5,000</option>
    </select>
  </div>
  <div id="grid" style="height: 480px"></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('count').addEventListener('change', (event) => actions.count(api, event.target.value));
example.js
import { createGantt, createSplitView } from '@maxgrid/gantt';
import { makeFixture } from '@maxgrid/gantt-core';
export const options = {
  columns: [
    { id: 'wbs', title: 'WBS', width: 140 },
    { id: 'name', title: 'Task', width: 300 },
    { 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: 'center',
      cellRenderer: 'progressRing',
    },
  ],
  rows: [],
  rowKey: 'id',
  rowHeight: 40,
  headerHeight: 48,
  verticalScroll: 'external',
  selection: 'single',
  tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 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();
  // Narrow the indent so names stay readable at depth 18 (the default 16px would use 288px of the name column).
  gridEl.style.setProperty('--mxg-indent', '6px');
  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: 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();
    },
  };
}
let view = null;
let say = () => { };
// Build fixture tasks, load them into the grid and the chart, and log the time. Both sides share the task id as the row key.
function load(api, count) {
  if (!view)
    return;
  const t0 = performance.now();
  const data = makeFixture({
    tasks: count,
    dependencies: Math.round(count * 1.2),
    seed: 1,
    startDate: '2026-10-05',
  });
  const t1 = performance.now();
  api.setRows([...data.tasks].sort((a, b) => a.sortNo - b.sortNo).map(toRow));
  const t2 = performance.now();
  view.gantt.setData(data);
  const t3 = performance.now();
  say(`${count.toLocaleString('en-US')} tasks: build ${Math.round(t1 - t0)} ms · grid ${Math.round(t2 - t1)} ms · gantt.setData ${Math.round(t3 - t2)} ms`);
}
export function setup(api, log) {
  say = log;
  view = mountGantt(api);
  load(api, 5000);
  const unlink = view.gantt.attachGrid(api);
  return () => {
    unlink();
    view?.destroy();
    view = null;
  };
}
export const actions = {
  count: (api, value) => load(api, Number(value) || 5000),
};