행을 고르면 폼 열기, 닫을 때 확인Open on select, ask before discarding
open: 'select'면 행을 하나 고를 때 폼이 열려요. 고친 값이 있는데 다른 줄로 옮기거나 닫으면 beforeRowPanelClose 훅이 먼저 물어요.With open: 'select' the form opens when one row is selected. With unsaved values, switching rows or closing asks the beforeRowPanelClose hook first.
코드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="position">
<option value="end" selected>끝(오른쪽)</option>
<option value="start">시작(왼쪽)</option>
<option value="bottom">아래</option>
</select>
<select aria-label="버릴 때 묻기" id="ask">
<option value="yes" selected>묻기</option>
<option value="no">묻지 않기</option>
</select>
</div>
<div id="grid" style="height: 330px"></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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('ask').addEventListener('change', (event) => actions.ask(api, event.target.value));const rows = [
{
id: 1,
name: '김서연',
team: '개발',
hours: 32,
joined: '2024-03-04',
active: true,
memo: '신규 입사자 멘토',
},
{
id: 2,
name: '이준호',
team: '디자인',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: '박민지',
team: '기획',
hours: 24,
joined: '2022-11-07',
active: false,
memo: '육아 휴직 중',
},
{ id: 4, name: '최도윤', team: '개발', hours: 36, joined: '2021-05-17', active: true, memo: '' },
{
id: 5,
name: '정하은',
team: '영업',
hours: 28,
joined: '2025-01-13',
active: true,
memo: '수습 기간',
},
];
// open: 'select'는 행을 하나만 고르면 폼을 열어요. 고친 값이 있는 채로 다른 줄로 옮기거나 닫으면 beforeRowPanelClose가 먼저 물어요(false를 돌려주면 그대로 있어요).
export const options = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: '이름',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: '팀',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['개발', '디자인', '기획', '영업'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: '입사일', kind: 'date', width: 120, editable: true },
{ id: 'active', title: '재직', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: '메모', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say = () => undefined;
export function setup(api, log) {
say = log;
log({
ko: '줄을 하나 고르면 폼이 열려요. 값을 고친 채 다른 줄을 고르거나 닫으면 확인을 거쳐요.',
en: 'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
});
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask)
return true;
const keep = !confirm(`${rowKey}번 줄의 저장하지 않은 값을 버릴까요? (${reason})`);
if (keep)
log({ ko: '닫지 않고 그대로 두었어요.', en: 'Kept the form open.' });
return !keep;
},
},
});
const offs = [
api.on('rowPanelClosed', (e) => log({ ko: `닫힘 (${e.reason})`, en: `Closed (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
// 위치를 바꾸면 열려 있던(없으면 2번 줄) 폼을 새 자리에 다시 열어 바로 보여 줘요.
position: (api, value) => {
const position = (value ?? 'end');
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say({
ko: `위치: ${position} — ${key}번 줄 폼을 다시 열었어요`,
en: `position: ${position} — reopened the form of row ${key}`,
});
},
ask: (_api, value) => {
ask = value !== 'no';
say(ask
? {
ko: '버릴 때 묻기: 켜요 — 값을 고친 채 닫으면 확인해요',
en: 'Ask before discarding: on — closing with unsaved values asks first',
}
: {
ko: '버릴 때 묻기: 꺼요 — 묻지 않고 바로 버려요',
en: 'Ask before discarding: off — unsaved values are dropped without asking',
});
},
};<!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="position">
<option value="end" selected>끝(오른쪽)</option>
<option value="start">시작(왼쪽)</option>
<option value="bottom">아래</option>
</select>
<select aria-label="버릴 때 묻기" id="ask">
<option value="yes" selected>묻기</option>
<option value="no">묻지 않기</option>
</select>
</div>
<div id="grid" style="height: 330px"></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,
joined: '2024-03-04',
active: true,
memo: '신규 입사자 멘토',
},
{
id: 2,
name: '이준호',
team: '디자인',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: '박민지',
team: '기획',
hours: 24,
joined: '2022-11-07',
active: false,
memo: '육아 휴직 중',
},
{ id: 4, name: '최도윤', team: '개발', hours: 36, joined: '2021-05-17', active: true, memo: '' },
{
id: 5,
name: '정하은',
team: '영업',
hours: 28,
joined: '2025-01-13',
active: true,
memo: '수습 기간',
},
];
// open: 'select'는 행을 하나만 고르면 폼을 열어요. 고친 값이 있는 채로 다른 줄로 옮기거나 닫으면 beforeRowPanelClose가 먼저 물어요(false를 돌려주면 그대로 있어요).
const options = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: '이름',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: '팀',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['개발', '디자인', '기획', '영업'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: '입사일', kind: 'date', width: 120, editable: true },
{ id: 'active', title: '재직', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: '메모', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say = () => undefined;
function setup(api, log) {
say = log;
log({
ko: '줄을 하나 고르면 폼이 열려요. 값을 고친 채 다른 줄을 고르거나 닫으면 확인을 거쳐요.',
en: 'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
});
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask)
return true;
const keep = !confirm(`${rowKey}번 줄의 저장하지 않은 값을 버릴까요? (${reason})`);
if (keep)
log({ ko: '닫지 않고 그대로 두었어요.', en: 'Kept the form open.' });
return !keep;
},
},
});
const offs = [
api.on('rowPanelClosed', (e) => log({ ko: `닫힘 (${e.reason})`, en: `Closed (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
// 위치를 바꾸면 열려 있던(없으면 2번 줄) 폼을 새 자리에 다시 열어 바로 보여 줘요.
position: (api, value) => {
const position = (value ?? 'end');
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say({
ko: `위치: ${position} — ${key}번 줄 폼을 다시 열었어요`,
en: `position: ${position} — reopened the form of row ${key}`,
});
},
ask: (_api, value) => {
ask = value !== 'no';
say(ask
? {
ko: '버릴 때 묻기: 켜요 — 값을 고친 채 닫으면 확인해요',
en: 'Ask before discarding: on — closing with unsaved values asks first',
}
: {
ko: '버릴 때 묻기: 꺼요 — 묻지 않고 바로 버려요',
en: 'Ask before discarding: off — unsaved values are dropped without asking',
});
},
};
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('ask').addEventListener('change', (event) => actions.ask(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="위치"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="end">끝(오른쪽)</option>
<option value="start">시작(왼쪽)</option>
<option value="bottom">아래</option>
</select>
<select defaultValue="end"
aria-label="버릴 때 묻기"
disabled={!api}
onChange={(event) => api && actions.ask(api, event.target.value)}
>
<option value="yes">묻기</option>
<option value="no">묻지 않기</option>
</select>
</div>
<Grid style={{ height: 330 }} 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;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: '김서연',
team: '개발',
hours: 32,
joined: '2024-03-04',
active: true,
memo: '신규 입사자 멘토',
},
{
id: 2,
name: '이준호',
team: '디자인',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: '박민지',
team: '기획',
hours: 24,
joined: '2022-11-07',
active: false,
memo: '육아 휴직 중',
},
{ id: 4, name: '최도윤', team: '개발', hours: 36, joined: '2021-05-17', active: true, memo: '' },
{
id: 5,
name: '정하은',
team: '영업',
hours: 28,
joined: '2025-01-13',
active: true,
memo: '수습 기간',
},
];
// open: 'select'는 행을 하나만 고르면 폼을 열어요. 고친 값이 있는 채로 다른 줄로 옮기거나 닫으면 beforeRowPanelClose가 먼저 물어요(false를 돌려주면 그대로 있어요).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: '이름',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: '팀',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['개발', '디자인', '기획', '영업'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: '입사일', kind: 'date', width: 120, editable: true },
{ id: 'active', title: '재직', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: '메모', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '줄을 하나 고르면 폼이 열려요. 값을 고친 채 다른 줄을 고르거나 닫으면 확인을 거쳐요.',
en: 'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
});
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`${rowKey}번 줄의 저장하지 않은 값을 버릴까요? (${reason})`);
if (keep) log({ ko: '닫지 않고 그대로 두었어요.', en: 'Kept the form open.' });
return !keep;
},
},
});
const offs = [
api.on('rowPanelClosed', (e) => log({ ko: `닫힘 (${e.reason})`, en: `Closed (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
// 위치를 바꾸면 열려 있던(없으면 2번 줄) 폼을 새 자리에 다시 열어 바로 보여 줘요.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say({
ko: `위치: ${position} — ${key}번 줄 폼을 다시 열었어요`,
en: `position: ${position} — reopened the form of row ${key}`,
});
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? {
ko: '버릴 때 묻기: 켜요 — 값을 고친 채 닫으면 확인해요',
en: 'Ask before discarding: on — closing with unsaved values asks first',
}
: {
ko: '버릴 때 묻기: 꺼요 — 묻지 않고 바로 버려요',
en: 'Ask before discarding: off — unsaved values are dropped without asking',
},
);
},
};버튼을 누르면 이 예제의 코드가 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.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="end" selected>끝(오른쪽)</option>
<option value="start">시작(왼쪽)</option>
<option value="bottom">아래</option>
</select>
<select
aria-label="버릴 때 묻기"
:disabled="!api"
@change="api && actions.ask(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>묻기</option>
<option value="no">묻지 않기</option>
</select>
</div>
<Grid style="height: 330px" :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;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: '김서연',
team: '개발',
hours: 32,
joined: '2024-03-04',
active: true,
memo: '신규 입사자 멘토',
},
{
id: 2,
name: '이준호',
team: '디자인',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: '박민지',
team: '기획',
hours: 24,
joined: '2022-11-07',
active: false,
memo: '육아 휴직 중',
},
{ id: 4, name: '최도윤', team: '개발', hours: 36, joined: '2021-05-17', active: true, memo: '' },
{
id: 5,
name: '정하은',
team: '영업',
hours: 28,
joined: '2025-01-13',
active: true,
memo: '수습 기간',
},
];
// open: 'select'는 행을 하나만 고르면 폼을 열어요. 고친 값이 있는 채로 다른 줄로 옮기거나 닫으면 beforeRowPanelClose가 먼저 물어요(false를 돌려주면 그대로 있어요).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: '이름',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: '팀',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['개발', '디자인', '기획', '영업'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: '입사일', kind: 'date', width: 120, editable: true },
{ id: 'active', title: '재직', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: '메모', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '줄을 하나 고르면 폼이 열려요. 값을 고친 채 다른 줄을 고르거나 닫으면 확인을 거쳐요.',
en: 'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
});
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`${rowKey}번 줄의 저장하지 않은 값을 버릴까요? (${reason})`);
if (keep) log({ ko: '닫지 않고 그대로 두었어요.', en: 'Kept the form open.' });
return !keep;
},
},
});
const offs = [
api.on('rowPanelClosed', (e) => log({ ko: `닫힘 (${e.reason})`, en: `Closed (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
// 위치를 바꾸면 열려 있던(없으면 2번 줄) 폼을 새 자리에 다시 열어 바로 보여 줘요.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say({
ko: `위치: ${position} — ${key}번 줄 폼을 다시 열었어요`,
en: `position: ${position} — reopened the form of row ${key}`,
});
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? {
ko: '버릴 때 묻기: 켜요 — 값을 고친 채 닫으면 확인해요',
en: 'Ask before discarding: on — closing with unsaved values asks first',
}
: {
ko: '버릴 때 묻기: 꺼요 — 묻지 않고 바로 버려요',
en: 'Ask before discarding: off — unsaved values are dropped without asking',
},
);
},
};버튼을 누르면 이 예제의 코드가 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.position(api, $any($event.target).value)"
>
<option value="end" selected>끝(오른쪽)</option>
<option value="start">시작(왼쪽)</option>
<option value="bottom">아래</option>
</select>
<select
aria-label="버릴 때 묻기"
[disabled]="!api"
(change)="api && actions.ask(api, $any($event.target).value)"
>
<option value="yes" selected>묻기</option>
<option value="no">묻지 않기</option>
</select>
</div>
<mx-grid style="height: 330px" [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;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: '김서연',
team: '개발',
hours: 32,
joined: '2024-03-04',
active: true,
memo: '신규 입사자 멘토',
},
{
id: 2,
name: '이준호',
team: '디자인',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: '박민지',
team: '기획',
hours: 24,
joined: '2022-11-07',
active: false,
memo: '육아 휴직 중',
},
{ id: 4, name: '최도윤', team: '개발', hours: 36, joined: '2021-05-17', active: true, memo: '' },
{
id: 5,
name: '정하은',
team: '영업',
hours: 28,
joined: '2025-01-13',
active: true,
memo: '수습 기간',
},
];
// open: 'select'는 행을 하나만 고르면 폼을 열어요. 고친 값이 있는 채로 다른 줄로 옮기거나 닫으면 beforeRowPanelClose가 먼저 물어요(false를 돌려주면 그대로 있어요).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: '이름',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: '팀',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['개발', '디자인', '기획', '영업'].map((value) => ({ value })),
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 110,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: '입사일', kind: 'date', width: 120, editable: true },
{ id: 'active', title: '재직', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: '메모', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '줄을 하나 고르면 폼이 열려요. 값을 고친 채 다른 줄을 고르거나 닫으면 확인을 거쳐요.',
en: 'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
});
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`${rowKey}번 줄의 저장하지 않은 값을 버릴까요? (${reason})`);
if (keep) log({ ko: '닫지 않고 그대로 두었어요.', en: 'Kept the form open.' });
return !keep;
},
},
});
const offs = [
api.on('rowPanelClosed', (e) => log({ ko: `닫힘 (${e.reason})`, en: `Closed (${e.reason})` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
// 위치를 바꾸면 열려 있던(없으면 2번 줄) 폼을 새 자리에 다시 열어 바로 보여 줘요.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say({
ko: `위치: ${position} — ${key}번 줄 폼을 다시 열었어요`,
en: `position: ${position} — reopened the form of row ${key}`,
});
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? {
ko: '버릴 때 묻기: 켜요 — 값을 고친 채 닫으면 확인해요',
en: 'Ask before discarding: on — closing with unsaved values asks first',
}
: {
ko: '버릴 때 묻기: 꺼요 — 묻지 않고 바로 버려요',
en: 'Ask before discarding: off — unsaved values are dropped without asking',
},
);
},
};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="Position" id="position">
<option value="end" selected>End (right)</option>
<option value="start">Start (left)</option>
<option value="bottom">Bottom</option>
</select>
<select aria-label="Ask before discarding" id="ask">
<option value="yes" selected>Ask</option>
<option value="no">Don't ask</option>
</select>
</div>
<div id="grid" style="height: 330px"></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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('ask').addEventListener('change', (event) => actions.ask(api, event.target.value));const rows = [
{
id: 1,
name: 'Liam Carter',
team: 'Dev',
hours: 32,
joined: '2024-03-04',
active: true,
memo: 'Mentor for new hires',
},
{
id: 2,
name: 'Emma Stone',
team: 'Design',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: 'Noah Kim',
team: 'Planning',
hours: 24,
joined: '2022-11-07',
active: false,
memo: 'On parental leave',
},
{
id: 4,
name: 'Olivia Reed',
team: 'Dev',
hours: 36,
joined: '2021-05-17',
active: true,
memo: '',
},
{
id: 5,
name: 'Ava Brooks',
team: 'Sales',
hours: 28,
joined: '2025-01-13',
active: true,
memo: 'Probation period',
},
];
// open: 'select' opens the form when exactly one row is selected. Moving to another row or closing with unsaved values asks beforeRowPanelClose first (return false to stay).
export const options = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: 'Name',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: 'Team',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning', 'Sales'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 140,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 120, editable: true },
{ id: 'active', title: 'Active', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: 'Memo', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say = () => undefined;
export function setup(api, log) {
say = log;
log('Select one row to open the form. With unsaved changes, selecting another row or closing asks first.');
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask)
return true;
const keep = !confirm(`Discard the unsaved values of row ${rowKey}? (${reason})`);
if (keep)
log('Kept the form open.');
return !keep;
},
},
});
const offs = [api.on('rowPanelClosed', (e) => log(`Closed (${e.reason})`))];
return () => offs.forEach((off) => off());
}
export const actions = {
// Changing the position reopens the open form (row 2 if none) in its new place so the change shows at once.
position: (api, value) => {
const position = (value ?? 'end');
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say(`position: ${position} — reopened the form of row ${key}`);
},
ask: (_api, value) => {
ask = value !== 'no';
say(ask
? 'Ask before discarding: on — closing with unsaved values asks first'
: 'Ask before discarding: off — unsaved values are dropped without asking');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Open on select, ask before discarding</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Position" id="position">
<option value="end" selected>End (right)</option>
<option value="start">Start (left)</option>
<option value="bottom">Bottom</option>
</select>
<select aria-label="Ask before discarding" id="ask">
<option value="yes" selected>Ask</option>
<option value="no">Don't ask</option>
</select>
</div>
<div id="grid" style="height: 330px"></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,
joined: '2024-03-04',
active: true,
memo: 'Mentor for new hires',
},
{
id: 2,
name: 'Emma Stone',
team: 'Design',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: 'Noah Kim',
team: 'Planning',
hours: 24,
joined: '2022-11-07',
active: false,
memo: 'On parental leave',
},
{
id: 4,
name: 'Olivia Reed',
team: 'Dev',
hours: 36,
joined: '2021-05-17',
active: true,
memo: '',
},
{
id: 5,
name: 'Ava Brooks',
team: 'Sales',
hours: 28,
joined: '2025-01-13',
active: true,
memo: 'Probation period',
},
];
// open: 'select' opens the form when exactly one row is selected. Moving to another row or closing with unsaved values asks beforeRowPanelClose first (return false to stay).
const options = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: 'Name',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: 'Team',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning', 'Sales'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 140,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 120, editable: true },
{ id: 'active', title: 'Active', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: 'Memo', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say = () => undefined;
function setup(api, log) {
say = log;
log('Select one row to open the form. With unsaved changes, selecting another row or closing asks first.');
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask)
return true;
const keep = !confirm(`Discard the unsaved values of row ${rowKey}? (${reason})`);
if (keep)
log('Kept the form open.');
return !keep;
},
},
});
const offs = [api.on('rowPanelClosed', (e) => log(`Closed (${e.reason})`))];
return () => offs.forEach((off) => off());
}
const actions = {
// Changing the position reopens the open form (row 2 if none) in its new place so the change shows at once.
position: (api, value) => {
const position = (value ?? 'end');
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say(`position: ${position} — reopened the form of row ${key}`);
},
ask: (_api, value) => {
ask = value !== 'no';
say(ask
? 'Ask before discarding: on — closing with unsaved values asks first'
: 'Ask before discarding: off — unsaved values are dropped without asking');
},
};
options.ariaLabel = "Open on select, ask before discarding";
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('ask').addEventListener('change', (event) => actions.ask(api, event.target.value));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="end">End (right)</option>
<option value="start">Start (left)</option>
<option value="bottom">Bottom</option>
</select>
<select defaultValue="end"
aria-label="Ask before discarding"
disabled={!api}
onChange={(event) => api && actions.ask(api, event.target.value)}
>
<option value="yes">Ask</option>
<option value="no">Don't ask</option>
</select>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
hours: number;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Liam Carter',
team: 'Dev',
hours: 32,
joined: '2024-03-04',
active: true,
memo: 'Mentor for new hires',
},
{
id: 2,
name: 'Emma Stone',
team: 'Design',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: 'Noah Kim',
team: 'Planning',
hours: 24,
joined: '2022-11-07',
active: false,
memo: 'On parental leave',
},
{
id: 4,
name: 'Olivia Reed',
team: 'Dev',
hours: 36,
joined: '2021-05-17',
active: true,
memo: '',
},
{
id: 5,
name: 'Ava Brooks',
team: 'Sales',
hours: 28,
joined: '2025-01-13',
active: true,
memo: 'Probation period',
},
];
// open: 'select' opens the form when exactly one row is selected. Moving to another row or closing with unsaved values asks beforeRowPanelClose first (return false to stay).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: 'Name',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: 'Team',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning', 'Sales'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 140,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 120, editable: true },
{ id: 'active', title: 'Active', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: 'Memo', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
);
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`Discard the unsaved values of row ${rowKey}? (${reason})`);
if (keep) log('Kept the form open.');
return !keep;
},
},
});
const offs = [api.on('rowPanelClosed', (e) => log(`Closed (${e.reason})`))];
return () => offs.forEach((off) => off());
}
export const actions = {
// Changing the position reopens the open form (row 2 if none) in its new place so the change shows at once.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say(`position: ${position} — reopened the form of row ${key}`);
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? 'Ask before discarding: on — closing with unsaved values asks first'
: 'Ask before discarding: off — unsaved values are dropped without asking',
);
},
};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="Position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="end" selected>End (right)</option>
<option value="start">Start (left)</option>
<option value="bottom">Bottom</option>
</select>
<select
aria-label="Ask before discarding"
:disabled="!api"
@change="api && actions.ask(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>Ask</option>
<option value="no">Don't ask</option>
</select>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
hours: number;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Liam Carter',
team: 'Dev',
hours: 32,
joined: '2024-03-04',
active: true,
memo: 'Mentor for new hires',
},
{
id: 2,
name: 'Emma Stone',
team: 'Design',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: 'Noah Kim',
team: 'Planning',
hours: 24,
joined: '2022-11-07',
active: false,
memo: 'On parental leave',
},
{
id: 4,
name: 'Olivia Reed',
team: 'Dev',
hours: 36,
joined: '2021-05-17',
active: true,
memo: '',
},
{
id: 5,
name: 'Ava Brooks',
team: 'Sales',
hours: 28,
joined: '2025-01-13',
active: true,
memo: 'Probation period',
},
];
// open: 'select' opens the form when exactly one row is selected. Moving to another row or closing with unsaved values asks beforeRowPanelClose first (return false to stay).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: 'Name',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: 'Team',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning', 'Sales'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 140,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 120, editable: true },
{ id: 'active', title: 'Active', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: 'Memo', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
);
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`Discard the unsaved values of row ${rowKey}? (${reason})`);
if (keep) log('Kept the form open.');
return !keep;
},
},
});
const offs = [api.on('rowPanelClosed', (e) => log(`Closed (${e.reason})`))];
return () => offs.forEach((off) => off());
}
export const actions = {
// Changing the position reopens the open form (row 2 if none) in its new place so the change shows at once.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say(`position: ${position} — reopened the form of row ${key}`);
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? 'Ask before discarding: on — closing with unsaved values asks first'
: 'Ask before discarding: off — unsaved values are dropped without asking',
);
},
};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="Position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="end" selected>End (right)</option>
<option value="start">Start (left)</option>
<option value="bottom">Bottom</option>
</select>
<select
aria-label="Ask before discarding"
[disabled]="!api"
(change)="api && actions.ask(api, $any($event.target).value)"
>
<option value="yes" selected>Ask</option>
<option value="no">Don't ask</option>
</select>
</div>
<mx-grid style="height: 330px" [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;
export interface Row {
id: number;
name: string;
team: string;
hours: number;
joined: string;
active: boolean;
memo: string;
}
const rows: Row[] = [
{
id: 1,
name: 'Liam Carter',
team: 'Dev',
hours: 32,
joined: '2024-03-04',
active: true,
memo: 'Mentor for new hires',
},
{
id: 2,
name: 'Emma Stone',
team: 'Design',
hours: 40,
joined: '2023-08-21',
active: true,
memo: '',
},
{
id: 3,
name: 'Noah Kim',
team: 'Planning',
hours: 24,
joined: '2022-11-07',
active: false,
memo: 'On parental leave',
},
{
id: 4,
name: 'Olivia Reed',
team: 'Dev',
hours: 36,
joined: '2021-05-17',
active: true,
memo: '',
},
{
id: 5,
name: 'Ava Brooks',
team: 'Sales',
hours: 28,
joined: '2025-01-13',
active: true,
memo: 'Probation period',
},
];
// open: 'select' opens the form when exactly one row is selected. Moving to another row or closing with unsaved values asks beforeRowPanelClose first (return false to stay).
export const options: GridOptions<Row> = {
selection: 'single',
rowEditPanel: { open: 'select' },
columns: [
{
id: 'name',
title: 'Name',
width: 130,
editable: true,
validation: { required: true, maxLength: 20 },
},
{
id: 'team',
title: 'Team',
kind: 'select',
width: 100,
editable: true,
editorOptions: ['Dev', 'Design', 'Planning', 'Sales'].map((value) => ({ value })),
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 140,
align: 'end',
editable: true,
validation: { min: 0, max: 60 },
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 120, editable: true },
{ id: 'active', title: 'Active', kind: 'boolean', width: 80, editable: true },
{ id: 'memo', title: 'Memo', width: 180, editable: true, cellEditor: 'textarea' },
],
rows,
rowKey: 'id',
};
let ask = true;
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'Select one row to open the form. With unsaved changes, selecting another row or closing asks first.',
);
api.setOptions({
hooks: {
beforeRowPanelClose: ({ rowKey, reason }) => {
if (!ask) return true;
const keep = !confirm(`Discard the unsaved values of row ${rowKey}? (${reason})`);
if (keep) log('Kept the form open.');
return !keep;
},
},
});
const offs = [api.on('rowPanelClosed', (e) => log(`Closed (${e.reason})`))];
return () => offs.forEach((off) => off());
}
export const actions = {
// Changing the position reopens the open form (row 2 if none) in its new place so the change shows at once.
position: (api: GridApi<Row>, value?: string) => {
const position = (value ?? 'end') as 'end' | 'start' | 'bottom';
api.setOptions({ rowEditPanel: { open: 'select', position } });
const key = api.getRowPanelState().rowKey ?? 2;
api.closeRowPanel({ discard: true });
api.openRowPanel(key);
say(`position: ${position} — reopened the form of row ${key}`);
},
ask: (_api: GridApi<Row>, value?: string) => {
ask = value !== 'no';
say(
ask
? 'Ask before discarding: on — closing with unsaved values asks first'
: 'Ask before discarding: off — unsaved values are dropped without asking',
);
},
};