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

날짜 선택기 열기 방식 정하기Choose how the date picker opens

dateTime의 openOnEdit은 편집을 시작하면 선택기를 바로 열고, pickOnly는 입력칸을 읽기 전용으로 두고 선택기로만 값을 정해요. confirm은 날을 누른 뒤 확인 단추로 확정해요. startDate는 값이 없을 때 달력이 보여 줄 달이에요.openOnEdit in dateTime opens the picker as soon as editing starts, and pickOnly makes the input read-only so only the picker sets the value. confirm adds an OK step after clicking a day. startDate is the month shown when there is no value.

활용Intermediate
직접 써 보기Live preview날짜 선택기 열기 방식 정하기Choose how the date picker opens

코드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="edit">첫 줄 편집</button>
    <select aria-label="동작" id="mode">
      <option value="open" selected>바로 열기</option>
      <option value="pick">선택기로만</option>
      <option value="confirm">확인 단추</option>
    </select>
  </div>
  <div id="grid" style="height: 340px"></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('edit').addEventListener('click', () => actions.edit(api));
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)를 그리드 locale로 써요.
const pageLang = () => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// openOnEdit: 편집을 시작하면 선택기를 바로 열어요. pickOnly: 입력칸은 읽기 전용, 선택기로만 정해요.
// confirm: 날을 눌러도 확인(또는 Enter)을 눌러야 확정돼요. startDate: 값이 없을 때 달력이 보여 줄 날이에요.
const columns = (mode) => [
  { id: 'name', title: '업무', width: 150 },
  {
    id: 'due',
    title: '마감일',
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: {
      startDate: '2030-07-01',
      ...(mode === 'open' ? { openOnEdit: true } : {}),
      ...(mode === 'pick' ? { pickOnly: true } : {}),
      ...(mode === 'confirm' ? { confirm: true } : {}),
    },
  },
];
export const options = {
  columns: columns('open'),
  rows: [
    { id: 1, name: '디자인 검수', due: '2026-03-05' },
    { id: 2, name: '문서 정리', due: null },
  ],
  rowKey: 'id',
  locale: pageLang(),
};
export function setup(current, log) {
  const off = current.on('editCommitted', ({ rowKey, columnId, newValue }) => log(`row ${rowKey} · ${columnId} = ${String(newValue)}`));
  const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
  watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
  return () => {
    off();
    watcher.disconnect();
  };
}
export const actions = {
  edit: (current) => current.startEdit(1, 'due'),
  mode: (current, value) => current.setColumns(columns(value ?? 'open')),
};

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="edit">Edit first row</button>
    <select aria-label="Behavior" id="mode">
      <option value="open" selected>Open at once</option>
      <option value="pick">Picker only</option>
      <option value="confirm">OK button</option>
    </select>
  </div>
  <div id="grid" style="height: 340px"></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('edit').addEventListener('click', () => actions.edit(api));
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
// openOnEdit: open the picker as soon as editing starts. pickOnly: the input is read-only, so the value is set only through the picker.
// confirm: clicking a day is not enough; the OK button (or Enter) must be pressed. startDate: the day the calendar shows when there is no value.
const columns = (mode) => [
  { id: 'name', title: 'Task', width: 150 },
  {
    id: 'due',
    title: 'Due',
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: {
      startDate: '2030-07-01',
      ...(mode === 'open' ? { openOnEdit: true } : {}),
      ...(mode === 'pick' ? { pickOnly: true } : {}),
      ...(mode === 'confirm' ? { confirm: true } : {}),
    },
  },
];
export const options = {
  columns: columns('open'),
  rows: [
    { id: 1, name: 'Design review', due: '2026-03-05' },
    { id: 2, name: 'Tidy documents', due: null },
  ],
  rowKey: 'id',
  locale: 'en',
};
export function setup(current, log) {
  const off = current.on('editCommitted', ({ rowKey, columnId, newValue }) => log(`row ${rowKey} · ${columnId} = ${String(newValue)}`));
  return () => {
    off();
  };
}
export const actions = {
  edit: (current) => current.startEdit(1, 'due'),
  mode: (current, value) => current.setColumns(columns(value ?? 'open')),
};