고를 수 있는 날짜 제한하기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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));// 예제 틀이 알려 주는 페이지 언어(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());
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>고를 수 있는 날짜 제한하기</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(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 },
},
];
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(),
};
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();
};
}
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());
},
};
options.ariaLabel = "고를 수 있는 날짜 제한하기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
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));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.edit(api)}
>첫 줄 편집</button>
<select
aria-label="범위"
disabled={!api}
onChange={(event) => api && actions.range(api, event.target.value)}
>
<option value="none">제한 없음</option>
<option value="month">2026년 11월 안</option>
<option value="window">11월 10일~20일</option>
</select>
<select defaultValue="month"
aria-label="막을 날"
disabled={!api}
onChange={(event) => api && actions.block(api, event.target.value)}
>
<option value="none">없음</option>
<option value="weekends">주말</option>
<option value="holidays">11월 12일, 19일</option>
</select>
<select defaultValue="weekends"
aria-label="한 주 시작"
disabled={!api}
onChange={(event) => api && actions.weekStart(api, event.target.value)}
>
<option value="1">월요일</option>
<option value="0">일요일</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
// 예제 틀이 알려 주는 페이지 언어(ko/en)를 그리드 locale로 써요.
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// 페이지 언어가 바뀌면 그리드 locale도 따라 바꿔요. 해제 함수를 돌려줘요.
function followPageLanguage(api: GridApi<Row>): () => void {
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();
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// 고를 수 있는 날짜 범위. min·max도 'YYYY-MM-DD' 글자예요(포함해서 계산해요).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// 한국어 화면은 한국어 샘플·칸 제목을, 영어 화면은 영어를 써요.
const TEXT = {
ko: { task: '업무', due: '마감일', names: ['기획서 쓰기', '디자인 검토', '배포 준비', '회고'] },
en: {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
},
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT[pageLang()].names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT[pageLang()].names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT[pageLang()].names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT[pageLang()].names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.edit(api)">첫 줄 편집</button>
<select
aria-label="범위"
:disabled="!api"
@change="api && actions.range(api, ($event.target as HTMLSelectElement).value)"
>
<option value="none">제한 없음</option>
<option value="month" selected>2026년 11월 안</option>
<option value="window">11월 10일~20일</option>
</select>
<select
aria-label="막을 날"
:disabled="!api"
@change="api && actions.block(api, ($event.target as HTMLSelectElement).value)"
>
<option value="none">없음</option>
<option value="weekends" selected>주말</option>
<option value="holidays">11월 12일, 19일</option>
</select>
<select
aria-label="한 주 시작"
:disabled="!api"
@change="api && actions.weekStart(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>월요일</option>
<option value="0">일요일</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
// 예제 틀이 알려 주는 페이지 언어(ko/en)를 그리드 locale로 써요.
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// 페이지 언어가 바뀌면 그리드 locale도 따라 바꿔요. 해제 함수를 돌려줘요.
function followPageLanguage(api: GridApi<Row>): () => void {
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();
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// 고를 수 있는 날짜 범위. min·max도 'YYYY-MM-DD' 글자예요(포함해서 계산해요).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// 한국어 화면은 한국어 샘플·칸 제목을, 영어 화면은 영어를 써요.
const TEXT = {
ko: { task: '업무', due: '마감일', names: ['기획서 쓰기', '디자인 검토', '배포 준비', '회고'] },
en: {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
},
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT[pageLang()].names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT[pageLang()].names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT[pageLang()].names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT[pageLang()].names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.edit(api)"
>첫 줄 편집</button>
<select
aria-label="범위"
[disabled]="!api"
(change)="api && actions.range(api, $any($event.target).value)"
>
<option value="none">제한 없음</option>
<option value="month" selected>2026년 11월 안</option>
<option value="window">11월 10일~20일</option>
</select>
<select
aria-label="막을 날"
[disabled]="!api"
(change)="api && actions.block(api, $any($event.target).value)"
>
<option value="none">없음</option>
<option value="weekends" selected>주말</option>
<option value="holidays">11월 12일, 19일</option>
</select>
<select
aria-label="한 주 시작"
[disabled]="!api"
(change)="api && actions.weekStart(api, $any($event.target).value)"
>
<option value="1" selected>월요일</option>
<option value="0">일요일</option>
</select>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
// 예제 틀이 알려 주는 페이지 언어(ko/en)를 그리드 locale로 써요.
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// 페이지 언어가 바뀌면 그리드 locale도 따라 바꿔요. 해제 함수를 돌려줘요.
function followPageLanguage(api: GridApi<Row>): () => void {
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();
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// 고를 수 있는 날짜 범위. min·max도 'YYYY-MM-DD' 글자예요(포함해서 계산해요).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// 한국어 화면은 한국어 샘플·칸 제목을, 영어 화면은 영어를 써요.
const TEXT = {
ko: { task: '업무', due: '마감일', names: ['기획서 쓰기', '디자인 검토', '배포 준비', '회고'] },
en: {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
},
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT[pageLang()].names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT[pageLang()].names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT[pageLang()].names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT[pageLang()].names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<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>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));// 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());
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Limit which dates can be picked</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 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 },
},
];
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',
};
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();
};
}
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());
},
};
options.ariaLabel = "Limit which dates can be picked";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
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));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.edit(api)}
>Edit first row</button>
<select
aria-label="Range"
disabled={!api}
onChange={(event) => api && actions.range(api, event.target.value)}
>
<option value="none">No limit</option>
<option value="month">Within November 2026</option>
<option value="window">Nov 10 to Nov 20</option>
</select>
<select defaultValue="month"
aria-label="Blocked days"
disabled={!api}
onChange={(event) => api && actions.block(api, event.target.value)}
>
<option value="none">None</option>
<option value="weekends">Weekends</option>
<option value="holidays">Nov 12 and Nov 19</option>
</select>
<select defaultValue="weekends"
aria-label="Week starts on"
disabled={!api}
onChange={(event) => api && actions.weekStart(api, event.target.value)}
>
<option value="1">Monday</option>
<option value="0">Sunday</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// Pickable date range. min and max are 'YYYY-MM-DD' strings (inclusive).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// English column titles and sample task names.
const TEXT = {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT.names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT.names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT.names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT.names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: 'en',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.edit(api)">Edit first row</button>
<select
aria-label="Range"
:disabled="!api"
@change="api && actions.range(api, ($event.target as HTMLSelectElement).value)"
>
<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"
:disabled="!api"
@change="api && actions.block(api, ($event.target as HTMLSelectElement).value)"
>
<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"
:disabled="!api"
@change="api && actions.weekStart(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>Monday</option>
<option value="0">Sunday</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// Pickable date range. min and max are 'YYYY-MM-DD' strings (inclusive).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// English column titles and sample task names.
const TEXT = {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT.names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT.names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT.names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT.names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: 'en',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.edit(api)"
>Edit first row</button>
<select
aria-label="Range"
[disabled]="!api"
(change)="api && actions.range(api, $any($event.target).value)"
>
<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"
[disabled]="!api"
(change)="api && actions.block(api, $any($event.target).value)"
>
<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"
[disabled]="!api"
(change)="api && actions.weekStart(api, $any($event.target).value)"
>
<option value="1" selected>Monday</option>
<option value="0">Sunday</option>
</select>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
due: string;
}
type Range = 'none' | 'month' | 'window';
type Block = 'none' | 'weekends' | 'holidays';
// Pickable date range. min and max are 'YYYY-MM-DD' strings (inclusive).
const RANGES: Record<Range, { min?: string; max?: string }> = {
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: Record<Block, (date: string) => boolean> = {
none: () => false,
weekends: (date) => [0, 6].includes(new Date(`${date}T00:00:00`).getDay()),
holidays: (date) => HOLIDAYS.includes(date),
};
let range: Range = 'month';
let block: Block = 'weekends';
let weekStart: 0 | 1 = 1;
// English column titles and sample task names.
const TEXT = {
task: 'Task',
due: 'Due',
names: ['Write plan', 'Review design', 'Prepare release', 'Retrospective'],
};
const columns = (): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, task: TEXT.names[0] as string, due: '2026-11-10' },
{ id: 2, task: TEXT.names[1] as string, due: '2026-11-12' },
{ id: 3, task: TEXT.names[2] as string, due: '2026-11-20' },
{ id: 4, task: TEXT.names[3] as string, due: '2026-11-27' },
],
rowKey: 'id',
locale: 'en',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
range: (api: GridApi<Row>, value?: string) => {
range = (value as Range) in RANGES ? (value as Range) : 'none';
api.setColumns(columns());
},
block: (api: GridApi<Row>, value?: string) => {
block = (value as Block) in BLOCKS ? (value as Block) : 'none';
api.setColumns(columns());
},
weekStart: (api: GridApi<Row>, value?: string) => {
weekStart = value === '0' ? 0 : 1;
api.setColumns(columns());
},
};