본문으로 건너뛰기Skip to content
예제 첫화면Examples home

모달 대화상자 안의 그리드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.

활용Intermediate
직접 써 보기Live preview모달 대화상자 안의 그리드A grid inside a modal dialog

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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 ↓.',
    });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
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 ↓.');
  },
};