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

날짜 칸 편집: 직접 쓰거나 달력에서 고르기Edit dates by typing or from a calendar

날짜 컬럼은 날짜 편집기가 열려요. 2026-03-05나 2026.3.5처럼 직접 쓰거나 달력에서 고를 수 있고, 값은 데이터에 들어 있던 모양(Date·글자·밀리초) 그대로 돌아와요.Date columns open a date editor: type 2026-03-05 or 2026.3.5, or pick from the calendar. The value comes back in the shape it had (Date, text or milliseconds).

입문Beginner
직접 써 보기Live preview날짜 칸 편집: 직접 쓰거나 달력에서 고르기Edit dates by typing or from a calendar

코드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="openCalendar">첫 줄 마감일 편집</button>
  </div>
  <div id="grid" style="height: 280px"></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('openCalendar').addEventListener('click', () => actions.openCalendar(api));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const tasks = ['계약서 검토', '디자인 시안 확인', '예산안 제출', '교육 자료 배포'];
// 날짜 컬럼(kind: 'date')은 날짜 편집기가 열려요. 같은 날짜라도 데이터에 어떤 모양으로 들어 있든 그 모양 그대로 돌려줘요:
// Date 객체는 Date로, 'YYYY-MM-DD' 글자는 글자로, 밀리초 숫자는 숫자로 돌아와요. 날짜는 로컬 달력 날짜라서 시간대 때문에 하루가 밀리지 않아요.
const rows = tasks.map((task, i) => {
  const date = new Date(2026, 2 + i, 5 + i * 3);
  const iso = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  return { id: i + 1, task, due: date, received: iso, updated: date.getTime() };
});
export const options = {
  columns: [
    { id: 'task', title: '업무', width: 150 },
    {
      id: 'due',
      title: '마감일 (Date)',
      kind: 'date',
      width: 150,
      editable: true,
      validation: {
        required: true,
        custom: (value) => value instanceof Date && value < new Date(2026, 0, 1)
          ? L('2026년 이후 날짜를 골라 주세요.', 'Pick a date in 2026 or later.')
          : null,
      },
    },
    { id: 'received', title: '접수일 (글자)', kind: 'date', width: 150, editable: true },
    { id: 'updated', title: '수정일 (밀리초)', kind: 'date', width: 150, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: '날짜 칸을 더블클릭하세요. 2026-03-05, 2026.3.5, 20260305처럼 직접 써도 돼요.',
    en: 'Double-click a date cell. You can also type it directly: 2026-03-05, 2026.3.5 or 20260305.',
  });
  const kinds = {
    due: 'Date 객체',
    received: '글자',
    updated: '숫자(밀리초)',
  };
  const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
  const offs = [
    api.on('editCommitted', (e) => log({
      ko: `${e.rowKey}번 줄 ${title(e.columnId)} → ${kinds[e.columnId] ?? ''}: ${String(e.newValue)}`,
      en: `Row ${e.rowKey} ${title(e.columnId)} → ${kinds[e.columnId] ?? ''}: ${String(e.newValue)}`,
    })),
    api.on('validationFailed', (e) => log({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  openCalendar: (api) => api.startEdit(1, 'due'),
};

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="openCalendar">Edit first due date</button>
  </div>
  <div id="grid" style="height: 280px"></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('openCalendar').addEventListener('click', () => actions.openCalendar(api));
example.js
const tasks = [
  'Review contract',
  'Check design draft',
  'Submit budget',
  'Distribute training material',
];
// A date column (kind: 'date') opens a date editor. Whatever shape the date has in the data, it comes back in that shape:
// a Date object returns as a Date, a 'YYYY-MM-DD' string as a string, and a millisecond number as a number. Dates are local calendar dates, so a time zone never shifts them by a day.
const rows = tasks.map((task, i) => {
  const date = new Date(2026, 2 + i, 5 + i * 3);
  const iso = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  return { id: i + 1, task, due: date, received: iso, updated: date.getTime() };
});
export const options = {
  columns: [
    { id: 'task', title: 'Task', width: 220 },
    {
      id: 'due',
      title: 'Due date (Date)',
      kind: 'date',
      width: 160,
      editable: true,
      validation: {
        required: true,
        custom: (value) => value instanceof Date && value < new Date(2026, 0, 1)
          ? 'Pick a date in 2026 or later.'
          : null,
      },
    },
    { id: 'received', title: 'Received (string)', kind: 'date', width: 160, editable: true },
    { id: 'updated', title: 'Updated (milliseconds)', kind: 'date', width: 180, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log('Double-click a date cell. You can also type it directly: 2026-03-05, 2026.3.5 or 20260305.');
  const kinds = {
    due: 'Date object',
    received: 'string',
    updated: 'number (milliseconds)',
  };
  const title = (id) => api.getColumns().find((c) => c.id === id)?.title ?? id;
  const offs = [
    api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${title(e.columnId)} → ${kinds[e.columnId] ?? ''}: ${String(e.newValue)}`)),
    api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  openCalendar: (api) => api.startEdit(1, 'due'),
};