줄 단위로 고치고 한 번에 확정하기Edit a whole row and commit it at once
줄 편집 모드에서는 Tab으로 같은 줄의 칸들을 차례로 고치고, 마지막에 줄 전체를 한 번에 확정해요. Esc 한 번이면 그 줄에서 고친 것이 모두 사라져요. 칸마다 바로 확정하는 기본 방식과 바꿔 가며 비교해 볼 수 있어요.In row mode, Tab walks through the cells of a row and the whole row commits at once. One Esc discards everything edited in that row. Compare with the default mode where each cell commits on its own.
코드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="row" selected>줄 단위</option>
<option value="cell">칸 단위</option>
</select>
<button type="button" id="editFirst">첫 줄 편집</button>
</div>
<div id="grid" style="height: 210px"></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('editFirst').addEventListener('click', () => actions.editFirst(api));const rows = [
{ id: 1, name: '김서연', team: '개발', hours: 32 },
{ id: 2, name: '이준호', team: '디자인', hours: 40 },
{ id: 3, name: '박민지', team: '기획', hours: 24 },
{ id: 4, name: '최도윤', team: '개발', hours: 36 },
];
// editMode: 'row'는 줄 전체를 한 덩어리로 고쳐요. Tab으로 같은 줄의 다음 칸으로 가고, 마지막 칸에서 Enter를 누르거나
// 다른 줄을 누르면 줄 전체가 확정돼요. Esc는 그 줄에서 고친 것을 모두 버려요.
// 기본값 'cell'은 칸마다 따로 확정해요.
export const options = {
editMode: 'row',
columns: [
{ id: 'name', title: '이름', width: 120, editable: true, validation: { required: true } },
{
id: 'team',
title: '팀',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['개발', '디자인', '기획'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api, log) {
log({
ko: '이름 칸을 더블클릭하고 Tab으로 팀·시간까지 고친 뒤 Enter를 눌러 보세요.',
en: 'Double-click a name cell, edit the team and hours with Tab, then press Enter.',
});
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) => log({
ko: `✓ ${e.rowKey}번 줄 확정: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
en: `✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
})),
api.on('rowEditCancelled', (e) => log({ ko: `↺ ${e.rowKey}번 줄 취소`, en: `↺ Row ${e.rowKey} cancelled` })),
// 줄 단위에서는 줄이 확정되기 전에는 아무것도 적지 않아요(칸이 하나씩 확정되는 것이 아니에요).
api.on('editCommitted', (e) => {
if (rowMode)
return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api, value) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api) => api.startEdit(1, 'name'),
};<!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="row" selected>줄 단위</option>
<option value="cell">칸 단위</option>
</select>
<button type="button" id="editFirst">첫 줄 편집</button>
</div>
<div id="grid" style="height: 210px"></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: '김서연', team: '개발', hours: 32 },
{ id: 2, name: '이준호', team: '디자인', hours: 40 },
{ id: 3, name: '박민지', team: '기획', hours: 24 },
{ id: 4, name: '최도윤', team: '개발', hours: 36 },
];
// editMode: 'row'는 줄 전체를 한 덩어리로 고쳐요. Tab으로 같은 줄의 다음 칸으로 가고, 마지막 칸에서 Enter를 누르거나
// 다른 줄을 누르면 줄 전체가 확정돼요. Esc는 그 줄에서 고친 것을 모두 버려요.
// 기본값 'cell'은 칸마다 따로 확정해요.
const options = {
editMode: 'row',
columns: [
{ id: 'name', title: '이름', width: 120, editable: true, validation: { required: true } },
{
id: 'team',
title: '팀',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['개발', '디자인', '기획'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
function setup(api, log) {
log({
ko: '이름 칸을 더블클릭하고 Tab으로 팀·시간까지 고친 뒤 Enter를 눌러 보세요.',
en: 'Double-click a name cell, edit the team and hours with Tab, then press Enter.',
});
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) => log({
ko: `✓ ${e.rowKey}번 줄 확정: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
en: `✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
})),
api.on('rowEditCancelled', (e) => log({ ko: `↺ ${e.rowKey}번 줄 취소`, en: `↺ Row ${e.rowKey} cancelled` })),
// 줄 단위에서는 줄이 확정되기 전에는 아무것도 적지 않아요(칸이 하나씩 확정되는 것이 아니에요).
api.on('editCommitted', (e) => {
if (rowMode)
return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
const actions = {
mode: (api, value) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api) => api.startEdit(1, 'name'),
};
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('editFirst').addEventListener('click', () => actions.editFirst(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="row">줄 단위</option>
<option value="cell">칸 단위</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editFirst(api)}
>첫 줄 편집</button>
</div>
<Grid style={{ height: 210 }} 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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: '김서연', team: '개발', hours: 32 },
{ id: 2, name: '이준호', team: '디자인', hours: 40 },
{ id: 3, name: '박민지', team: '기획', hours: 24 },
{ id: 4, name: '최도윤', team: '개발', hours: 36 },
];
// editMode: 'row'는 줄 전체를 한 덩어리로 고쳐요. Tab으로 같은 줄의 다음 칸으로 가고, 마지막 칸에서 Enter를 누르거나
// 다른 줄을 누르면 줄 전체가 확정돼요. Esc는 그 줄에서 고친 것을 모두 버려요.
// 기본값 'cell'은 칸마다 따로 확정해요.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: '이름', width: 120, editable: true, validation: { required: true } },
{
id: 'team',
title: '팀',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['개발', '디자인', '기획'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '이름 칸을 더블클릭하고 Tab으로 팀·시간까지 고친 뒤 Enter를 눌러 보세요.',
en: 'Double-click a name cell, edit the team and hours with Tab, then press Enter.',
});
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log({
ko: `✓ ${e.rowKey}번 줄 확정: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
en: `✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
}),
),
api.on('rowEditCancelled', (e) =>
log({ ko: `↺ ${e.rowKey}번 줄 취소`, en: `↺ Row ${e.rowKey} cancelled` }),
),
// 줄 단위에서는 줄이 확정되기 전에는 아무것도 적지 않아요(칸이 하나씩 확정되는 것이 아니에요).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};버튼을 누르면 이 예제의 코드가 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="row" selected>줄 단위</option>
<option value="cell">칸 단위</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.editFirst(api)"
>첫 줄 편집</button>
</div>
<Grid style="height: 210px" :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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: '김서연', team: '개발', hours: 32 },
{ id: 2, name: '이준호', team: '디자인', hours: 40 },
{ id: 3, name: '박민지', team: '기획', hours: 24 },
{ id: 4, name: '최도윤', team: '개발', hours: 36 },
];
// editMode: 'row'는 줄 전체를 한 덩어리로 고쳐요. Tab으로 같은 줄의 다음 칸으로 가고, 마지막 칸에서 Enter를 누르거나
// 다른 줄을 누르면 줄 전체가 확정돼요. Esc는 그 줄에서 고친 것을 모두 버려요.
// 기본값 'cell'은 칸마다 따로 확정해요.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: '이름', width: 120, editable: true, validation: { required: true } },
{
id: 'team',
title: '팀',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['개발', '디자인', '기획'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '이름 칸을 더블클릭하고 Tab으로 팀·시간까지 고친 뒤 Enter를 눌러 보세요.',
en: 'Double-click a name cell, edit the team and hours with Tab, then press Enter.',
});
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log({
ko: `✓ ${e.rowKey}번 줄 확정: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
en: `✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
}),
),
api.on('rowEditCancelled', (e) =>
log({ ko: `↺ ${e.rowKey}번 줄 취소`, en: `↺ Row ${e.rowKey} cancelled` }),
),
// 줄 단위에서는 줄이 확정되기 전에는 아무것도 적지 않아요(칸이 하나씩 확정되는 것이 아니에요).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};버튼을 누르면 이 예제의 코드가 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="row" selected>줄 단위</option>
<option value="cell">칸 단위</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editFirst(api)"
>첫 줄 편집</button>
</div>
<mx-grid style="height: 210px" [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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: '김서연', team: '개발', hours: 32 },
{ id: 2, name: '이준호', team: '디자인', hours: 40 },
{ id: 3, name: '박민지', team: '기획', hours: 24 },
{ id: 4, name: '최도윤', team: '개발', hours: 36 },
];
// editMode: 'row'는 줄 전체를 한 덩어리로 고쳐요. Tab으로 같은 줄의 다음 칸으로 가고, 마지막 칸에서 Enter를 누르거나
// 다른 줄을 누르면 줄 전체가 확정돼요. Esc는 그 줄에서 고친 것을 모두 버려요.
// 기본값 'cell'은 칸마다 따로 확정해요.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: '이름', width: 120, editable: true, validation: { required: true } },
{
id: 'team',
title: '팀',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['개발', '디자인', '기획'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '이름 칸을 더블클릭하고 Tab으로 팀·시간까지 고친 뒤 Enter를 눌러 보세요.',
en: 'Double-click a name cell, edit the team and hours with Tab, then press Enter.',
});
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log({
ko: `✓ ${e.rowKey}번 줄 확정: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
en: `✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`,
}),
),
api.on('rowEditCancelled', (e) =>
log({ ko: `↺ ${e.rowKey}번 줄 취소`, en: `↺ Row ${e.rowKey} cancelled` }),
),
// 줄 단위에서는 줄이 확정되기 전에는 아무것도 적지 않아요(칸이 하나씩 확정되는 것이 아니에요).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};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="Edit unit" id="mode">
<option value="row" selected>Row</option>
<option value="cell">Cell</option>
</select>
<button type="button" id="editFirst">Edit first row</button>
</div>
<div id="grid" style="height: 210px"></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('editFirst').addEventListener('click', () => actions.editFirst(api));const rows = [
{ id: 1, name: 'Liam Carter', team: 'Dev', hours: 32 },
{ id: 2, name: 'Emma Stone', team: 'Design', hours: 40 },
{ id: 3, name: 'Noah Kim', team: 'Planning', hours: 24 },
{ id: 4, name: 'Olivia Reed', team: 'Dev', hours: 36 },
];
// editMode: 'row' edits a whole row as one unit. Tab moves to the next cell in the same row, and pressing Enter in the last cell
// or clicking another row commits the whole row. Esc discards everything changed in that row.
// The default 'cell' commits each cell separately.
export const options = {
editMode: 'row',
columns: [
{ id: 'name', title: 'Name', width: 140, editable: true, validation: { required: true } },
{
id: 'team',
title: 'Team',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api, log) {
log('Double-click a name cell, edit the team and hours with Tab, then press Enter.');
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) => log(`✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`)),
api.on('rowEditCancelled', (e) => log(`↺ Row ${e.rowKey} cancelled`)),
// In row mode nothing is logged until the row is committed (cells are not committed one by one).
api.on('editCommitted', (e) => {
if (rowMode)
return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api, value) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api) => api.startEdit(1, 'name'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Edit a whole row and commit it at once</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Edit unit" id="mode">
<option value="row" selected>Row</option>
<option value="cell">Cell</option>
</select>
<button type="button" id="editFirst">Edit first row</button>
</div>
<div id="grid" style="height: 210px"></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: 'Liam Carter', team: 'Dev', hours: 32 },
{ id: 2, name: 'Emma Stone', team: 'Design', hours: 40 },
{ id: 3, name: 'Noah Kim', team: 'Planning', hours: 24 },
{ id: 4, name: 'Olivia Reed', team: 'Dev', hours: 36 },
];
// editMode: 'row' edits a whole row as one unit. Tab moves to the next cell in the same row, and pressing Enter in the last cell
// or clicking another row commits the whole row. Esc discards everything changed in that row.
// The default 'cell' commits each cell separately.
const options = {
editMode: 'row',
columns: [
{ id: 'name', title: 'Name', width: 140, editable: true, validation: { required: true } },
{
id: 'team',
title: 'Team',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
function setup(api, log) {
log('Double-click a name cell, edit the team and hours with Tab, then press Enter.');
const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) => log(`✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`)),
api.on('rowEditCancelled', (e) => log(`↺ Row ${e.rowKey} cancelled`)),
// In row mode nothing is logged until the row is committed (cells are not committed one by one).
api.on('editCommitted', (e) => {
if (rowMode)
return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
const actions = {
mode: (api, value) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api) => api.startEdit(1, 'name'),
};
options.ariaLabel = "Edit a whole row and commit it at once";
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('editFirst').addEventListener('click', () => actions.editFirst(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="Edit unit"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="row">Row</option>
<option value="cell">Cell</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editFirst(api)}
>Edit first row</button>
</div>
<Grid style={{ height: 210 }} 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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', team: 'Dev', hours: 32 },
{ id: 2, name: 'Emma Stone', team: 'Design', hours: 40 },
{ id: 3, name: 'Noah Kim', team: 'Planning', hours: 24 },
{ id: 4, name: 'Olivia Reed', team: 'Dev', hours: 36 },
];
// editMode: 'row' edits a whole row as one unit. Tab moves to the next cell in the same row, and pressing Enter in the last cell
// or clicking another row commits the whole row. Esc discards everything changed in that row.
// The default 'cell' commits each cell separately.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: 'Name', width: 140, editable: true, validation: { required: true } },
{
id: 'team',
title: 'Team',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a name cell, edit the team and hours with Tab, then press Enter.');
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log(`✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`),
),
api.on('rowEditCancelled', (e) => log(`↺ Row ${e.rowKey} cancelled`)),
// In row mode nothing is logged until the row is committed (cells are not committed one by one).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};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="Edit unit"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="row" selected>Row</option>
<option value="cell">Cell</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.editFirst(api)"
>Edit first row</button>
</div>
<Grid style="height: 210px" :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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', team: 'Dev', hours: 32 },
{ id: 2, name: 'Emma Stone', team: 'Design', hours: 40 },
{ id: 3, name: 'Noah Kim', team: 'Planning', hours: 24 },
{ id: 4, name: 'Olivia Reed', team: 'Dev', hours: 36 },
];
// editMode: 'row' edits a whole row as one unit. Tab moves to the next cell in the same row, and pressing Enter in the last cell
// or clicking another row commits the whole row. Esc discards everything changed in that row.
// The default 'cell' commits each cell separately.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: 'Name', width: 140, editable: true, validation: { required: true } },
{
id: 'team',
title: 'Team',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a name cell, edit the team and hours with Tab, then press Enter.');
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log(`✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`),
),
api.on('rowEditCancelled', (e) => log(`↺ Row ${e.rowKey} cancelled`)),
// In row mode nothing is logged until the row is committed (cells are not committed one by one).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};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="Edit unit"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="row" selected>Row</option>
<option value="cell">Cell</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editFirst(api)"
>Edit first row</button>
</div>
<mx-grid style="height: 210px" [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;
team: string;
hours: number;
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', team: 'Dev', hours: 32 },
{ id: 2, name: 'Emma Stone', team: 'Design', hours: 40 },
{ id: 3, name: 'Noah Kim', team: 'Planning', hours: 24 },
{ id: 4, name: 'Olivia Reed', team: 'Dev', hours: 36 },
];
// editMode: 'row' edits a whole row as one unit. Tab moves to the next cell in the same row, and pressing Enter in the last cell
// or clicking another row commits the whole row. Esc discards everything changed in that row.
// The default 'cell' commits each cell separately.
export const options: GridOptions<Row> = {
editMode: 'row',
columns: [
{ id: 'name', title: 'Name', width: 140, editable: true, validation: { required: true } },
{
id: 'team',
title: 'Team',
kind: 'select',
width: 110,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
],
rows,
rowKey: 'id',
};
let rowMode = true;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a name cell, edit the team and hours with Tab, then press Enter.');
const title = (id: string) => api.getColumns().find((c) => c.id === id)?.title ?? id;
const offs = [
api.on('rowEditCommitted', (e) =>
log(`✓ Row ${e.rowKey} confirmed: ${e.cells.map((c) => title(c.columnId)).join(', ')}`),
),
api.on('rowEditCancelled', (e) => log(`↺ Row ${e.rowKey} cancelled`)),
// In row mode nothing is logged until the row is committed (cells are not committed one by one).
api.on('editCommitted', (e) => {
if (rowMode) return;
log(`· ${title(e.columnId)} = ${String(e.newValue)}`);
}),
];
return () => offs.forEach((off) => off());
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
rowMode = value !== 'cell';
api.setOptions({ editMode: rowMode ? 'row' : 'cell' });
},
editFirst: (api: GridApi<Row>) => api.startEdit(1, 'name'),
};