코드로 폼 열기·저장·닫기Open, save and close the form from code
open: 'api'면 두 번 눌러도 열리지 않고 openRowPanel로만 열어요. saveRowPanel, closeRowPanel({ discard }), getRowPanelState로 폼을 다뤄요.With open: 'api' double-clicks do nothing; the form opens only through openRowPanel. Drive it with saveRowPanel, closeRowPanel({ discard }) and getRowPanelState.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="open3">3번 줄 열기</button>
<button type="button" id="save">저장</button>
<button type="button" id="discard">버리고 닫기</button>
<button type="button" id="state">상태 보기</button>
</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('open3').addEventListener('click', () => actions.open3(api));
document.getElementById('save').addEventListener('click', () => actions.save(api));
document.getElementById('discard').addEventListener('click', () => actions.discard(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));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: 'api'는 사용자가 두 번 눌러도 열리지 않고 코드(openRowPanel)로만 열어요. 닫을 때 discard: true면 고친 값을 묻지 않고 버려요.
export const options = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say = () => undefined;
export function setup(api, log) {
say = log;
log({
ko: '버튼으로 폼을 열고 닫고 저장해 보세요. 상태는 getRowPanelState()로 읽어요.',
en: 'Open, save and close the form with the buttons. Read the state with getRowPanelState().',
});
const offs = [
api.on('rowPanelOpened', (e) => log({ ko: `rowPanelOpened ${e.rowKey}`, en: `rowPanelOpened ${e.rowKey}` })),
api.on('rowPanelSaved', (e) => log({
ko: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
en: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
})),
api.on('rowPanelClosed', (e) => log({ ko: `rowPanelClosed ${e.reason}`, en: `rowPanelClosed ${e.reason}` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api) => api.openRowPanel(3),
save: (api) => api.saveRowPanel(),
discard: (api) => api.closeRowPanel({ discard: true }),
state: (api) => say(JSON.stringify(api.getRowPanelState())),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>코드로 폼 열기·저장·닫기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="open3">3번 줄 열기</button>
<button type="button" id="save">저장</button>
<button type="button" id="discard">버리고 닫기</button>
<button type="button" id="state">상태 보기</button>
</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: 'api'는 사용자가 두 번 눌러도 열리지 않고 코드(openRowPanel)로만 열어요. 닫을 때 discard: true면 고친 값을 묻지 않고 버려요.
const options = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say = () => undefined;
function setup(api, log) {
say = log;
log({
ko: '버튼으로 폼을 열고 닫고 저장해 보세요. 상태는 getRowPanelState()로 읽어요.',
en: 'Open, save and close the form with the buttons. Read the state with getRowPanelState().',
});
const offs = [
api.on('rowPanelOpened', (e) => log({ ko: `rowPanelOpened ${e.rowKey}`, en: `rowPanelOpened ${e.rowKey}` })),
api.on('rowPanelSaved', (e) => log({
ko: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
en: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
})),
api.on('rowPanelClosed', (e) => log({ ko: `rowPanelClosed ${e.reason}`, en: `rowPanelClosed ${e.reason}` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
open3: (api) => api.openRowPanel(3),
save: (api) => api.saveRowPanel(),
discard: (api) => api.closeRowPanel({ discard: true }),
state: (api) => say(JSON.stringify(api.getRowPanelState())),
};
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('open3').addEventListener('click', () => actions.open3(api));
document.getElementById('save').addEventListener('click', () => actions.save(api));
document.getElementById('discard').addEventListener('click', () => actions.discard(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.open3(api)}
>3번 줄 열기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.save(api)}
>저장</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.discard(api)}
>버리고 닫기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.state(api)}
>상태 보기</button>
</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: 'api'는 사용자가 두 번 눌러도 열리지 않고 코드(openRowPanel)로만 열어요. 닫을 때 discard: true면 고친 값을 묻지 않고 버려요.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼으로 폼을 열고 닫고 저장해 보세요. 상태는 getRowPanelState()로 읽어요.',
en: 'Open, save and close the form with the buttons. Read the state with getRowPanelState().',
});
const offs = [
api.on('rowPanelOpened', (e) =>
log({ ko: `rowPanelOpened ${e.rowKey}`, en: `rowPanelOpened ${e.rowKey}` }),
),
api.on('rowPanelSaved', (e) =>
log({
ko: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
en: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
}),
),
api.on('rowPanelClosed', (e) =>
log({ ko: `rowPanelClosed ${e.reason}`, en: `rowPanelClosed ${e.reason}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.open3(api)">3번 줄 열기</button>
<button type="button" :disabled="!api" @click="api && actions.save(api)">저장</button>
<button type="button" :disabled="!api" @click="api && actions.discard(api)">버리고 닫기</button>
<button type="button" :disabled="!api" @click="api && actions.state(api)">상태 보기</button>
</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: 'api'는 사용자가 두 번 눌러도 열리지 않고 코드(openRowPanel)로만 열어요. 닫을 때 discard: true면 고친 값을 묻지 않고 버려요.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼으로 폼을 열고 닫고 저장해 보세요. 상태는 getRowPanelState()로 읽어요.',
en: 'Open, save and close the form with the buttons. Read the state with getRowPanelState().',
});
const offs = [
api.on('rowPanelOpened', (e) =>
log({ ko: `rowPanelOpened ${e.rowKey}`, en: `rowPanelOpened ${e.rowKey}` }),
),
api.on('rowPanelSaved', (e) =>
log({
ko: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
en: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
}),
),
api.on('rowPanelClosed', (e) =>
log({ ko: `rowPanelClosed ${e.reason}`, en: `rowPanelClosed ${e.reason}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.open3(api)"
>3번 줄 열기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.save(api)"
>저장</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.discard(api)"
>버리고 닫기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.state(api)"
>상태 보기</button>
</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: 'api'는 사용자가 두 번 눌러도 열리지 않고 코드(openRowPanel)로만 열어요. 닫을 때 discard: true면 고친 값을 묻지 않고 버려요.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '버튼으로 폼을 열고 닫고 저장해 보세요. 상태는 getRowPanelState()로 읽어요.',
en: 'Open, save and close the form with the buttons. Read the state with getRowPanelState().',
});
const offs = [
api.on('rowPanelOpened', (e) =>
log({ ko: `rowPanelOpened ${e.rowKey}`, en: `rowPanelOpened ${e.rowKey}` }),
),
api.on('rowPanelSaved', (e) =>
log({
ko: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
en: `rowPanelSaved ${Object.keys(e.changes).join(',')}`,
}),
),
api.on('rowPanelClosed', (e) =>
log({ ko: `rowPanelClosed ${e.reason}`, en: `rowPanelClosed ${e.reason}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="open3">Open row 3</button>
<button type="button" id="save">Save</button>
<button type="button" id="discard">Close and discard</button>
<button type="button" id="state">Show state</button>
</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('open3').addEventListener('click', () => actions.open3(api));
document.getElementById('save').addEventListener('click', () => actions.save(api));
document.getElementById('discard').addEventListener('click', () => actions.discard(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));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: 'api' ignores double-clicks: only openRowPanel opens the form. closeRowPanel({ discard: true }) drops edited values without asking.
export const options = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say = () => undefined;
export function setup(api, log) {
say = log;
log('Open, save and close the form with the buttons. Read the state with getRowPanelState().');
const offs = [
api.on('rowPanelOpened', (e) => log(`rowPanelOpened ${e.rowKey}`)),
api.on('rowPanelSaved', (e) => log(`rowPanelSaved ${Object.keys(e.changes).join(',')}`)),
api.on('rowPanelClosed', (e) => log(`rowPanelClosed ${e.reason}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api) => api.openRowPanel(3),
save: (api) => api.saveRowPanel(),
discard: (api) => api.closeRowPanel({ discard: true }),
state: (api) => say(JSON.stringify(api.getRowPanelState())),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Open, save and close the form from code</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="open3">Open row 3</button>
<button type="button" id="save">Save</button>
<button type="button" id="discard">Close and discard</button>
<button type="button" id="state">Show state</button>
</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: 'api' ignores double-clicks: only openRowPanel opens the form. closeRowPanel({ discard: true }) drops edited values without asking.
const options = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say = () => undefined;
function setup(api, log) {
say = log;
log('Open, save and close the form with the buttons. Read the state with getRowPanelState().');
const offs = [
api.on('rowPanelOpened', (e) => log(`rowPanelOpened ${e.rowKey}`)),
api.on('rowPanelSaved', (e) => log(`rowPanelSaved ${Object.keys(e.changes).join(',')}`)),
api.on('rowPanelClosed', (e) => log(`rowPanelClosed ${e.reason}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
open3: (api) => api.openRowPanel(3),
save: (api) => api.saveRowPanel(),
discard: (api) => api.closeRowPanel({ discard: true }),
state: (api) => say(JSON.stringify(api.getRowPanelState())),
};
options.ariaLabel = "Open, save and close the form from code";
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('open3').addEventListener('click', () => actions.open3(api));
document.getElementById('save').addEventListener('click', () => actions.save(api));
document.getElementById('discard').addEventListener('click', () => actions.discard(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.open3(api)}
>Open row 3</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.save(api)}
>Save</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.discard(api)}
>Close and discard</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.state(api)}
>Show state</button>
</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: 'api' ignores double-clicks: only openRowPanel opens the form. closeRowPanel({ discard: true }) drops edited values without asking.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Open, save and close the form with the buttons. Read the state with getRowPanelState().');
const offs = [
api.on('rowPanelOpened', (e) => log(`rowPanelOpened ${e.rowKey}`)),
api.on('rowPanelSaved', (e) => log(`rowPanelSaved ${Object.keys(e.changes).join(',')}`)),
api.on('rowPanelClosed', (e) => log(`rowPanelClosed ${e.reason}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.open3(api)">Open row 3</button>
<button type="button" :disabled="!api" @click="api && actions.save(api)">Save</button>
<button type="button" :disabled="!api" @click="api && actions.discard(api)">Close and discard</button>
<button type="button" :disabled="!api" @click="api && actions.state(api)">Show state</button>
</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: 'api' ignores double-clicks: only openRowPanel opens the form. closeRowPanel({ discard: true }) drops edited values without asking.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Open, save and close the form with the buttons. Read the state with getRowPanelState().');
const offs = [
api.on('rowPanelOpened', (e) => log(`rowPanelOpened ${e.rowKey}`)),
api.on('rowPanelSaved', (e) => log(`rowPanelSaved ${Object.keys(e.changes).join(',')}`)),
api.on('rowPanelClosed', (e) => log(`rowPanelClosed ${e.reason}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.open3(api)"
>Open row 3</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.save(api)"
>Save</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.discard(api)"
>Close and discard</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.state(api)"
>Show state</button>
</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: 'api' ignores double-clicks: only openRowPanel opens the form. closeRowPanel({ discard: true }) drops edited values without asking.
export const options: GridOptions<Row> = {
rowEditPanel: { open: 'api', position: 'start', size: 320 },
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 say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Open, save and close the form with the buttons. Read the state with getRowPanelState().');
const offs = [
api.on('rowPanelOpened', (e) => log(`rowPanelOpened ${e.rowKey}`)),
api.on('rowPanelSaved', (e) => log(`rowPanelSaved ${Object.keys(e.changes).join(',')}`)),
api.on('rowPanelClosed', (e) => log(`rowPanelClosed ${e.reason}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
open3: (api: GridApi<Row>) => api.openRowPanel(3),
save: (api: GridApi<Row>) => api.saveRowPanel(),
discard: (api: GridApi<Row>) => api.closeRowPanel({ discard: true }),
state: (api: GridApi<Row>) => say(JSON.stringify(api.getRowPanelState())),
};