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

진행 막대: 범위와 구간별 색Progress bars: range and colors by band

숫자를 막대로 보여 줘요. 범위를 정하고, 값 구간에 따라 초록·노랑·빨강으로 바뀌게 하고, 막대만 보일지 숫자도 함께 보일지 고를 수 있어요.Show numbers as bars. Set the range, change green/yellow/red by band, and choose bar only or bar with number.

입문Beginner
직접 써 보기Live preview진행 막대: 범위와 구간별 색Progress bars: range and colors by band

코드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="text">
      <option value="both" selected>막대와 숫자</option>
      <option value="bar">막대만</option>
    </select>
    <button type="button" id="more">진행률 +10%</button>
  </div>
  <div id="grid" style="height: 300px"></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('text').addEventListener('change', (event) => actions.text(api, event.target.value));
document.getElementById('more').addEventListener('click', () => actions.more(api));
example.js
// 내장 진행 막대에는 화면 읽기 프로그램용 이름이 없어서, 줄의 첫 칸 글자를 붙여 이름을 달아 줘요.
function nameBars(label, cell = 0) {
  const root = document.getElementById('grid');
  if (!root)
    return () => undefined;
  const apply = () => {
    for (const bar of root.querySelectorAll('[role="progressbar"]')) {
      if (bar.getAttribute('aria-label'))
        continue;
      const row = bar.closest('[role="row"]');
      const cells = [...(row?.querySelectorAll('[role="gridcell"]:not(.mxg-checkcell)') ?? [])];
      const mine = bar.closest('[role="gridcell"]');
      const headers = root.querySelectorAll('[role="columnheader"]');
      const header = headers[cells.indexOf(mine)]?.textContent?.trim();
      bar.setAttribute('aria-label', `${cells[cell]?.textContent?.trim() ?? ''} ${header || label}`.trim());
    }
  };
  const observer = new MutationObserver(apply);
  observer.observe(root, { childList: true, subtree: true });
  apply();
  return () => observer.disconnect();
}
// cellRenderer: 'progress'는 숫자를 막대로 그려요. 기본 범위는 0~100이고 범위를 벗어난 값은 끝에 맞춰요.
// 숫자가 아니면 막대가 비어 있어요. min·max로 범위를, ranges로 구간별 색을, showText로 숫자 표시를 정해요.
const rows = [
  { id: 1, task: '디자인 검토', owner: '김서연', done: 100, load: 3, quota: 20 },
  { id: 2, task: '빌드 자동화', owner: '이준호', done: 72, load: 7, quota: 55 },
  { id: 3, task: '부하 시험', owner: '박민지', done: 35, load: 9.5, quota: 90 },
  { id: 4, task: '문서 작성', owner: '김서연', done: 0, load: 1, quota: 8 },
  { id: 5, task: '보고 과다 입력', owner: '이준호', done: 130, load: 5, quota: 45 },
  { id: 6, task: '아직 시작 전', owner: '박민지', done: null, load: 2, quota: 12 },
];
let showText = true;
const columns = () => [
  { id: 'task', title: '업무', width: 130 },
  {
    id: 'done',
    title: '진행률',
    kind: 'number',
    width: 170,
    formatValue: (value) => (typeof value === 'number' ? `${String(value)}%` : '해당 없음'),
    cellRenderer: 'progress',
    cellRendererParams: { showText },
  },
  {
    id: 'load',
    title: '서버 부하(0~10)',
    kind: 'number',
    width: 190,
    formatValue: (value) => `${String(value)} / 10`,
    cellRenderer: 'progress',
    cellRendererParams: {
      min: 0,
      max: 10,
      showText,
      ranges: [
        { upTo: 60, tone: 'success' },
        { upTo: 85, tone: 'warning' },
        { upTo: 100, tone: 'danger' },
      ],
    },
  },
];
export const options = {
  columns: columns(),
  rows,
  rowKey: 'id',
  saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  showText = true;
  const stop = nameBars('진행');
  log({
    ko: '130%처럼 범위를 넘은 값은 막대가 100%에서 멈추고, 비어 있는 값은 막대가 비어 있어요.',
    en: 'A value over the range like 130% stops the bar at 100%, and an empty value leaves the bar empty.',
  });
  return stop;
}
export const actions = {
  text: (api, value) => {
    showText = value !== 'bar';
    api.setColumns(columns());
    say({
      ko: showText ? '막대에 숫자도 함께 보여요.' : '막대만 보여요.',
      en: showText ? 'Showing numbers on the bar too.' : 'Showing only the bar.',
    });
  },
  more: (api) => {
    const changed = api
      .getRows()
      .flatMap((row) => typeof row.done === 'number' && row.done < 100
      ? [{ ...row, done: Math.min(100, row.done + 10) }]
      : []);
    api.updateRows(changed);
    say({
      ko: `진행률이 100% 미만인 ${changed.length}줄을 10%씩 올렸어요.`,
      en: `Raised the ${changed.length} rows under 100% progress by 10%.`,
    });
  },
};

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="Bar display" id="text">
      <option value="both" selected>Bar and number</option>
      <option value="bar">Bar only</option>
    </select>
    <button type="button" id="more">Progress +10%</button>
  </div>
  <div id="grid" style="height: 300px"></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('text').addEventListener('change', (event) => actions.text(api, event.target.value));
document.getElementById('more').addEventListener('click', () => actions.more(api));
example.js
// The built-in progress bar has no name for screen readers, so this adds one using the text of the row's first cell.
function nameBars(label, cell = 0) {
  const root = document.getElementById('grid');
  if (!root)
    return () => undefined;
  const apply = () => {
    for (const bar of root.querySelectorAll('[role="progressbar"]')) {
      if (bar.getAttribute('aria-label'))
        continue;
      const row = bar.closest('[role="row"]');
      const cells = [...(row?.querySelectorAll('[role="gridcell"]:not(.mxg-checkcell)') ?? [])];
      const mine = bar.closest('[role="gridcell"]');
      const headers = root.querySelectorAll('[role="columnheader"]');
      const header = headers[cells.indexOf(mine)]?.textContent?.trim();
      bar.setAttribute('aria-label', `${cells[cell]?.textContent?.trim() ?? ''} ${header || label}`.trim());
    }
  };
  const observer = new MutationObserver(apply);
  observer.observe(root, { childList: true, subtree: true });
  apply();
  return () => observer.disconnect();
}
// cellRenderer: 'progress' draws a number as a bar. The default range is 0-100 and out-of-range values are clamped to the ends.
// A non-number leaves the bar empty. min/max set the range, ranges set colors per band, and showText controls the number display.
const rows = [
  { id: 1, task: 'Design review', owner: 'Olivia Reed', done: 100, load: 3, quota: 20 },
  { id: 2, task: 'Build automation', owner: 'Liam Carter', done: 72, load: 7, quota: 55 },
  { id: 3, task: 'Load test', owner: 'Emma Stone', done: 35, load: 9.5, quota: 90 },
  { id: 4, task: 'Write docs', owner: 'Olivia Reed', done: 0, load: 1, quota: 8 },
  { id: 5, task: 'Over-reported entry', owner: 'Liam Carter', done: 130, load: 5, quota: 45 },
  { id: 6, task: 'Not started yet', owner: 'Emma Stone', done: null, load: 2, quota: 12 },
];
let showText = true;
const columns = () => [
  { id: 'task', title: 'Task', width: 150 },
  {
    id: 'done',
    title: 'Progress',
    kind: 'number',
    width: 170,
    formatValue: (value) => (typeof value === 'number' ? `${String(value)}%` : 'N/A'),
    cellRenderer: 'progress',
    cellRendererParams: { showText },
  },
  {
    id: 'load',
    title: 'Server load (0-10)',
    kind: 'number',
    width: 190,
    formatValue: (value) => `${String(value)} / 10`,
    cellRenderer: 'progress',
    cellRendererParams: {
      min: 0,
      max: 10,
      showText,
      ranges: [
        { upTo: 60, tone: 'success' },
        { upTo: 85, tone: 'warning' },
        { upTo: 100, tone: 'danger' },
      ],
    },
  },
];
export const options = {
  columns: columns(),
  rows,
  rowKey: 'id',
  saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  showText = true;
  const stop = nameBars('Progress');
  log('A value over the range like 130% stops the bar at 100%, and an empty value leaves the bar empty.');
  return stop;
}
export const actions = {
  text: (api, value) => {
    showText = value !== 'bar';
    api.setColumns(columns());
    say(showText ? 'Showing numbers on the bar too.' : 'Showing only the bar.');
  },
  more: (api) => {
    const changed = api
      .getRows()
      .flatMap((row) => typeof row.done === 'number' && row.done < 100
      ? [{ ...row, done: Math.min(100, row.done + 10) }]
      : []);
    api.updateRows(changed);
    say(`Raised the ${changed.length} rows under 100% progress by 10%.`);
  },
};