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

달력으로 날짜 고르기Pick a date with the calendar

날짜 컬럼(kind: date)을 고치면 달력이 열려요. 주 번호, 한 주 시작 요일, 고를 수 없는 날(주말)을 옵션으로 정해요. 저장되는 값은 'YYYY-MM-DD' 글자 하나예요.Editing a date column opens a calendar. Week numbers, the first day of the week and days that cannot be picked (weekends) are options. The stored value is one 'YYYY-MM-DD' string.

입문Beginner
직접 써 보기Live preview달력으로 날짜 고르기Pick a date with the 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="edit">첫 줄 편집</button>
    <select aria-label="한 주 시작" id="weekStart">
      <option value="1" selected>월요일</option>
      <option value="0">일요일</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('weekStart').addEventListener('change', (event) => actions.weekStart(api, event.target.value));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)를 그리드 locale로 써요. 샘플 데이터는 한국어 그대로예요.
const pageLang = () => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// 페이지 언어가 바뀌면 그리드 locale도 따라 바꿔요. 해제 함수를 돌려줘요.
function followPageLanguage(api) {
  const watcher = new MutationObserver(() => api.setOptions({ locale: pageLang() }));
  watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
  return () => watcher.disconnect();
}
// 값은 시간대 없는 'YYYY-MM-DD' 문자열이에요. 컬럼의 dateTime 옵션으로 달력을 정해요.
const columns = (weekStart) => [
  { id: 'task', title: '할 일', width: 160 },
  {
    id: 'due',
    title: '마감일',
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: {
      min: '2026-01-01', // 이 날짜 앞은 고를 수 없어요(입력해도 검증이 막아요)
      weekStart, // 0 일요일, 1 월요일부터 시작
      weekNumbers: true, // 주 번호(ISO 8601)
      isDateDisabled: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()), // 주말은 못 골라요
    },
  },
];
export const options = {
  columns: columns(1),
  rows: [
    { id: 1, task: '기획서 쓰기', due: '2026-11-10' },
    { id: 2, task: '디자인 검토', due: '2026-11-12' },
    { id: 3, task: '배포 준비', due: '2026-11-20' },
    { id: 4, task: '회고', due: '2026-11-27' },
  ],
  rowKey: 'id',
  locale: pageLang(),
};
// 로그에는 화면에 보이는 글자가 아니라 저장되는 값 그대로 찍어요. 날짜 문자열 하나뿐이에요.
export function setup(api, log) {
  const off = api.on('editCommitted', ({ rowKey, columnId, newValue }) => log(`row ${rowKey} · ${columnId} = ${String(newValue)}`));
  const fail = api.on('validationFailed', ({ message }) => log(message));
  const stop = followPageLanguage(api);
  return () => {
    off();
    fail();
    stop();
  };
}
export const actions = {
  edit: (api) => api.startEdit(1, 'due'),
  // 컬럼 정의만 새로 주면 다음에 여는 달력부터 바뀌어요.
  weekStart: (api, value) => api.setColumns(columns(value === '0' ? 0 : 1)),
};

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="Week starts on" id="weekStart">
      <option value="1" selected>Monday</option>
      <option value="0">Sunday</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('weekStart').addEventListener('change', (event) => actions.weekStart(api, event.target.value));
example.js
// The grid locale is English.
// The value is a 'YYYY-MM-DD' string without a time zone. The column's dateTime option configures the calendar.
const columns = (weekStart) => [
  { id: 'task', title: 'To do', width: 160 },
  {
    id: 'due',
    title: 'Due',
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: {
      min: '2026-01-01', // Dates before this cannot be picked (validation also blocks typed input)
      weekStart, // 0 starts on Sunday, 1 on Monday
      weekNumbers: true, // Week numbers (ISO 8601)
      isDateDisabled: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()), // Weekends cannot be picked
    },
  },
];
export const options = {
  columns: columns(1),
  rows: [
    { id: 1, task: 'Write plan', due: '2026-11-10' },
    { id: 2, task: 'Review design', due: '2026-11-12' },
    { id: 3, task: 'Prepare release', due: '2026-11-20' },
    { id: 4, task: 'Retrospective', due: '2026-11-27' },
  ],
  rowKey: 'id',
  locale: 'en',
};
// The log shows the stored value, not the displayed text. It is just one date string.
export function setup(api, log) {
  const off = api.on('editCommitted', ({ rowKey, columnId, newValue }) => log(`row ${rowKey} · ${columnId} = ${String(newValue)}`));
  const fail = api.on('validationFailed', ({ message }) => log(message));
  return () => {
    off();
    fail();
  };
}
export const actions = {
  edit: (api) => api.startEdit(1, 'due'),
  // Passing new column definitions takes effect from the next time the calendar opens.
  weekStart: (api, value) => api.setColumns(columns(value === '0' ? 0 : 1)),
};