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

진행 막대: 두께·글자 위치·퍼센트Progress bars: thickness, label position, percent

막대 두께와 간격, 글자를 앞·뒤·막대 안에 놓기, 0~1 비율 값, 퍼센트 글자, 구간별 클래스를 옵션만으로 바꿔요.Change bar thickness and gap, put the label before, after or inside the bar, use 0–1 ratios, percent text and per-band classes with options only.

입문Beginner
직접 써 보기Live preview진행 막대: 두께·글자 위치·퍼센트Progress bars: thickness, label position, percent

코드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="position">
      <option value="end" selected>막대 뒤</option>
      <option value="start">막대 앞</option>
      <option value="inside">막대 안</option>
      <option value="none">숨김</option>
    </select>
    <select aria-label="막대 두께" id="thick">
      <option value="8" selected>기본 (8px)</option>
      <option value="16">16px</option>
      <option value="4">4px</option>
    </select>
  </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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));
example.js
const rows = [
  { id: 1, task: '설계', done: 100, ratio: 1 },
  { id: 2, task: '개발', done: 72, ratio: 0.72 },
  { id: 3, task: '시험', done: 35.5, ratio: 0.355 },
  { id: 4, task: '배포', done: 8, ratio: 0.08 },
  { id: 5, task: '문서', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
  { id: 'task', title: '작업', width: 110 },
  {
    id: 'done',
    title: '진행률',
    width: 260,
    cellRenderer: 'progress',
    cellRendererParams: {
      height,
      labelPosition: position,
      ranges: [
        { upTo: 30, tone: 'danger', className: 'band-low' },
        { upTo: 70, tone: 'warning' },
        { upTo: 100, tone: 'success' },
      ],
    },
  },
  {
    id: 'ratio',
    title: '비율 (0~1)',
    width: 240,
    cellRenderer: 'progress',
    cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
  },
];
export const options = {
  columns: columns(),
  rows,
  rowKey: 'id',
  saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  position = 'end';
  height = 8;
  log({
    ko: '두 번째 열은 0~1 값을 퍼센트 글자(소수 1자리)로 보여요.',
    en: 'The second column shows 0–1 values as percent text with one decimal.',
  });
}
export const actions = {
  position: (api, value) => {
    position = (value ?? 'end');
    api.setColumns(columns());
    say({ ko: `글자 위치: ${position}`, en: `Label position: ${position}` });
  },
  thick: (api, value) => {
    height = Number(value ?? 8);
    api.setColumns(columns());
    say({ ko: `막대 두께: ${height}px`, en: `Bar thickness: ${height}px` });
  },
};

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="Label position" id="position">
      <option value="end" selected>After the bar</option>
      <option value="start">Before the bar</option>
      <option value="inside">Inside the bar</option>
      <option value="none">Hidden</option>
    </select>
    <select aria-label="Bar thickness" id="thick">
      <option value="8" selected>Default (8px)</option>
      <option value="16">16px</option>
      <option value="4">4px</option>
    </select>
  </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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('thick').addEventListener('change', (event) => actions.thick(api, event.target.value));
example.js
const rows = [
  { id: 1, task: 'Design', done: 100, ratio: 1 },
  { id: 2, task: 'Development', done: 72, ratio: 0.72 },
  { id: 3, task: 'Testing', done: 35.5, ratio: 0.355 },
  { id: 4, task: 'Deployment', done: 8, ratio: 0.08 },
  { id: 5, task: 'Docs', done: 0, ratio: 0 },
];
let position = 'end';
let height = 8;
const columns = () => [
  { id: 'task', title: 'Task', width: 120 },
  {
    id: 'done',
    title: 'Progress',
    width: 260,
    cellRenderer: 'progress',
    cellRendererParams: {
      height,
      labelPosition: position,
      ranges: [
        { upTo: 30, tone: 'danger', className: 'band-low' },
        { upTo: 70, tone: 'warning' },
        { upTo: 100, tone: 'success' },
      ],
    },
  },
  {
    id: 'ratio',
    title: 'Ratio (0-1)',
    width: 240,
    cellRenderer: 'progress',
    cellRendererParams: { scale: 'ratio', label: 'percent', precision: 1, height, gap: 12 },
  },
];
export const options = {
  columns: columns(),
  rows,
  rowKey: 'id',
  saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  position = 'end';
  height = 8;
  log('The second column shows 0–1 values as percent text with one decimal.');
}
export const actions = {
  position: (api, value) => {
    position = (value ?? 'end');
    api.setColumns(columns());
    say(`Label position: ${position}`);
  },
  thick: (api, value) => {
    height = Number(value ?? 8);
    api.setColumns(columns());
    say(`Bar thickness: ${height}px`);
  },
};