셀 안의 버튼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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div id="grid" style="height: 230px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);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;
};
}<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>셀 안의 버튼</title>
</head>
<body>
<div id="grid" style="height: 230px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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만 불리고 셀 편집이나 선택은 그대로예요. 던져도 그리드는 멈추지 않아요.
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;
function setup(grid, log) {
current = grid;
say = log;
log({
ko: '"처리" 버튼을 눌러 보세요.',
en: 'Press a "Process" button.',
});
return () => {
current = null;
};
}
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ id: 1, task: '견적서 보내기', state: 'open' },
{ id: 2, task: '계약서 검토', state: 'done' },
{ id: 3, task: '납품 일정 확정', state: 'hold' },
{ id: 4, task: '세금계산서 발행', state: 'open' },
];
let say: (message: LogText) => void = () => undefined;
// 버튼은 cellRenderer 'button'이에요. label은 값이나 함수, disabled와 visible은 행 조건을 받아요.
// onClick만 불리고 셀 편집이나 선택은 그대로예요. 던져도 그리드는 멈추지 않아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 170 },
{
id: 'state',
title: '상태',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? '완료됨' : '처리'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `${ctx.row.task} 처리`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say({ ko: `${row.task}: 처리했어요`, en: `${row.task}: processed` });
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log({
ko: '"처리" 버튼을 눌러 보세요.',
en: 'Press a "Process" button.',
});
return () => {
current = null;
};
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<Grid style="height: 230px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ id: 1, task: '견적서 보내기', state: 'open' },
{ id: 2, task: '계약서 검토', state: 'done' },
{ id: 3, task: '납품 일정 확정', state: 'hold' },
{ id: 4, task: '세금계산서 발행', state: 'open' },
];
let say: (message: LogText) => void = () => undefined;
// 버튼은 cellRenderer 'button'이에요. label은 값이나 함수, disabled와 visible은 행 조건을 받아요.
// onClick만 불리고 셀 편집이나 선택은 그대로예요. 던져도 그리드는 멈추지 않아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 170 },
{
id: 'state',
title: '상태',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? '완료됨' : '처리'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `${ctx.row.task} 처리`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say({ ko: `${row.task}: 처리했어요`, en: `${row.task}: processed` });
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log({
ko: '"처리" 버튼을 눌러 보세요.',
en: 'Press a "Process" button.',
});
return () => {
current = null;
};
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 230px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ id: 1, task: '견적서 보내기', state: 'open' },
{ id: 2, task: '계약서 검토', state: 'done' },
{ id: 3, task: '납품 일정 확정', state: 'hold' },
{ id: 4, task: '세금계산서 발행', state: 'open' },
];
let say: (message: LogText) => void = () => undefined;
// 버튼은 cellRenderer 'button'이에요. label은 값이나 함수, disabled와 visible은 행 조건을 받아요.
// onClick만 불리고 셀 편집이나 선택은 그대로예요. 던져도 그리드는 멈추지 않아요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 170 },
{
id: 'state',
title: '상태',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? '완료됨' : '처리'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `${ctx.row.task} 처리`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say({ ko: `${row.task}: 처리했어요`, en: `${row.task}: processed` });
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log({
ko: '"처리" 버튼을 눌러 보세요.',
en: 'Press a "Process" button.',
});
return () => {
current = null;
};
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div id="grid" style="height: 230px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);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;
};
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Buttons inside cells</title>
</head>
<body>
<div id="grid" style="height: 230px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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.
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;
function setup(grid, log) {
current = grid;
say = log;
log('Press a "Process" button.');
return () => {
current = null;
};
}
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ 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: (message: LogText) => void = () => 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: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 200 },
{
id: 'state',
title: 'Status',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? 'Done' : 'Process'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `Process ${ctx.row.task}`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say(`${row.task}: processed`);
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log('Press a "Process" button.');
return () => {
current = null;
};
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<Grid style="height: 230px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ 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: (message: LogText) => void = () => 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: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 200 },
{
id: 'state',
title: 'Status',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? 'Done' : 'Process'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `Process ${ctx.row.task}`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say(`${row.task}: processed`);
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log('Press a "Process" button.');
return () => {
current = null;
};
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 230px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
task: string;
state: 'open' | 'done' | 'hold';
}
const rows: Row[] = [
{ 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: (message: LogText) => void = () => 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: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 200 },
{
id: 'state',
title: 'Status',
width: 120,
cellRenderer: 'button',
cellRendererParams: {
label: (ctx: { row: Row }) => (ctx.row.state === 'done' ? 'Done' : 'Process'),
disabled: (ctx: { row: Row }) => ctx.row.state === 'done',
visible: (ctx: { row: Row }) => ctx.row.state !== 'hold',
ariaLabel: (ctx: { row: Row }) => `Process ${ctx.row.task}`,
onClick: ({ row, rowKey }: { row: Row; rowKey: number | string }) => {
say(`${row.task}: processed`);
current?.updateRows([{ ...row, state: 'done' }]);
void rowKey;
},
},
},
],
rows,
rowKey: 'id',
};
let current: GridApi<Row> | null = null;
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
current = grid;
say = log;
log('Press a "Process" button.');
return () => {
current = null;
};
}