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

업무 트리: 폴더 아이콘·가지선·상태 배지·진행 막대Task tree: folder icons, branch lines, status badges and progress bars

폴더 아이콘과 가지선으로 단계를 보여 주고, 다른 컬럼에는 상태 배지와 진행 막대를 그려요. 상태로 걸러 볼 수 있어요.Show levels with folder icons and branch lines, draw status badges and progress bars in other columns, and filter by status.

활용Intermediate
직접 써 보기Live preview업무 트리: 폴더 아이콘·가지선·상태 배지·진행 막대Task tree: folder icons, branch lines, status badges and progress bars

코드Code

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

이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)

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

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

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="상태" id="status">
      <option value="all" selected>전체</option>
      <option value="progress">진행</option>
      <option value="done">완료</option>
      <option value="blocked">막힘</option>
    </select>
    <button type="button" id="expandAll">모두 펼치기</button>
    <button type="button" id="collapseAll">모두 접기</button>
  </div>
  <div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
example.js
// 상태 배지와 진행 막대는 테마 변수 위에 색을 섞어서, 밝은·어두운 테마 모두에서 글자가 잘 보여요.
const tones = { 완료: '#1a7f37', 진행: '#1a56c4', 막힘: '#cf222e' };
const badge = () => {
  let chip;
  return {
    mount(el, ctx) {
      const box = document.createElement('div');
      box.className = 'mxg-cell-center';
      el.append(box);
      chip = document.createElement('span');
      chip.style.cssText =
        'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
      box.append(chip);
      this.update(ctx);
    },
    update(ctx) {
      chip.textContent = ctx.text;
      chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
      chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
    },
    destroy() { },
  };
};
const bar = () => {
  let fill;
  let label;
  return {
    mount(el, ctx) {
      // 칸(el)의 style을 통째로 바꾸면 그리드가 넣은 위치·크기 값이 지워져요. 안에 상자를 하나 두고 그 상자만 꾸며요.
      const box = document.createElement('div');
      box.className = 'mxg-cell-center';
      box.style.gap = '8px';
      el.append(box);
      const track = document.createElement('div');
      // 바탕(트랙)은 글자색을 조금 섞어서 밝은·어두운 화면 모두에서 보여요.
      track.style.cssText =
        'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
      fill = document.createElement('div');
      fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
      track.append(fill);
      label = document.createElement('span');
      label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
      box.append(track, label);
      this.update(ctx);
    },
    update(ctx) {
      const percent = Math.min(100, Math.max(0, Number(ctx.value)));
      fill.style.width = `${percent}%`;
      label.textContent = `${percent}%`;
    },
    destroy() { },
  };
};
// 폴더 아이콘과 가지선(├ └)을 쓴 업무 트리예요. 배지와 막대는 다른 컬럼에 달고, 트리 컬럼은 기본 칸이라 화살표가 나와요.
export const options = {
  columns: [
    { id: 'name', title: '업무', width: 230 },
    { id: 'owner', title: '담당', width: 80 },
    { id: 'status', title: '상태', width: 90, cellRenderer: badge },
    { id: 'done', title: '진행률', width: 140, cellRenderer: bar },
  ],
  rows: [
    { id: 1, parentId: null, name: '2.0 출시', owner: '김서연', status: '진행', done: 60 },
    { id: 2, parentId: 1, name: '데이터 이전', owner: '이준호', status: '완료', done: 100 },
    { id: 3, parentId: 1, name: '새 편집기', owner: '박민지', status: '진행', done: 55 },
    { id: 4, parentId: 3, name: '입력 검증', owner: '박민지', status: '진행', done: 70 },
    { id: 5, parentId: 3, name: '붙여넣기', owner: '최도윤', status: '막힘', done: 20 },
    { id: 6, parentId: 1, name: '결제 연동', owner: '정하은', status: '막힘', done: 20 },
    { id: 7, parentId: null, name: '문서', owner: '강지후', status: '진행', done: 40 },
    { id: 8, parentId: 7, name: '시작 안내', owner: '강지후', status: '완료', done: 100 },
    { id: 9, parentId: 7, name: '예제 모음', owner: '조수빈', status: '진행', done: 25 },
  ],
  rowKey: 'id',
  tree: {
    parentKey: 'parentId',
    column: 'name',
    expandDepth: 'all',
    toggleIcon: 'folder',
    guides: 'solid',
    guideStyle: 'branch',
  },
};
// 상태 목록은 영문 id를 넘겨요. 표의 상태 글자로 바꿔서 걸러요.
const statusById = { progress: '진행', done: '완료', blocked: '막힘' };
export const actions = {
  status: (api, value) => api.setFilterModel(value && statusById[value]
    ? {
      match: 'all',
      items: [{ columnId: 'status', operator: 'equals', value: statusById[value] }],
    }
    : null),
  expandAll: (api) => api.expandAll(),
  collapseAll: (api) => api.collapseAll(),
};

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

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="Status" id="status">
      <option value="all" selected>All</option>
      <option value="progress">In progress</option>
      <option value="done">Done</option>
      <option value="blocked">Blocked</option>
    </select>
    <button type="button" id="expandAll">Expand all</button>
    <button type="button" id="collapseAll">Collapse all</button>
  </div>
  <div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
example.js
// Status badges and progress bars blend their colors over the theme variables, so the text reads in both light and dark themes.
const tones = {
  Done: '#1a7f37',
  'In progress': '#1a56c4',
  Blocked: '#cf222e',
};
const badge = () => {
  let chip;
  return {
    mount(el, ctx) {
      const box = document.createElement('div');
      box.className = 'mxg-cell-center';
      el.append(box);
      chip = document.createElement('span');
      chip.style.cssText =
        'box-sizing:border-box;height:20px;line-height:18px;padding:0 8px;border-radius:10px;font-size:12px;white-space:nowrap;color:var(--mxg-fg)';
      box.append(chip);
      this.update(ctx);
    },
    update(ctx) {
      chip.textContent = ctx.text;
      chip.style.background = `color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 28%, var(--mxg-bg))`;
      chip.style.border = `1px solid color-mix(in srgb, ${tones[ctx.text] ?? '#57606a'} 55%, var(--mxg-bg))`;
    },
    destroy() { },
  };
};
const bar = () => {
  let fill;
  let label;
  return {
    mount(el, ctx) {
      // Replacing the whole style of the cell (el) would erase the position and size values the grid set. Put one box inside and style only that box.
      const box = document.createElement('div');
      box.className = 'mxg-cell-center';
      box.style.gap = '8px';
      el.append(box);
      const track = document.createElement('div');
      // The track mixes in a bit of the text color so it shows on both light and dark backgrounds.
      track.style.cssText =
        'flex:1;height:8px;border-radius:4px;background:color-mix(in srgb, var(--mxg-fg) 22%, var(--mxg-bg));overflow:hidden';
      fill = document.createElement('div');
      fill.style.cssText = 'height:100%;background:var(--mxg-accent)';
      track.append(fill);
      label = document.createElement('span');
      label.style.cssText = 'min-width:34px;text-align:end;font-size:12px;color:var(--mxg-fg)';
      box.append(track, label);
      this.update(ctx);
    },
    update(ctx) {
      const percent = Math.min(100, Math.max(0, Number(ctx.value)));
      fill.style.width = `${percent}%`;
      label.textContent = `${percent}%`;
    },
    destroy() { },
  };
};
// A task tree with folder icons and branch lines (├ └). The badge and bar go on other columns, and the tree column keeps the default cell so the arrow shows.
export const options = {
  columns: [
    { id: 'name', title: 'Task', width: 230 },
    { id: 'owner', title: 'Owner', width: 120 },
    { id: 'status', title: 'Status', width: 110, cellRenderer: badge },
    { id: 'done', title: 'Progress', width: 140, cellRenderer: bar },
  ],
  rows: [
    {
      id: 1,
      parentId: null,
      name: '2.0 Release',
      owner: 'Emma Stone',
      status: 'In progress',
      done: 60,
    },
    { id: 2, parentId: 1, name: 'Data migration', owner: 'Liam Carter', status: 'Done', done: 100 },
    {
      id: 3,
      parentId: 1,
      name: 'New editor',
      owner: 'Mia Parker',
      status: 'In progress',
      done: 55,
    },
    {
      id: 4,
      parentId: 3,
      name: 'Input validation',
      owner: 'Mia Parker',
      status: 'In progress',
      done: 70,
    },
    { id: 5, parentId: 3, name: 'Paste', owner: 'Noah Davis', status: 'Blocked', done: 20 },
    {
      id: 6,
      parentId: 1,
      name: 'Payment integration',
      owner: 'Ava Moore',
      status: 'Blocked',
      done: 20,
    },
    { id: 7, parentId: null, name: 'Docs', owner: 'Jack Reed', status: 'In progress', done: 40 },
    { id: 8, parentId: 7, name: 'Getting started', owner: 'Jack Reed', status: 'Done', done: 100 },
    {
      id: 9,
      parentId: 7,
      name: 'Example gallery',
      owner: 'Lily Brooks',
      status: 'In progress',
      done: 25,
    },
  ],
  rowKey: 'id',
  tree: {
    parentKey: 'parentId',
    column: 'name',
    expandDepth: 'all',
    toggleIcon: 'folder',
    guides: 'solid',
    guideStyle: 'branch',
  },
};
// The status control hands over English ids; map them to the status texts in the table.
const statusById = {
  progress: 'In progress',
  done: 'Done',
  blocked: 'Blocked',
};
export const actions = {
  status: (api, value) => {
    const status = value ? (statusById[value] ?? 'all') : 'all';
    api.setFilterModel(status !== 'all'
      ? { match: 'all', items: [{ columnId: 'status', operator: 'equals', value: status }] }
      : null);
  },
  expandAll: (api) => api.expandAll(),
  collapseAll: (api) => api.collapseAll(),
};