스위치로 켜고 끄기Turn things on and off with a switch
cellRenderer 'switch'는 셀 안에 누르는 스위치를 그려요. 눌러서 바꾼 값은 일반 편집처럼 검증, 되돌리기, 변경 추적을 거쳐요. 편집할 수 없는 행은 비활성이고, canToggle로 바꾸지 못하게 막을 수도 있어요.cellRenderer 'switch' draws a switch you can press in the cell. The value you change goes through validation, undo and change tracking like any edit. Rows that are not editable are disabled, and canToggle can refuse a change.
코드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 class="toolbar">
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const rows = [
{ id: 1, name: '알림 메일', active: true, required: false, locked: false },
{ id: 2, name: '보안 로그', active: true, required: true, locked: false },
{ id: 3, name: '정기 백업', active: false, required: false, locked: false },
{ id: 4, name: '관리자 계정', active: true, required: false, locked: true },
];
// switch 렌더러는 값을 그대로(true/false) 쓰고, 누르면 일반 편집 확정 경로로 값이 바뀌어요.
// editable이 행 조건을 받으면 잠긴 행은 비활성으로 그려져요. canToggle이 false를 돌려주면 값은 그대로예요.
export const options = {
columns: [
{ id: 'name', title: '기능', width: 150 },
{
id: 'active',
title: '사용',
kind: 'boolean',
width: 110,
editable: (row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: '사용',
canToggle: ({ row, next }) => !(row.required && next === false),
},
},
{ id: 'required', title: '필수', kind: 'boolean', width: 80 },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
export function setup(api, log) {
say = log;
const off = api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}));
return off;
}
export const actions = {
undo: (api) => {
if (!api.canUndo())
say({ ko: '되돌릴 것이 없어요.', en: 'Nothing to undo.' });
else
api.undo();
},
};<!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 class="toolbar">
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 250px"></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, name: '알림 메일', active: true, required: false, locked: false },
{ id: 2, name: '보안 로그', active: true, required: true, locked: false },
{ id: 3, name: '정기 백업', active: false, required: false, locked: false },
{ id: 4, name: '관리자 계정', active: true, required: false, locked: true },
];
// switch 렌더러는 값을 그대로(true/false) 쓰고, 누르면 일반 편집 확정 경로로 값이 바뀌어요.
// editable이 행 조건을 받으면 잠긴 행은 비활성으로 그려져요. canToggle이 false를 돌려주면 값은 그대로예요.
const options = {
columns: [
{ id: 'name', title: '기능', width: 150 },
{
id: 'active',
title: '사용',
kind: 'boolean',
width: 110,
editable: (row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: '사용',
canToggle: ({ row, next }) => !(row.required && next === false),
},
},
{ id: 'required', title: '필수', kind: 'boolean', width: 80 },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
function setup(api, log) {
say = log;
const off = api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}));
return off;
}
const actions = {
undo: (api) => {
if (!api.canUndo())
say({ ko: '되돌릴 것이 없어요.', en: 'Nothing to undo.' });
else
api.undo();
},
};
options.ariaLabel = "스위치로 켜고 끄기";
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);
});
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 250 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: '알림 메일', active: true, required: false, locked: false },
{ id: 2, name: '보안 로그', active: true, required: true, locked: false },
{ id: 3, name: '정기 백업', active: false, required: false, locked: false },
{ id: 4, name: '관리자 계정', active: true, required: false, locked: true },
];
// switch 렌더러는 값을 그대로(true/false) 쓰고, 누르면 일반 편집 확정 경로로 값이 바뀌어요.
// editable이 행 조건을 받으면 잠긴 행은 비활성으로 그려져요. canToggle이 false를 돌려주면 값은 그대로예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '기능', width: 150 },
{
id: 'active',
title: '사용',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: '사용',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: '필수', kind: 'boolean', width: 80 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say({ ko: '되돌릴 것이 없어요.', en: 'Nothing to undo.' });
else api.undo();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, 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>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.undo(api)">되돌리기</button>
</div>
<Grid style="height: 250px" :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;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: '알림 메일', active: true, required: false, locked: false },
{ id: 2, name: '보안 로그', active: true, required: true, locked: false },
{ id: 3, name: '정기 백업', active: false, required: false, locked: false },
{ id: 4, name: '관리자 계정', active: true, required: false, locked: true },
];
// switch 렌더러는 값을 그대로(true/false) 쓰고, 누르면 일반 편집 확정 경로로 값이 바뀌어요.
// editable이 행 조건을 받으면 잠긴 행은 비활성으로 그려져요. canToggle이 false를 돌려주면 값은 그대로예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '기능', width: 150 },
{
id: 'active',
title: '사용',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: '사용',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: '필수', kind: 'boolean', width: 80 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say({ ko: '되돌릴 것이 없어요.', en: 'Nothing to undo.' });
else api.undo();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 250px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
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;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: '알림 메일', active: true, required: false, locked: false },
{ id: 2, name: '보안 로그', active: true, required: true, locked: false },
{ id: 3, name: '정기 백업', active: false, required: false, locked: false },
{ id: 4, name: '관리자 계정', active: true, required: false, locked: true },
];
// switch 렌더러는 값을 그대로(true/false) 쓰고, 누르면 일반 편집 확정 경로로 값이 바뀌어요.
// editable이 행 조건을 받으면 잠긴 행은 비활성으로 그려져요. canToggle이 false를 돌려주면 값은 그대로예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '기능', width: 150 },
{
id: 'active',
title: '사용',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: '사용',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: '필수', kind: 'boolean', width: 80 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say({ ko: '되돌릴 것이 없어요.', en: 'Nothing to undo.' });
else api.undo();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const rows = [
{ id: 1, name: 'Notification mail', active: true, required: false, locked: false },
{ id: 2, name: 'Security log', active: true, required: true, locked: false },
{ id: 3, name: 'Scheduled backup', active: false, required: false, locked: false },
{ id: 4, name: 'Admin account', active: true, required: false, locked: true },
];
// The switch renderer uses the value as is (true/false), and pressing it changes the value through the normal edit-commit path.
// When editable takes a row condition, locked rows are drawn disabled. If canToggle returns false, the value stays.
export const options = {
columns: [
{ id: 'name', title: 'Feature', width: 170 },
{
id: 'active',
title: 'Enabled',
kind: 'boolean',
width: 110,
editable: (row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: 'Enabled',
canToggle: ({ row, next }) => !(row.required && next === false),
},
},
{ id: 'required', title: 'Required', kind: 'boolean', width: 90 },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
export function setup(api, log) {
say = log;
const off = api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`));
return off;
}
export const actions = {
undo: (api) => {
if (!api.canUndo())
say('Nothing to undo.');
else
api.undo();
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Turn things on and off with a switch</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 250px"></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, name: 'Notification mail', active: true, required: false, locked: false },
{ id: 2, name: 'Security log', active: true, required: true, locked: false },
{ id: 3, name: 'Scheduled backup', active: false, required: false, locked: false },
{ id: 4, name: 'Admin account', active: true, required: false, locked: true },
];
// The switch renderer uses the value as is (true/false), and pressing it changes the value through the normal edit-commit path.
// When editable takes a row condition, locked rows are drawn disabled. If canToggle returns false, the value stays.
const options = {
columns: [
{ id: 'name', title: 'Feature', width: 170 },
{
id: 'active',
title: 'Enabled',
kind: 'boolean',
width: 110,
editable: (row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: 'Enabled',
canToggle: ({ row, next }) => !(row.required && next === false),
},
},
{ id: 'required', title: 'Required', kind: 'boolean', width: 90 },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
function setup(api, log) {
say = log;
const off = api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`));
return off;
}
const actions = {
undo: (api) => {
if (!api.canUndo())
say('Nothing to undo.');
else
api.undo();
},
};
options.ariaLabel = "Turn things on and off with a switch";
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);
});
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
</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 { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>Undo</button>
</div>
<Grid style={{ height: 250 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: 'Notification mail', active: true, required: false, locked: false },
{ id: 2, name: 'Security log', active: true, required: true, locked: false },
{ id: 3, name: 'Scheduled backup', active: false, required: false, locked: false },
{ id: 4, name: 'Admin account', active: true, required: false, locked: true },
];
// The switch renderer uses the value as is (true/false), and pressing it changes the value through the normal edit-commit path.
// When editable takes a row condition, locked rows are drawn disabled. If canToggle returns false, the value stays.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Feature', width: 170 },
{
id: 'active',
title: 'Enabled',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: 'Enabled',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: 'Required', kind: 'boolean', width: 90 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say('Nothing to undo.');
else api.undo();
},
};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 { actions, 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>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.undo(api)">Undo</button>
</div>
<Grid style="height: 250px" :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;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: 'Notification mail', active: true, required: false, locked: false },
{ id: 2, name: 'Security log', active: true, required: true, locked: false },
{ id: 3, name: 'Scheduled backup', active: false, required: false, locked: false },
{ id: 4, name: 'Admin account', active: true, required: false, locked: true },
];
// The switch renderer uses the value as is (true/false), and pressing it changes the value through the normal edit-commit path.
// When editable takes a row condition, locked rows are drawn disabled. If canToggle returns false, the value stays.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Feature', width: 170 },
{
id: 'active',
title: 'Enabled',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: 'Enabled',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: 'Required', kind: 'boolean', width: 90 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say('Nothing to undo.');
else api.undo();
},
};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 { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>Undo</button>
</div>
<mx-grid style="height: 250px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
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;
name: string;
active: boolean;
required: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, name: 'Notification mail', active: true, required: false, locked: false },
{ id: 2, name: 'Security log', active: true, required: true, locked: false },
{ id: 3, name: 'Scheduled backup', active: false, required: false, locked: false },
{ id: 4, name: 'Admin account', active: true, required: false, locked: true },
];
// The switch renderer uses the value as is (true/false), and pressing it changes the value through the normal edit-commit path.
// When editable takes a row condition, locked rows are drawn disabled. If canToggle returns false, the value stays.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Feature', width: 170 },
{
id: 'active',
title: 'Enabled',
kind: 'boolean',
width: 110,
editable: (row: Row) => !row.locked,
cellRenderer: 'switch',
cellRendererParams: {
label: 'Enabled',
canToggle: ({ row, next }: { row: Row; next: unknown }) =>
!(row.required && next === false),
},
},
{ id: 'required', title: 'Required', kind: 'boolean', width: 90 },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`),
);
return off;
}
export const actions = {
undo: (api: GridApi<Row>) => {
if (!api.canUndo()) say('Nothing to undo.');
else api.undo();
},
};