칸 끝의 편집 시작 버튼An edit start button at the end of a cell
컬럼의 editButton은 칸 끝에 작은 연필 버튼을 달아 터치에서도 편집을 열게 해요. 'selected'는 고른 칸에만, 'hover'는 포인터가 올라간 칸에, 'always'는 편집할 수 있는 모든 칸에 보여요.A column's editButton puts a small pencil button at the end of a cell so touch users can open the editor too. 'selected' shows it in the chosen cell, 'hover' under the pointer, and 'always' in every editable cell.
코드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">
<select aria-label="보이는 때" id="mode">
<option value="selected" selected>고른 칸</option>
<option value="hover">포인터를 올린 칸</option>
<option value="always">항상</option>
</select>
</div>
<div id="grid" style="height: 200px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));const rows = [
{ id: 1, task: '디자인 검수', memo: '아이콘 간격 확인', done: false, locked: false },
{ id: 2, task: '문서 정리', memo: '', done: true, locked: false },
{ id: 3, task: '결산(잠김)', memo: '수정 불가', done: false, locked: true },
{ id: 4, task: '배포 점검', memo: '체크리스트 3번', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. 편집할 수 있는 칸에만 보이고 누르면 F2처럼 편집이 열려요(trigger는 'button').
// 체크박스·스위치·버튼·링크 칸에는 달리지 않아요(자기 클릭 대상이 있어서요).
const columns = (mode) => [
{ id: 'task', title: '할 일', width: 150, editable: (row) => !row.locked, editButton: mode },
{ id: 'memo', title: '메모', width: 220, editable: (row) => !row.locked, editButton: mode },
{
id: 'done',
title: '완료',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api, value) => api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api, log) {
log({
ko: '칸을 고르거나(또는 포인터를 올리면) 끝에 연필이 보여요. 눌러서 편집을 열어 보세요.',
en: 'Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.',
});
const off = api.on('editStarted', (e) => log({
ko: `편집 시작: 행 ${e.rowKey} · ${e.columnId} (${e.trigger})`,
en: `Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`,
}));
return () => off();
}<!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">
<select aria-label="보이는 때" id="mode">
<option value="selected" selected>고른 칸</option>
<option value="hover">포인터를 올린 칸</option>
<option value="always">항상</option>
</select>
</div>
<div id="grid" style="height: 200px"></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: '디자인 검수', memo: '아이콘 간격 확인', done: false, locked: false },
{ id: 2, task: '문서 정리', memo: '', done: true, locked: false },
{ id: 3, task: '결산(잠김)', memo: '수정 불가', done: false, locked: true },
{ id: 4, task: '배포 점검', memo: '체크리스트 3번', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. 편집할 수 있는 칸에만 보이고 누르면 F2처럼 편집이 열려요(trigger는 'button').
// 체크박스·스위치·버튼·링크 칸에는 달리지 않아요(자기 클릭 대상이 있어서요).
const columns = (mode) => [
{ id: 'task', title: '할 일', width: 150, editable: (row) => !row.locked, editButton: mode },
{ id: 'memo', title: '메모', width: 220, editable: (row) => !row.locked, editButton: mode },
{
id: 'done',
title: '완료',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
const options = { columns: columns('selected'), rows, rowKey: 'id' };
const actions = {
mode: (api, value) => api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
function setup(api, log) {
log({
ko: '칸을 고르거나(또는 포인터를 올리면) 끝에 연필이 보여요. 눌러서 편집을 열어 보세요.',
en: 'Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.',
});
const off = api.on('editStarted', (e) => log({
ko: `편집 시작: 행 ${e.rowKey} · ${e.columnId} (${e.trigger})`,
en: `Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`,
}));
return () => off();
}
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
</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">
<select
aria-label="보이는 때"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="selected">고른 칸</option>
<option value="hover">포인터를 올린 칸</option>
<option value="always">항상</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: '디자인 검수', memo: '아이콘 간격 확인', done: false, locked: false },
{ id: 2, task: '문서 정리', memo: '', done: true, locked: false },
{ id: 3, task: '결산(잠김)', memo: '수정 불가', done: false, locked: true },
{ id: 4, task: '배포 점검', memo: '체크리스트 3번', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. 편집할 수 있는 칸에만 보이고 누르면 F2처럼 편집이 열려요(trigger는 'button').
// 체크박스·스위치·버튼·링크 칸에는 달리지 않아요(자기 클릭 대상이 있어서요).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: '할 일', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: '메모', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: '완료',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '칸을 고르거나(또는 포인터를 올리면) 끝에 연필이 보여요. 눌러서 편집을 열어 보세요.',
en: 'Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.',
});
const off = api.on('editStarted', (e) =>
log({
ko: `편집 시작: 행 ${e.rowKey} · ${e.columnId} (${e.trigger})`,
en: `Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`,
}),
);
return () => off();
}버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="보이는 때"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="selected" selected>고른 칸</option>
<option value="hover">포인터를 올린 칸</option>
<option value="always">항상</option>
</select>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: '디자인 검수', memo: '아이콘 간격 확인', done: false, locked: false },
{ id: 2, task: '문서 정리', memo: '', done: true, locked: false },
{ id: 3, task: '결산(잠김)', memo: '수정 불가', done: false, locked: true },
{ id: 4, task: '배포 점검', memo: '체크리스트 3번', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. 편집할 수 있는 칸에만 보이고 누르면 F2처럼 편집이 열려요(trigger는 'button').
// 체크박스·스위치·버튼·링크 칸에는 달리지 않아요(자기 클릭 대상이 있어서요).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: '할 일', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: '메모', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: '완료',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '칸을 고르거나(또는 포인터를 올리면) 끝에 연필이 보여요. 눌러서 편집을 열어 보세요.',
en: 'Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.',
});
const off = api.on('editStarted', (e) =>
log({
ko: `편집 시작: 행 ${e.rowKey} · ${e.columnId} (${e.trigger})`,
en: `Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`,
}),
);
return () => off();
}버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="보이는 때"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="selected" selected>고른 칸</option>
<option value="hover">포인터를 올린 칸</option>
<option value="always">항상</option>
</select>
</div>
<mx-grid style="height: 200px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: '디자인 검수', memo: '아이콘 간격 확인', done: false, locked: false },
{ id: 2, task: '문서 정리', memo: '', done: true, locked: false },
{ id: 3, task: '결산(잠김)', memo: '수정 불가', done: false, locked: true },
{ id: 4, task: '배포 점검', memo: '체크리스트 3번', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. 편집할 수 있는 칸에만 보이고 누르면 F2처럼 편집이 열려요(trigger는 'button').
// 체크박스·스위치·버튼·링크 칸에는 달리지 않아요(자기 클릭 대상이 있어서요).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: '할 일', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: '메모', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: '완료',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '칸을 고르거나(또는 포인터를 올리면) 끝에 연필이 보여요. 눌러서 편집을 열어 보세요.',
en: 'Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.',
});
const off = api.on('editStarted', (e) =>
log({
ko: `편집 시작: 행 ${e.rowKey} · ${e.columnId} (${e.trigger})`,
en: `Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`,
}),
);
return () => off();
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="When shown" id="mode">
<option value="selected" selected>Chosen cell</option>
<option value="hover">Hovered cell</option>
<option value="always">Always</option>
</select>
</div>
<div id="grid" style="height: 200px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));const rows = [
{ id: 1, task: 'Design review', memo: 'Check icon spacing', done: false, locked: false },
{ id: 2, task: 'Tidy up docs', memo: '', done: true, locked: false },
{ id: 3, task: 'Month-end close (locked)', memo: 'Read-only', done: false, locked: true },
{ id: 4, task: 'Release check', memo: 'Checklist item 3', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. It shows only on editable cells, and pressing it opens the editor like F2 (the trigger is 'button').
// It is not added to checkbox, switch, button or link cells (they have their own click target).
const columns = (mode) => [
{ id: 'task', title: 'Task', width: 150, editable: (row) => !row.locked, editButton: mode },
{ id: 'memo', title: 'Memo', width: 220, editable: (row) => !row.locked, editButton: mode },
{
id: 'done',
title: 'Done',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api, value) => api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api, log) {
log('Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.');
const off = api.on('editStarted', (e) => log(`Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`));
return () => off();
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>An edit start button at the end of a cell</title>
</head>
<body>
<div class="toolbar">
<select aria-label="When shown" id="mode">
<option value="selected" selected>Chosen cell</option>
<option value="hover">Hovered cell</option>
<option value="always">Always</option>
</select>
</div>
<div id="grid" style="height: 200px"></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: 'Design review', memo: 'Check icon spacing', done: false, locked: false },
{ id: 2, task: 'Tidy up docs', memo: '', done: true, locked: false },
{ id: 3, task: 'Month-end close (locked)', memo: 'Read-only', done: false, locked: true },
{ id: 4, task: 'Release check', memo: 'Checklist item 3', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. It shows only on editable cells, and pressing it opens the editor like F2 (the trigger is 'button').
// It is not added to checkbox, switch, button or link cells (they have their own click target).
const columns = (mode) => [
{ id: 'task', title: 'Task', width: 150, editable: (row) => !row.locked, editButton: mode },
{ id: 'memo', title: 'Memo', width: 220, editable: (row) => !row.locked, editButton: mode },
{
id: 'done',
title: 'Done',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
const options = { columns: columns('selected'), rows, rowKey: 'id' };
const actions = {
mode: (api, value) => api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
function setup(api, log) {
log('Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.');
const off = api.on('editStarted', (e) => log(`Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`));
return () => off();
}
options.ariaLabel = "An edit start button at the end of a cell";
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
</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">
<select
aria-label="When shown"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="selected">Chosen cell</option>
<option value="hover">Hovered cell</option>
<option value="always">Always</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Design review', memo: 'Check icon spacing', done: false, locked: false },
{ id: 2, task: 'Tidy up docs', memo: '', done: true, locked: false },
{ id: 3, task: 'Month-end close (locked)', memo: 'Read-only', done: false, locked: true },
{ id: 4, task: 'Release check', memo: 'Checklist item 3', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. It shows only on editable cells, and pressing it opens the editor like F2 (the trigger is 'button').
// It is not added to checkbox, switch, button or link cells (they have their own click target).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: 'Memo', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: 'Done',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.');
const off = api.on('editStarted', (e) =>
log(`Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`),
);
return () => off();
}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">
<select
aria-label="When shown"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="selected" selected>Chosen cell</option>
<option value="hover">Hovered cell</option>
<option value="always">Always</option>
</select>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Design review', memo: 'Check icon spacing', done: false, locked: false },
{ id: 2, task: 'Tidy up docs', memo: '', done: true, locked: false },
{ id: 3, task: 'Month-end close (locked)', memo: 'Read-only', done: false, locked: true },
{ id: 4, task: 'Release check', memo: 'Checklist item 3', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. It shows only on editable cells, and pressing it opens the editor like F2 (the trigger is 'button').
// It is not added to checkbox, switch, button or link cells (they have their own click target).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: 'Memo', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: 'Done',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.');
const off = api.on('editStarted', (e) =>
log(`Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`),
);
return () => off();
}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">
<select
aria-label="When shown"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="selected" selected>Chosen cell</option>
<option value="hover">Hovered cell</option>
<option value="always">Always</option>
</select>
</div>
<mx-grid style="height: 200px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
memo: string;
done: boolean;
locked: boolean;
}
const rows: Row[] = [
{ id: 1, task: 'Design review', memo: 'Check icon spacing', done: false, locked: false },
{ id: 2, task: 'Tidy up docs', memo: '', done: true, locked: false },
{ id: 3, task: 'Month-end close (locked)', memo: 'Read-only', done: false, locked: true },
{ id: 4, task: 'Release check', memo: 'Checklist item 3', done: false, locked: false },
];
// editButton: 'selected' | 'hover' | 'always'. It shows only on editable cells, and pressing it opens the editor like F2 (the trigger is 'button').
// It is not added to checkbox, switch, button or link cells (they have their own click target).
const columns = (mode: 'selected' | 'hover' | 'always'): ColumnDef<Row>[] => [
{ id: 'task', title: 'Task', width: 150, editable: (row: Row) => !row.locked, editButton: mode },
{ id: 'memo', title: 'Memo', width: 220, editable: (row: Row) => !row.locked, editButton: mode },
{
id: 'done',
title: 'Done',
width: 100,
kind: 'boolean',
editable: true,
cellRenderer: 'switch',
editButton: mode,
},
];
export const options: GridOptions<Row> = { columns: columns('selected'), rows, rowKey: 'id' };
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'hover' || value === 'always' ? value : 'selected')),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Choose a cell (or hover it) to see the pencil at its end. Press it to open the editor.');
const off = api.on('editStarted', (e) =>
log(`Edit started: row ${e.rowKey} · ${e.columnId} (${e.trigger})`),
);
return () => off();
}