달력으로 날짜 고르기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.
코드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="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>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));// 예제 틀이 알려 주는 페이지 언어(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)),
};<!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="weekStart">
<option value="1" selected>월요일</option>
<option value="0">일요일</option>
</select>
</div>
<div id="grid" style="height: 340px"></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() }));
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()), // 주말은 못 골라요
},
},
];
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(),
};
// 로그에는 화면에 보이는 글자가 아니라 저장되는 값 그대로 찍어요. 날짜 문자열 하나뿐이에요.
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();
};
}
const actions = {
edit: (api) => api.startEdit(1, 'due'),
// 컬럼 정의만 새로 주면 다음에 여는 달력부터 바뀌어요.
weekStart: (api, value) => api.setColumns(columns(value === '0' ? 0 : 1)),
};
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('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.weekStart(api, event.target.value)}
>
<option value="1">월요일</option>
<option value="0">일요일</option>
</select>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
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() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => watcher.disconnect();
}
// 값은 시간대 없는 'YYYY-MM-DD' 문자열이에요. 컬럼의 dateTime 옵션으로 달력을 정해요.
const columns = (weekStart: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// 컬럼 정의만 새로 주면 다음에 여는 달력부터 바뀌어요.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};버튼을 누르면 이 예제의 코드가 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.weekStart(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>월요일</option>
<option value="0">일요일</option>
</select>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
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() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => watcher.disconnect();
}
// 값은 시간대 없는 'YYYY-MM-DD' 문자열이에요. 컬럼의 dateTime 옵션으로 달력을 정해요.
const columns = (weekStart: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// 컬럼 정의만 새로 주면 다음에 여는 달력부터 바뀌어요.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};버튼을 누르면 이 예제의 코드가 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.weekStart(api, $any($event.target).value)"
>
<option value="1" selected>월요일</option>
<option value="0">일요일</option>
</select>
</div>
<mx-grid style="height: 340px" [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 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() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => watcher.disconnect();
}
// 값은 시간대 없는 'YYYY-MM-DD' 문자열이에요. 컬럼의 dateTime 옵션으로 달력을 정해요.
const columns = (weekStart: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// 컬럼 정의만 새로 주면 다음에 여는 달력부터 바뀌어요.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};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="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>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));// 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)),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pick a date with the calendar</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 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
},
},
];
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.
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();
};
}
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)),
};
options.ariaLabel = "Pick a date with the calendar";
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('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="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: 340 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
task: string;
due: string;
}
// 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: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// Passing new column definitions takes effect from the next time the calendar opens.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};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="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: 340px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
task: string;
due: string;
}
// 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: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// Passing new column definitions takes effect from the next time the calendar opens.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};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="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: 340px" [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 interface Row {
id: number;
task: string;
due: string;
}
// 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: 0 | 1): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.startEdit(1, 'due'),
// Passing new column definitions takes effect from the next time the calendar opens.
weekStart: (api: GridApi<Row>, value?: string) => api.setColumns(columns(value === '0' ? 0 : 1)),
};