모달 대화상자 안의 그리드A grid inside a modal dialog
그리드를 모달 <dialog>에 넣어도 메뉴와 날짜 선택기가 대화상자 위에 보여요. popupParent로 팝업이 붙을 곳도 정할 수 있어요.Put the grid in a modal <dialog> and the menus and the date picker still show above it. popupParent picks where popups attach.
코드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="open">대화상자로 열기</button>
</div>
<div id="grid" style="height: 360px"></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('open').addEventListener('click', () => actions.open(api));export const options = {
columns: [
{ id: 'task', title: '작업', width: 130, editable: true },
{ id: 'due', title: '마감일', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: '견적서 보내기', due: '2026-12-01' },
{ id: 2, task: '계약서 검토', due: '2026-12-08' },
{ id: 3, task: '납품 일정 확정', due: '2026-12-15' },
],
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
}
const hostOf = () => document.querySelector('.mxg')?.parentElement ?? null;
// 그리드가 놓인 칸을 모달 <dialog>로 옮긴다(그리드는 다시 만들지 않는다). 닫으면 원래 자리로 돌려놓는다.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null)
return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = document.documentElement.lang === 'en' ? 'Close' : '닫기';
close.style.marginTop = '12px';
// 그리드가 틀 흐름에서 빠지면 예제 틀이 줄어든다. 대화상자와 달력이 들어갈 높이를 열린 동안 지킨다.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = () => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say({ ko: '그리드를 제자리로 돌려놓았어요.', en: 'Put the grid back in place.' });
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say({
ko: '모달 안이에요. 마감일 칸을 두 번 누르고 ↓를 눌러 보세요.',
en: 'Inside the modal. Double-click a due date and press ↓.',
});
},
};<!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="open">대화상자로 열기</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const options = {
columns: [
{ id: 'task', title: '작업', width: 130, editable: true },
{ id: 'due', title: '마감일', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: '견적서 보내기', due: '2026-12-01' },
{ id: 2, task: '계약서 검토', due: '2026-12-08' },
{ id: 3, task: '납품 일정 확정', due: '2026-12-15' },
],
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
}
const hostOf = () => document.querySelector('.mxg')?.parentElement ?? null;
// 그리드가 놓인 칸을 모달 <dialog>로 옮긴다(그리드는 다시 만들지 않는다). 닫으면 원래 자리로 돌려놓는다.
const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null)
return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = document.documentElement.lang === 'en' ? 'Close' : '닫기';
close.style.marginTop = '12px';
// 그리드가 틀 흐름에서 빠지면 예제 틀이 줄어든다. 대화상자와 달력이 들어갈 높이를 열린 동안 지킨다.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = () => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say({ ko: '그리드를 제자리로 돌려놓았어요.', en: 'Put the grid back in place.' });
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say({
ko: '모달 안이에요. 마감일 칸을 두 번 누르고 ↓를 눌러 보세요.',
en: 'Inside the modal. Double-click a due date and press ↓.',
});
},
};
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('open').addEventListener('click', () => actions.open(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.open(api)}
>대화상자로 열기</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 130, editable: true },
{ id: 'due', title: '마감일', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: '견적서 보내기', due: '2026-12-01' },
{ id: 2, task: '계약서 검토', due: '2026-12-08' },
{ id: 3, task: '납품 일정 확정', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// 그리드가 놓인 칸을 모달 <dialog>로 옮긴다(그리드는 다시 만들지 않는다). 닫으면 원래 자리로 돌려놓는다.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = document.documentElement.lang === 'en' ? 'Close' : '닫기';
close.style.marginTop = '12px';
// 그리드가 틀 흐름에서 빠지면 예제 틀이 줄어든다. 대화상자와 달력이 들어갈 높이를 열린 동안 지킨다.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say({ ko: '그리드를 제자리로 돌려놓았어요.', en: 'Put the grid back in place.' });
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say({
ko: '모달 안이에요. 마감일 칸을 두 번 누르고 ↓를 눌러 보세요.',
en: 'Inside the modal. Double-click a due date and press ↓.',
});
},
};버튼을 누르면 이 예제의 코드가 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.open(api)">대화상자로 열기</button>
</div>
<Grid style="height: 360px" :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;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 130, editable: true },
{ id: 'due', title: '마감일', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: '견적서 보내기', due: '2026-12-01' },
{ id: 2, task: '계약서 검토', due: '2026-12-08' },
{ id: 3, task: '납품 일정 확정', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// 그리드가 놓인 칸을 모달 <dialog>로 옮긴다(그리드는 다시 만들지 않는다). 닫으면 원래 자리로 돌려놓는다.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = document.documentElement.lang === 'en' ? 'Close' : '닫기';
close.style.marginTop = '12px';
// 그리드가 틀 흐름에서 빠지면 예제 틀이 줄어든다. 대화상자와 달력이 들어갈 높이를 열린 동안 지킨다.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say({ ko: '그리드를 제자리로 돌려놓았어요.', en: 'Put the grid back in place.' });
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say({
ko: '모달 안이에요. 마감일 칸을 두 번 누르고 ↓를 눌러 보세요.',
en: 'Inside the modal. Double-click a due date and press ↓.',
});
},
};버튼을 누르면 이 예제의 코드가 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.open(api)"
>대화상자로 열기</button>
</div>
<mx-grid style="height: 360px" [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;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: '작업', width: 130, editable: true },
{ id: 'due', title: '마감일', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: '견적서 보내기', due: '2026-12-01' },
{ id: 2, task: '계약서 검토', due: '2026-12-08' },
{ id: 3, task: '납품 일정 확정', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// 그리드가 놓인 칸을 모달 <dialog>로 옮긴다(그리드는 다시 만들지 않는다). 닫으면 원래 자리로 돌려놓는다.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = document.documentElement.lang === 'en' ? 'Close' : '닫기';
close.style.marginTop = '12px';
// 그리드가 틀 흐름에서 빠지면 예제 틀이 줄어든다. 대화상자와 달력이 들어갈 높이를 열린 동안 지킨다.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say({ ko: '그리드를 제자리로 돌려놓았어요.', en: 'Put the grid back in place.' });
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say({
ko: '모달 안이에요. 마감일 칸을 두 번 누르고 ↓를 눌러 보세요.',
en: 'Inside the modal. Double-click a due date and press ↓.',
});
},
};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="open">Open in dialog</button>
</div>
<div id="grid" style="height: 360px"></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('open').addEventListener('click', () => actions.open(api));export const options = {
columns: [
{ id: 'task', title: 'Task', width: 130, editable: true },
{ id: 'due', title: 'Due date', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: 'Send the quote', due: '2026-12-01' },
{ id: 2, task: 'Review the contract', due: '2026-12-08' },
{ id: 3, task: 'Confirm delivery schedule', due: '2026-12-15' },
],
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
}
const hostOf = () => document.querySelector('.mxg')?.parentElement ?? null;
// Moves the cell holding the grid into a modal <dialog> (the grid is not recreated). Closing puts it back in place.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null)
return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = 'Close';
close.style.marginTop = '12px';
// When the grid leaves the frame flow the example frame shrinks. Keep the height for the dialog and calendar while open.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = () => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say('Put the grid back in place.');
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say('Inside the modal. Double-click a due date and press ↓.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A grid inside a modal dialog</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="open">Open in dialog</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const options = {
columns: [
{ id: 'task', title: 'Task', width: 130, editable: true },
{ id: 'due', title: 'Due date', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: 'Send the quote', due: '2026-12-01' },
{ id: 2, task: 'Review the contract', due: '2026-12-08' },
{ id: 3, task: 'Confirm delivery schedule', due: '2026-12-15' },
],
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
}
const hostOf = () => document.querySelector('.mxg')?.parentElement ?? null;
// Moves the cell holding the grid into a modal <dialog> (the grid is not recreated). Closing puts it back in place.
const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null)
return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = 'Close';
close.style.marginTop = '12px';
// When the grid leaves the frame flow the example frame shrinks. Keep the height for the dialog and calendar while open.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = () => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say('Put the grid back in place.');
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say('Inside the modal. Double-click a due date and press ↓.');
},
};
options.ariaLabel = "A grid inside a modal dialog";
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('open').addEventListener('click', () => actions.open(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.open(api)}
>Open in dialog</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 130, editable: true },
{ id: 'due', title: 'Due date', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: 'Send the quote', due: '2026-12-01' },
{ id: 2, task: 'Review the contract', due: '2026-12-08' },
{ id: 3, task: 'Confirm delivery schedule', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// Moves the cell holding the grid into a modal <dialog> (the grid is not recreated). Closing puts it back in place.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = 'Close';
close.style.marginTop = '12px';
// When the grid leaves the frame flow the example frame shrinks. Keep the height for the dialog and calendar while open.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say('Put the grid back in place.');
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say('Inside the modal. Double-click a due date and press ↓.');
},
};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.open(api)">Open in dialog</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 130, editable: true },
{ id: 'due', title: 'Due date', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: 'Send the quote', due: '2026-12-01' },
{ id: 2, task: 'Review the contract', due: '2026-12-08' },
{ id: 3, task: 'Confirm delivery schedule', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// Moves the cell holding the grid into a modal <dialog> (the grid is not recreated). Closing puts it back in place.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = 'Close';
close.style.marginTop = '12px';
// When the grid leaves the frame flow the example frame shrinks. Keep the height for the dialog and calendar while open.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say('Put the grid back in place.');
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say('Inside the modal. Double-click a due date and press ↓.');
},
};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.open(api)"
>Open in dialog</button>
</div>
<mx-grid style="height: 360px" [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;
task: string;
due: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'task', title: 'Task', width: 130, editable: true },
{ id: 'due', title: 'Due date', width: 130, kind: 'date', editable: true, cellEditor: 'date' },
],
rows: [
{ id: 1, task: 'Send the quote', due: '2026-12-01' },
{ id: 2, task: 'Review the contract', due: '2026-12-08' },
{ id: 3, task: 'Confirm delivery schedule', due: '2026-12-15' },
],
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const hostOf = (): HTMLElement | null =>
document.querySelector<HTMLElement>('.mxg')?.parentElement ?? null;
// Moves the cell holding the grid into a modal <dialog> (the grid is not recreated). Closing puts it back in place.
export const actions = {
open: () => {
const host = hostOf();
if (!host || host.closest('dialog') !== null) return;
const home = host.parentElement;
const anchor = document.createComment('grid-home');
host.before(anchor);
const dialog = document.createElement('dialog');
dialog.style.cssText = 'width:min(520px,92vw);padding:16px;border-radius:8px;';
const close = document.createElement('button');
close.type = 'button';
close.textContent = 'Close';
close.style.marginTop = '12px';
// When the grid leaves the frame flow the example frame shrinks. Keep the height for the dialog and calendar while open.
const spacer = document.createElement('div');
spacer.style.minHeight = '560px';
const restore = (): void => {
spacer.remove();
anchor.replaceWith(host);
dialog.remove();
say('Put the grid back in place.');
};
close.addEventListener('click', () => dialog.close());
dialog.addEventListener('close', restore, { once: true });
dialog.append(host, close);
(home ?? document.body).append(spacer, dialog);
dialog.showModal();
say('Inside the modal. Double-click a due date and press ↓.');
},
};