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

고를 수 있는 날짜 제한하기Limit which dates can be picked

날짜 컬럼의 dateTime 옵션으로 고를 수 있는 범위(min, max), 막을 날(isDateDisabled), 한 주 시작 요일(weekStart)을 정해요. 달력과 직접 입력 모두 같은 규칙으로 막혀요.The dateTime option of a date column sets the pickable range (min, max), the days to block (isDateDisabled) and the first day of the week (weekStart). The calendar and typed input follow the same rules.

활용Intermediate
직접 써 보기Live preview고를 수 있는 날짜 제한하기Limit which dates can be picked

코드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="range">
      <option value="none">제한 없음</option>
      <option value="month" selected>2026년 11월 안</option>
      <option value="window">11월 10일~20일</option>
    </select>
    <select aria-label="막을 날" id="block">
      <option value="none">없음</option>
      <option value="weekends" selected>주말</option>
      <option value="holidays">11월 12일, 19일</option>
    </select>
    <select aria-label="한 주 시작" id="weekStart">
      <option value="1" selected>월요일</option>
      <option value="0">일요일</option>
    </select>
  </div>
  <div id="grid" style="height: 300px"></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('range').addEventListener('change', (event) => actions.range(api, event.target.value));
document.getElementById('block').addEventListener('change', (event) => actions.block(api, event.target.value));
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() });
    api.setColumns(columns()); // 칸 제목과 업무 이름도 페이지 언어로 바꿔요(고친 마감일 값은 그대로 두고 변경 표시만 지워요)
    api.setRows(api
      .getRows()
      .map((row) => ({ ...row, task: TEXT[pageLang()].names[row.id - 1] ?? row.task })));
  });
  watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
  return () => watcher.disconnect();
}
// 고를 수 있는 날짜 범위. min·max도 'YYYY-MM-DD' 글자예요(포함해서 계산해요).
const RANGES = {
  none: {},
  month: { min: '2026-11-01', max: '2026-11-30' },
  window: { min: '2026-11-10', max: '2026-11-20' },
};
// 막을 날짜. 함수는 'YYYY-MM-DD' 글자를 받아 막을지 돌려줘요. 예외를 던지면 그 날은 고를 수 있는 날로 봐요.
const HOLIDAYS = ['2026-11-12', '2026-11-19'];
const BLOCKS = {
  none: () => false,
  weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
  holidays: (date) => HOLIDAYS.includes(date),
};
let range = 'month';
let block = 'weekends';
let weekStart = 1;
// 한국어 화면은 한국어 샘플·칸 제목을, 영어 화면은 영어를 써요.
const TEXT = {
  ko: { task: '업무', due: '마감일', names: ['기획서 쓰기', '디자인 검토', '배포 준비', '회고'] },
  en: {
    task: 'Task',
    due: 'Due',
    names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
  },
};
const columns = () => [
  { id: 'task', title: TEXT[pageLang()].task, width: 130 },
  {
    id: 'due',
    title: TEXT[pageLang()].due,
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: { ...RANGES[range], isDateDisabled: BLOCKS[block], weekStart, weekNumbers: true },
  },
];
export const options = {
  columns: columns(),
  rows: [
    { id: 1, task: TEXT[pageLang()].names[0], due: '2026-11-10' },
    { id: 2, task: TEXT[pageLang()].names[1], due: '2026-11-12' },
    { id: 3, task: TEXT[pageLang()].names[2], due: '2026-11-20' },
    { id: 4, task: TEXT[pageLang()].names[3], due: '2026-11-27' },
  ],
  rowKey: 'id',
  locale: pageLang(),
};
export function setup(api, log) {
  const off = api.on('editCommitted', ({ rowKey, newValue }) => log({
    ko: `${rowKey}번 줄 마감일 = ${String(newValue)}`,
    en: `Row ${rowKey} due date = ${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'),
  range: (api, value) => {
    range = value in RANGES ? value : 'none';
    api.setColumns(columns());
  },
  block: (api, value) => {
    block = value in BLOCKS ? value : 'none';
    api.setColumns(columns());
  },
  weekStart: (api, value) => {
    weekStart = value === '0' ? 0 : 1;
    api.setColumns(columns());
  },
};

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="Range" id="range">
      <option value="none">No limit</option>
      <option value="month" selected>Within November 2026</option>
      <option value="window">Nov 10 to Nov 20</option>
    </select>
    <select aria-label="Blocked days" id="block">
      <option value="none">None</option>
      <option value="weekends" selected>Weekends</option>
      <option value="holidays">Nov 12 and Nov 19</option>
    </select>
    <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: 300px"></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('range').addEventListener('change', (event) => actions.range(api, event.target.value));
document.getElementById('block').addEventListener('change', (event) => actions.block(api, event.target.value));
document.getElementById('weekStart').addEventListener('change', (event) => actions.weekStart(api, event.target.value));
example.js
// Pickable date range. min and max are 'YYYY-MM-DD' strings (inclusive).
const RANGES = {
  none: {},
  month: { min: '2026-11-01', max: '2026-11-30' },
  window: { min: '2026-11-10', max: '2026-11-20' },
};
// Days to block. The function receives a 'YYYY-MM-DD' string and returns whether to block it. If it throws, that day is treated as pickable.
const HOLIDAYS = ['2026-11-12', '2026-11-19'];
const BLOCKS = {
  none: () => false,
  weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
  holidays: (date) => HOLIDAYS.includes(date),
};
let range = 'month';
let block = 'weekends';
let weekStart = 1;
// English column titles and sample task names.
const TEXT = {
  task: 'Task',
  due: 'Due',
  names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
};
const columns = () => [
  { id: 'task', title: TEXT.task, width: 150 },
  {
    id: 'due',
    title: TEXT.due,
    kind: 'date',
    width: 170,
    editable: true,
    dateTime: { ...RANGES[range], isDateDisabled: BLOCKS[block], weekStart, weekNumbers: true },
  },
];
export const options = {
  columns: columns(),
  rows: [
    { id: 1, task: TEXT.names[0], due: '2026-11-10' },
    { id: 2, task: TEXT.names[1], due: '2026-11-12' },
    { id: 3, task: TEXT.names[2], due: '2026-11-20' },
    { id: 4, task: TEXT.names[3], due: '2026-11-27' },
  ],
  rowKey: 'id',
  locale: 'en',
};
export function setup(api, log) {
  const off = api.on('editCommitted', ({ rowKey, newValue }) => log(`Row ${rowKey} due date = ${String(newValue)}`));
  // Typing a blocked value shows the reason. Clicking a blocked day in the calendar is silently ignored.
  const fail = api.on('validationFailed', ({ message }) => log(message));
  return () => {
    off();
    fail();
  };
}
export const actions = {
  edit: (api) => api.startEdit(1, 'due'),
  range: (api, value) => {
    range = value in RANGES ? value : 'none';
    api.setColumns(columns());
  },
  block: (api, value) => {
    block = value in BLOCKS ? value : 'none';
    api.setColumns(columns());
  },
  weekStart: (api, value) => {
    weekStart = value === '0' ? 0 : 1;
    api.setColumns(columns());
  },
};