편집 중 키 이동을 내 방식으로 바꾸기Change how keys move while editing
editNav로 Enter 뒤 이동, Tab으로 편집 시작 여부, 읽기 전용 컬럼 건너뛰기, 편집 중 ↑↓ 확정, Backspace로 편집 시작을 고르고, 컬럼의 navigable로 키보드 이동에서 뺄 칸을 정해요.editNav picks where Enter goes, whether Tab starts an edit, skipping read-only columns, Up/Down commit and Backspace-to-edit; a column's navigable keeps it out of keyboard movement.
코드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="basic" selected>기본</option>
<option value="enter">Enter 뒤 아래로</option>
<option value="sheet">엑셀처럼</option>
</select>
<button type="button" id="editQty">수량 편집</button>
</div>
<div id="grid" style="height: 280px"></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));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));const rows = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map((item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1500 + i * 2500,
note: '',
}));
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
// - enter: Enter로 확정한 뒤 한 칸 아래로
// - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
// - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
// - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode) => ({
columns: [
{ id: 'item', title: '품목', width: 120 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{ id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
{ id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav: mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options = optionsFor('basic');
export function setup(api, log) {
log({
ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
});
const offs = [
api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
editQty: (api) => api.startEdit(1, 'qty'),
};<!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="basic" selected>기본</option>
<option value="enter">Enter 뒤 아래로</option>
<option value="sheet">엑셀처럼</option>
</select>
<button type="button" id="editQty">수량 편집</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map((item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1500 + i * 2500,
note: '',
}));
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
// - enter: Enter로 확정한 뒤 한 칸 아래로
// - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
// - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
// - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode) => ({
columns: [
{ id: 'item', title: '품목', width: 120 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{ id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
{ id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav: mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
const options = optionsFor('basic');
function setup(api, log) {
log({
ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
});
const offs = [
api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
editQty: (api) => api.startEdit(1, 'qty'),
};
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));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(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">
<select
aria-label="키 설정"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="basic">기본</option>
<option value="enter">Enter 뒤 아래로</option>
<option value="sheet">엑셀처럼</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editQty(api)}
>수량 편집</button>
</div>
<Grid style={{ height: 280 }} 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 rows: Row[] = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1500 + i * 2500,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
// - enter: Enter로 확정한 뒤 한 칸 아래로
// - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
// - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
// - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode: Mode): GridOptions<Row> => ({
columns: [
{ id: 'item', title: '품목', width: 120 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{ id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
{ id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
});
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};버튼을 누르면 이 예제의 코드가 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="basic" selected>기본</option>
<option value="enter">Enter 뒤 아래로</option>
<option value="sheet">엑셀처럼</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.editQty(api)">수량 편집</button>
</div>
<Grid style="height: 280px" :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 rows: Row[] = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1500 + i * 2500,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
// - enter: Enter로 확정한 뒤 한 칸 아래로
// - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
// - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
// - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode: Mode): GridOptions<Row> => ({
columns: [
{ id: 'item', title: '품목', width: 120 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{ id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
{ id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
});
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};버튼을 누르면 이 예제의 코드가 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="basic" selected>기본</option>
<option value="enter">Enter 뒤 아래로</option>
<option value="sheet">엑셀처럼</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editQty(api)"
>수량 편집</button>
</div>
<mx-grid style="height: 280px" [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 rows: Row[] = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1500 + i * 2500,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
// - enter: Enter로 확정한 뒤 한 칸 아래로
// - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
// - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
// - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode: Mode): GridOptions<Row> => ({
columns: [
{ id: 'item', title: '품목', width: 120 },
{ id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
{ id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
{ id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
});
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};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="Key mode" id="mode">
<option value="basic" selected>Default</option>
<option value="enter">Enter moves down</option>
<option value="sheet">Spreadsheet style</option>
</select>
<button type="button" id="editQty">Edit quantity</button>
</div>
<div id="grid" style="height: 280px"></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));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));const rows = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map((item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1.5 + i * 2.5,
note: '',
}));
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
// - enter: after committing with Enter, move one cell down
// - skipReadonly: arrow keys and Tab skip the read-only "Item" column
// - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
// - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode) => ({
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 },
{ id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav: mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options = optionsFor('basic');
export function setup(api, log) {
log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
const offs = [
api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
editQty: (api) => api.startEdit(1, 'qty'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change how keys move while editing</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Key mode" id="mode">
<option value="basic" selected>Default</option>
<option value="enter">Enter moves down</option>
<option value="sheet">Spreadsheet style</option>
</select>
<button type="button" id="editQty">Edit quantity</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map((item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1.5 + i * 2.5,
note: '',
}));
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
// - enter: after committing with Enter, move one cell down
// - skipReadonly: arrow keys and Tab skip the read-only "Item" column
// - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
// - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode) => ({
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 },
{ id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav: mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
const options = optionsFor('basic');
function setup(api, log) {
log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
const offs = [
api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
editQty: (api) => api.startEdit(1, 'qty'),
};
options.ariaLabel = "Change how keys move while editing";
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));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(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">
<select
aria-label="Key mode"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="basic">Default</option>
<option value="enter">Enter moves down</option>
<option value="sheet">Spreadsheet style</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editQty(api)}
>Edit quantity</button>
</div>
<Grid style={{ height: 280 }} 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 rows: Row[] = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1.5 + i * 2.5,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
// - enter: after committing with Enter, move one cell down
// - skipReadonly: arrow keys and Tab skip the read-only "Item" column
// - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
// - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode: Mode): 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 },
{ id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};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="Key mode"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="basic" selected>Default</option>
<option value="enter">Enter moves down</option>
<option value="sheet">Spreadsheet style</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.editQty(api)">Edit quantity</button>
</div>
<Grid style="height: 280px" :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 rows: Row[] = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1.5 + i * 2.5,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
// - enter: after committing with Enter, move one cell down
// - skipReadonly: arrow keys and Tab skip the read-only "Item" column
// - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
// - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode: Mode): 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 },
{ id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};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="Key mode"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="basic" selected>Default</option>
<option value="enter">Enter moves down</option>
<option value="sheet">Spreadsheet style</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editQty(api)"
>Edit quantity</button>
</div>
<mx-grid style="height: 280px" [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 rows: Row[] = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map(
(item, i) => ({
id: i + 1,
item,
qty: 2 + i,
price: 1.5 + i * 2.5,
note: '',
}),
);
type Mode = 'basic' | 'enter' | 'sheet';
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
// - enter: after committing with Enter, move one cell down
// - skipReadonly: arrow keys and Tab skip the read-only "Item" column
// - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
// - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode: Mode): 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 },
{ id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
],
rows,
rowKey: 'id',
singleClickEdit: mode === 'sheet' ? 'all' : true,
editNav:
mode === 'basic'
? {}
: mode === 'enter'
? { enter: 'down', tabStartsEdit: false }
: { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options: GridOptions<Row> = optionsFor('basic');
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
const offs = [
api.on('editCommitted', (e) =>
log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`),
),
api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value as Mode) ?? 'basic')),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
};