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

셀 안의 버튼Buttons inside cells

cellRenderer 'button'으로 행마다 버튼을 그려요. 라벨은 행에 따라 바뀌고, 조건에 따라 비활성이 되거나 숨고, 누르면 onClick이 불려요. 셀 편집이나 선택은 건드리지 않아요.cellRenderer 'button' draws a button per row. The label follows the row, the button can be disabled or hidden by a condition, and a click calls onClick. It does not touch cell editing or selection.

입문Beginner
직접 써 보기Live preview셀 안의 버튼Buttons inside cells

코드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: 230px"></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, task: '견적서 보내기', state: 'open' },
  { id: 2, task: '계약서 검토', state: 'done' },
  { id: 3, task: '납품 일정 확정', state: 'hold' },
  { id: 4, task: '세금계산서 발행', state: 'open' },
];
let say = () => undefined;
// 버튼은 cellRenderer 'button'이에요. label은 값이나 함수, disabled와 visible은 행 조건을 받아요.
// onClick만 불리고 셀 편집이나 선택은 그대로예요. 던져도 그리드는 멈추지 않아요.
export const options = {
  columns: [
    { id: 'task', title: '작업', width: 170 },
    {
      id: 'state',
      title: '상태',
      width: 120,
      cellRenderer: 'button',
      cellRendererParams: {
        label: (ctx) => (ctx.row.state === 'done' ? '완료됨' : '처리'),
        disabled: (ctx) => ctx.row.state === 'done',
        visible: (ctx) => ctx.row.state !== 'hold',
        ariaLabel: (ctx) => `${ctx.row.task} 처리`,
        onClick: ({ row, rowKey }) => {
          say({ ko: `${row.task}: 처리했어요`, en: `${row.task}: processed` });
          current?.updateRows([{ ...row, state: 'done' }]);
          void rowKey;
        },
      },
    },
  ],
  rows,
  rowKey: 'id',
};
let current = null;
export function setup(grid, log) {
  current = grid;
  say = log;
  log({
    ko: '"처리" 버튼을 눌러 보세요.',
    en: 'Press a "Process" button.',
  });
  return () => {
    current = null;
  };
}

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: 230px"></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, task: 'Send the quote', state: 'open' },
  { id: 2, task: 'Review the contract', state: 'done' },
  { id: 3, task: 'Confirm delivery schedule', state: 'hold' },
  { id: 4, task: 'Issue the invoice', state: 'open' },
];
let say = () => undefined;
// The button is cellRenderer 'button'. label takes a value or a function; disabled and visible take row conditions.
// Only onClick is called; cell editing and selection stay as they are. Throwing does not stop the grid.
export const options = {
  columns: [
    { id: 'task', title: 'Task', width: 200 },
    {
      id: 'state',
      title: 'Status',
      width: 120,
      cellRenderer: 'button',
      cellRendererParams: {
        label: (ctx) => (ctx.row.state === 'done' ? 'Done' : 'Process'),
        disabled: (ctx) => ctx.row.state === 'done',
        visible: (ctx) => ctx.row.state !== 'hold',
        ariaLabel: (ctx) => `Process ${ctx.row.task}`,
        onClick: ({ row, rowKey }) => {
          say(`${row.task}: processed`);
          current?.updateRows([{ ...row, state: 'done' }]);
          void rowKey;
        },
      },
    },
  ],
  rows,
  rowKey: 'id',
};
let current = null;
export function setup(grid, log) {
  current = grid;
  say = log;
  log('Press a "Process" button.');
  return () => {
    current = null;
  };
}