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

버튼으로 숫자 올리고 내리기Raise and lower numbers with buttons

cellEditor 'stepper'는 숫자 칸에 올리기·내리기 버튼을 붙여요. step, min, max, repeat, layout, typing 옵션으로 걸음 크기, 범위, 누르고 있을 때의 반복, 버튼 모양, 직접 입력 여부를 정해요. 범위 밖 숫자를 직접 치면 고치지 않고 확정할 때 이유를 알려 줘요.cellEditor 'stepper' adds increase and decrease buttons to a number cell. The step, min, max, repeat, layout and typing options set the step size, the range, the repeat while held, the button layout and whether typing is allowed. A typed number outside the range is not corrected; the commit explains why it is refused.

입문Beginner
직접 써 보기Live preview버튼으로 숫자 올리고 내리기Raise and lower numbers with buttons

코드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 id="grid" style="height: 280px"></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
const rows = [
  { id: 1, item: '노트북 거치대', qty: 3, discount: 10, price: 24.5 },
  { id: 2, item: '무선 마우스', qty: 12, discount: 0, price: 18 },
  { id: 3, item: '모니터 암', qty: null, discount: 25, price: 52.9 },
  { id: 4, item: 'USB 허브', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// editorParams: step(걸음 크기), min·max(범위), repeat(누르고 있을 때 반복 ms), layout('sides' | 'stacked'),
// typing(false면 버튼과 키로만 바꿈), decimals(결과 소수 자릿수).
export const options = {
  columns: [
    { id: 'item', title: '품목', width: 150 },
    {
      id: 'qty',
      title: '수량',
      kind: 'number',
      width: 150,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 1, min: 0, max: 99 },
    },
    {
      id: 'discount',
      title: '할인율(%)',
      kind: 'number',
      width: 140,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
    },
    {
      id: 'price',
      title: '단가',
      kind: 'number',
      width: 140,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: '"수량"·"할인율"·"단가" 칸을 두 번 누르세요. − + 버튼이나 위아래 키로 바꿔요.',
    en: 'Double-click a "수량" (qty), "할인율" (discount) or "단가" (price) cell. Change it with the − + buttons or the up and down keys.',
  });
  const offs = [
    api.on('editCommitted', (e) => log({
      ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
      en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
    })),
    api.on('validationFailed', (e) => log(e.message)),
  ];
  return () => offs.forEach((off) => off());
}

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 id="grid" style="height: 280px"></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
const rows = [
  { id: 1, item: 'Laptop stand', qty: 3, discount: 10, price: 24.5 },
  { id: 2, item: 'Wireless mouse', qty: 12, discount: 0, price: 18 },
  { id: 3, item: 'Monitor arm', qty: null, discount: 25, price: 52.9 },
  { id: 4, item: 'USB hub', qty: 99, discount: 5, price: 12.3 },
];
// cellEditor: 'stepper' needs the editors bundle (the full bundle includes it).
// editorParams: step (step size), min and max (range), repeat (repeat interval in ms while held), layout ('sides' | 'stacked'),
// typing (false changes only with buttons and keys), decimals (decimal places of the result).
export const options = {
  columns: [
    { id: 'item', title: 'Item', width: 150 },
    {
      id: 'qty',
      title: 'Qty',
      kind: 'number',
      width: 150,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 1, min: 0, max: 99 },
    },
    {
      id: 'discount',
      title: 'Discount (%)',
      kind: 'number',
      width: 140,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 5, min: 0, max: 50, layout: 'stacked', typing: false },
    },
    {
      id: 'price',
      title: 'Unit price',
      kind: 'number',
      width: 140,
      editable: true,
      cellEditor: 'stepper',
      editorParams: { step: 0.1, min: 0, decimals: 1, repeat: 120 },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log('Double-click a "Qty", "Discount" or "Unit price" cell. Change it with the − + buttons or the up and down keys.');
  const offs = [
    api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
    api.on('validationFailed', (e) => log(e.message)),
  ];
  return () => offs.forEach((off) => off());
}