마우스 없이 입력하기: 편집 시작과 키보드 이동Entering data without the mouse
더블클릭, F2·Enter, 글자 입력, 코드의 편집 시작 호출로 편집을 시작할 수 있고, Enter는 확정, Esc는 취소, Tab은 다음에 고칠 수 있는 칸으로 가요. 읽기 전용 칸은 건너뛰어요.Start an edit by double-click, F2, Enter, typing, or startEdit from code. Enter commits, Esc cancels and Tab jumps to the next editable cell, skipping read-only ones.
코드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="editQty">코드로 수량 편집 시작</button>
<button type="button" id="editNote">코드로 메모 편집 시작</button>
<button type="button" id="cancel">편집 취소</button>
</div>
<div id="grid" style="height: 340px"></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('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('editNote').addEventListener('click', () => actions.editNote(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(api));const items = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇', '레이저 포인터'];
// "품목"은 읽기 전용이고 나머지는 고칠 수 있어요. Tab은 다음에 고칠 수 있는 칸으로 가기 때문에 품목 칸은 건너뛰어요.
const rows = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1500 + ((i * 7) % 6) * 2500,
note: '',
}));
export const options = {
columns: [
{ id: 'item', title: '품목', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: '단가',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
{ id: 'note', title: '메모', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// 편집을 시작하는 방법은 세 가지예요. editStarted 이벤트의 trigger가 어떤 방법이었는지 알려 줘요.
const how = {
doubleClick: ['더블클릭', 'double-click'],
click: ['한 번 클릭(목록·체크박스 칸)', 'single click (list and checkbox cells)'],
key: ['키보드(F2·Enter·글자 입력)', 'keyboard (F2, Enter, typing)'],
api: ['코드(startEdit)', 'code (startEdit)'],
};
export function setup(api, log) {
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) => log({
ko: `▶ ${title(e.columnId)} 편집 시작 — ${how[e.trigger]?.[0] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
en: `▶ ${title(e.columnId)} edit started — ${how[e.trigger]?.[1] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
})),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log({ ko: `✗ 취소 (${e.reason})`, en: `✗ Cancelled (${e.reason})` })),
];
log({
ko: '첫 줄 "수량" 칸을 한 번 눌러 두고 키보드로 해 보세요: 방향키로 이동, F2·Enter로 편집, Tab으로 다음 칸.',
en: 'Click the "수량" (quantity) cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
});
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api) => api.startEdit(1, 'qty'),
editNote: (api) => api.startEdit(1, 'note'),
cancel: (api) => api.stopEdit({ cancel: true }),
};<!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="editQty">코드로 수량 편집 시작</button>
<button type="button" id="editNote">코드로 메모 편집 시작</button>
<button type="button" id="cancel">편집 취소</button>
</div>
<div id="grid" style="height: 340px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const items = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇', '레이저 포인터'];
// "품목"은 읽기 전용이고 나머지는 고칠 수 있어요. Tab은 다음에 고칠 수 있는 칸으로 가기 때문에 품목 칸은 건너뛰어요.
const rows = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1500 + ((i * 7) % 6) * 2500,
note: '',
}));
const options = {
columns: [
{ id: 'item', title: '품목', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: '단가',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
{ id: 'note', title: '메모', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// 편집을 시작하는 방법은 세 가지예요. editStarted 이벤트의 trigger가 어떤 방법이었는지 알려 줘요.
const how = {
doubleClick: ['더블클릭', 'double-click'],
click: ['한 번 클릭(목록·체크박스 칸)', 'single click (list and checkbox cells)'],
key: ['키보드(F2·Enter·글자 입력)', 'keyboard (F2, Enter, typing)'],
api: ['코드(startEdit)', 'code (startEdit)'],
};
function setup(api, log) {
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) => log({
ko: `▶ ${title(e.columnId)} 편집 시작 — ${how[e.trigger]?.[0] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
en: `▶ ${title(e.columnId)} edit started — ${how[e.trigger]?.[1] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
})),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log({ ko: `✗ 취소 (${e.reason})`, en: `✗ Cancelled (${e.reason})` })),
];
log({
ko: '첫 줄 "수량" 칸을 한 번 눌러 두고 키보드로 해 보세요: 방향키로 이동, F2·Enter로 편집, Tab으로 다음 칸.',
en: 'Click the "수량" (quantity) cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
});
return () => offs.forEach((off) => off());
}
const actions = {
editQty: (api) => api.startEdit(1, 'qty'),
editNote: (api) => api.startEdit(1, 'note'),
cancel: (api) => api.stopEdit({ cancel: true }),
};
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('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('editNote').addEventListener('click', () => actions.editNote(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(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.editQty(api)}
>코드로 수량 편집 시작</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editNote(api)}
>코드로 메모 편집 시작</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cancel(api)}
>편집 취소</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number;
price: number;
note: string;
}
const items = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇', '레이저 포인터'];
// "품목"은 읽기 전용이고 나머지는 고칠 수 있어요. Tab은 다음에 고칠 수 있는 칸으로 가기 때문에 품목 칸은 건너뛰어요.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1500 + ((i * 7) % 6) * 2500,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: '단가',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
{ id: 'note', title: '메모', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// 편집을 시작하는 방법은 세 가지예요. editStarted 이벤트의 trigger가 어떤 방법이었는지 알려 줘요.
const how: Record<string, [string, string]> = {
doubleClick: ['더블클릭', 'double-click'],
click: ['한 번 클릭(목록·체크박스 칸)', 'single click (list and checkbox cells)'],
key: ['키보드(F2·Enter·글자 입력)', 'keyboard (F2, Enter, typing)'],
api: ['코드(startEdit)', 'code (startEdit)'],
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log({
ko: `▶ ${title(e.columnId)} 편집 시작 — ${how[e.trigger]?.[0] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
en: `▶ ${title(e.columnId)} edit started — ${how[e.trigger]?.[1] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
}),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) =>
log({ ko: `✗ 취소 (${e.reason})`, en: `✗ Cancelled (${e.reason})` }),
),
];
log({
ko: '첫 줄 "수량" 칸을 한 번 눌러 두고 키보드로 해 보세요: 방향키로 이동, F2·Enter로 편집, Tab으로 다음 칸.',
en: 'Click the "수량" (quantity) cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
});
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};버튼을 누르면 이 예제의 코드가 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.editQty(api)">코드로 수량 편집 시작</button>
<button
type="button"
:disabled="!api"
@click="api && actions.editNote(api)"
>코드로 메모 편집 시작</button>
<button type="button" :disabled="!api" @click="api && actions.cancel(api)">편집 취소</button>
</div>
<Grid style="height: 340px" :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;
item: string;
qty: number;
price: number;
note: string;
}
const items = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇', '레이저 포인터'];
// "품목"은 읽기 전용이고 나머지는 고칠 수 있어요. Tab은 다음에 고칠 수 있는 칸으로 가기 때문에 품목 칸은 건너뛰어요.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1500 + ((i * 7) % 6) * 2500,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: '단가',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
{ id: 'note', title: '메모', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// 편집을 시작하는 방법은 세 가지예요. editStarted 이벤트의 trigger가 어떤 방법이었는지 알려 줘요.
const how: Record<string, [string, string]> = {
doubleClick: ['더블클릭', 'double-click'],
click: ['한 번 클릭(목록·체크박스 칸)', 'single click (list and checkbox cells)'],
key: ['키보드(F2·Enter·글자 입력)', 'keyboard (F2, Enter, typing)'],
api: ['코드(startEdit)', 'code (startEdit)'],
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log({
ko: `▶ ${title(e.columnId)} 편집 시작 — ${how[e.trigger]?.[0] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
en: `▶ ${title(e.columnId)} edit started — ${how[e.trigger]?.[1] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
}),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) =>
log({ ko: `✗ 취소 (${e.reason})`, en: `✗ Cancelled (${e.reason})` }),
),
];
log({
ko: '첫 줄 "수량" 칸을 한 번 눌러 두고 키보드로 해 보세요: 방향키로 이동, F2·Enter로 편집, Tab으로 다음 칸.',
en: 'Click the "수량" (quantity) cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
});
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};버튼을 누르면 이 예제의 코드가 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.editQty(api)"
>코드로 수량 편집 시작</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editNote(api)"
>코드로 메모 편집 시작</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cancel(api)"
>편집 취소</button>
</div>
<mx-grid style="height: 340px" [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;
item: string;
qty: number;
price: number;
note: string;
}
const items = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇', '레이저 포인터'];
// "품목"은 읽기 전용이고 나머지는 고칠 수 있어요. Tab은 다음에 고칠 수 있는 칸으로 가기 때문에 품목 칸은 건너뛰어요.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1500 + ((i * 7) % 6) * 2500,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: '단가',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
{ id: 'note', title: '메모', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// 편집을 시작하는 방법은 세 가지예요. editStarted 이벤트의 trigger가 어떤 방법이었는지 알려 줘요.
const how: Record<string, [string, string]> = {
doubleClick: ['더블클릭', 'double-click'],
click: ['한 번 클릭(목록·체크박스 칸)', 'single click (list and checkbox cells)'],
key: ['키보드(F2·Enter·글자 입력)', 'keyboard (F2, Enter, typing)'],
api: ['코드(startEdit)', 'code (startEdit)'],
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log({
ko: `▶ ${title(e.columnId)} 편집 시작 — ${how[e.trigger]?.[0] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
en: `▶ ${title(e.columnId)} edit started — ${how[e.trigger]?.[1] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
}),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) =>
log({ ko: `✗ 취소 (${e.reason})`, en: `✗ Cancelled (${e.reason})` }),
),
];
log({
ko: '첫 줄 "수량" 칸을 한 번 눌러 두고 키보드로 해 보세요: 방향키로 이동, F2·Enter로 편집, Tab으로 다음 칸.',
en: 'Click the "수량" (quantity) cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
});
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};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="editQty">Start qty edit from code</button>
<button type="button" id="editNote">Start note edit from code</button>
<button type="button" id="cancel">Cancel edit</button>
</div>
<div id="grid" style="height: 340px"></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('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('editNote').addEventListener('click', () => actions.editNote(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(api));const items = [
'Whiteboard',
'Board markers',
'Eraser',
'Magnet clips',
'Sticky notes',
'Laser pointer',
];
// "Item" is read-only and the rest can be edited. Tab goes to the next editable cell, so it skips the Item cell.
const rows = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1.5 + ((i * 7) % 6) * 2.5,
note: '',
}));
export const options = {
columns: [
{ id: 'item', title: 'Item', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `$${Number(v).toLocaleString('en-US', { minimumFractionDigits: 2 })}`,
},
{ id: 'note', title: 'Note', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// There are several ways to start editing. The trigger of the editStarted event tells which one was used.
const how = {
doubleClick: 'double-click',
click: 'single click (list and checkbox cells)',
key: 'keyboard (F2, Enter, typing)',
api: 'code (startEdit)',
};
export function setup(api, log) {
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) => log(`▶ ${title(e.columnId)} edit started — ${how[e.trigger] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`)),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log(`✗ Cancelled (${e.reason})`)),
];
log('Click the "Qty" cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.');
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api) => api.startEdit(1, 'qty'),
editNote: (api) => api.startEdit(1, 'note'),
cancel: (api) => api.stopEdit({ cancel: true }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Entering data without the mouse</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editQty">Start qty edit from code</button>
<button type="button" id="editNote">Start note edit from code</button>
<button type="button" id="cancel">Cancel edit</button>
</div>
<div id="grid" style="height: 340px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const items = [
'Whiteboard',
'Board markers',
'Eraser',
'Magnet clips',
'Sticky notes',
'Laser pointer',
];
// "Item" is read-only and the rest can be edited. Tab goes to the next editable cell, so it skips the Item cell.
const rows = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1.5 + ((i * 7) % 6) * 2.5,
note: '',
}));
const options = {
columns: [
{ id: 'item', title: 'Item', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `$${Number(v).toLocaleString('en-US', { minimumFractionDigits: 2 })}`,
},
{ id: 'note', title: 'Note', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// There are several ways to start editing. The trigger of the editStarted event tells which one was used.
const how = {
doubleClick: 'double-click',
click: 'single click (list and checkbox cells)',
key: 'keyboard (F2, Enter, typing)',
api: 'code (startEdit)',
};
function setup(api, log) {
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) => log(`▶ ${title(e.columnId)} edit started — ${how[e.trigger] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`)),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log(`✗ Cancelled (${e.reason})`)),
];
log('Click the "Qty" cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.');
return () => offs.forEach((off) => off());
}
const actions = {
editQty: (api) => api.startEdit(1, 'qty'),
editNote: (api) => api.startEdit(1, 'note'),
cancel: (api) => api.stopEdit({ cancel: true }),
};
options.ariaLabel = "Entering data without the mouse";
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('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('editNote').addEventListener('click', () => actions.editNote(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(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.editQty(api)}
>Start qty edit from code</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editNote(api)}
>Start note edit from code</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cancel(api)}
>Cancel edit</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number;
price: number;
note: string;
}
const items = [
'Whiteboard',
'Board markers',
'Eraser',
'Magnet clips',
'Sticky notes',
'Laser pointer',
];
// "Item" is read-only and the rest can be edited. Tab goes to the next editable cell, so it skips the Item cell.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1.5 + ((i * 7) % 6) * 2.5,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `$${Number(v).toLocaleString('en-US', { minimumFractionDigits: 2 })}`,
},
{ id: 'note', title: 'Note', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// There are several ways to start editing. The trigger of the editStarted event tells which one was used.
const how: Record<string, string> = {
doubleClick: 'double-click',
click: 'single click (list and checkbox cells)',
key: 'keyboard (F2, Enter, typing)',
api: 'code (startEdit)',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log(
`▶ ${title(e.columnId)} edit started — ${how[e.trigger] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log(`✗ Cancelled (${e.reason})`)),
];
log(
'Click the "Qty" cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
);
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};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.editQty(api)">Start qty edit from code</button>
<button
type="button"
:disabled="!api"
@click="api && actions.editNote(api)"
>Start note edit from code</button>
<button type="button" :disabled="!api" @click="api && actions.cancel(api)">Cancel edit</button>
</div>
<Grid style="height: 340px" :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;
item: string;
qty: number;
price: number;
note: string;
}
const items = [
'Whiteboard',
'Board markers',
'Eraser',
'Magnet clips',
'Sticky notes',
'Laser pointer',
];
// "Item" is read-only and the rest can be edited. Tab goes to the next editable cell, so it skips the Item cell.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1.5 + ((i * 7) % 6) * 2.5,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `$${Number(v).toLocaleString('en-US', { minimumFractionDigits: 2 })}`,
},
{ id: 'note', title: 'Note', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// There are several ways to start editing. The trigger of the editStarted event tells which one was used.
const how: Record<string, string> = {
doubleClick: 'double-click',
click: 'single click (list and checkbox cells)',
key: 'keyboard (F2, Enter, typing)',
api: 'code (startEdit)',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log(
`▶ ${title(e.columnId)} edit started — ${how[e.trigger] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log(`✗ Cancelled (${e.reason})`)),
];
log(
'Click the "Qty" cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
);
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};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.editQty(api)"
>Start qty edit from code</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editNote(api)"
>Start note edit from code</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cancel(api)"
>Cancel edit</button>
</div>
<mx-grid style="height: 340px" [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;
item: string;
qty: number;
price: number;
note: string;
}
const items = [
'Whiteboard',
'Board markers',
'Eraser',
'Magnet clips',
'Sticky notes',
'Laser pointer',
];
// "Item" is read-only and the rest can be edited. Tab goes to the next editable cell, so it skips the Item cell.
const rows: Row[] = items.map((item, i) => ({
id: i + 1,
item,
qty: 1 + ((i * 3) % 8),
price: 1.5 + ((i * 7) % 6) * 2.5,
note: '',
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
editable: true,
formatValue: (v) => `$${Number(v).toLocaleString('en-US', { minimumFractionDigits: 2 })}`,
},
{ id: 'note', title: 'Note', width: 180, editable: true },
],
rows,
rowKey: 'id',
};
// There are several ways to start editing. The trigger of the editStarted event tells which one was used.
const how: Record<string, string> = {
doubleClick: 'double-click',
click: 'single click (list and checkbox cells)',
key: 'keyboard (F2, Enter, typing)',
api: 'code (startEdit)',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('editStarted', (e) =>
log(
`▶ ${title(e.columnId)} edit started — ${how[e.trigger] ?? e.trigger}${e.startKey ? ` [${e.startKey}]` : ''}`,
),
),
api.on('editCommitted', (e) => log(`✓ ${title(e.columnId)} = ${String(e.newValue)}`)),
api.on('editCancelled', (e) => log(`✗ Cancelled (${e.reason})`)),
];
log(
'Click the "Qty" cell of the first row once, then use the keyboard: arrows to move, F2 or Enter to edit, Tab for the next cell.',
);
return () => offs.forEach((off) => off());
}
export const actions = {
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
editNote: (api: GridApi<Row>) => api.startEdit(1, 'note'),
cancel: (api: GridApi<Row>) => api.stopEdit({ cancel: true }),
};