시·초 간격과 고를 수 있는 시간Hour and second steps and allowed times
hourStep과 secondStep으로 시·초 목록 간격을 줄이고, allowedHours·allowedMinutes로 고를 수 있는 시간을 정해요. 나머지는 흐리게 막히고 직접 입력해도 검증이 막아요.hourStep and secondStep thin out the hour and second lists, and allowedHours and allowedMinutes choose the selectable times. The rest are dimmed, and validation also refuses them when typed.
코드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="hour">
<option value="1" selected>1시간</option>
<option value="3">3시간</option>
<option value="6">6시간</option>
</select>
<select aria-label="초 간격" id="second">
<option value="1" selected>1초</option>
<option value="15">15초</option>
<option value="30">30초</option>
</select>
<select aria-label="허용 시간" id="allowed">
<option value="all" selected>모두</option>
<option value="work">근무 시간만</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('hour').addEventListener('change', (event) => actions.hour(api, event.target.value));
document.getElementById('second').addEventListener('change', (event) => actions.second(api, event.target.value));
document.getElementById('allowed').addEventListener('change', (event) => actions.allowed(api, event.target.value));const pageLang = () => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// hourStep·secondStep은 목록 간격이고(분 간격은 step), allowedHours·allowedMinutes는 고를 수 있는 시·분이에요.
// 허용되지 않은 시각은 목록에서 흐리게 막히고 직접 써도 검증이 막아요.
const columns = (hour, second, work) => [
{ id: 'name', title: '일정', width: 150 },
{
id: 'at',
title: '시각',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current) => current.setColumns(columns(state.hour, state.second, state.work));
export const options = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: '회의', at: '09:30:00' },
{ id: 2, name: '점심', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current, log) {
const off = current.on('editCommitted', ({ rowKey, newValue }) => log(`row ${rowKey} = ${String(newValue)}`));
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current) => current.startEdit(1, 'at'),
hour: (current, value) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current, value) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current, value) => {
state.work = value === 'work';
apply(current);
},
};<!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="hour">
<option value="1" selected>1시간</option>
<option value="3">3시간</option>
<option value="6">6시간</option>
</select>
<select aria-label="초 간격" id="second">
<option value="1" selected>1초</option>
<option value="15">15초</option>
<option value="30">30초</option>
</select>
<select aria-label="허용 시간" id="allowed">
<option value="all" selected>모두</option>
<option value="work">근무 시간만</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>
const pageLang = () => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// hourStep·secondStep은 목록 간격이고(분 간격은 step), allowedHours·allowedMinutes는 고를 수 있는 시·분이에요.
// 허용되지 않은 시각은 목록에서 흐리게 막히고 직접 써도 검증이 막아요.
const columns = (hour, second, work) => [
{ id: 'name', title: '일정', width: 150 },
{
id: 'at',
title: '시각',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current) => current.setColumns(columns(state.hour, state.second, state.work));
const options = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: '회의', at: '09:30:00' },
{ id: 2, name: '점심', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
function setup(current, log) {
const off = current.on('editCommitted', ({ rowKey, newValue }) => log(`row ${rowKey} = ${String(newValue)}`));
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
const actions = {
edit: (current) => current.startEdit(1, 'at'),
hour: (current, value) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current, value) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current, value) => {
state.work = value === 'work';
apply(current);
},
};
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('hour').addEventListener('change', (event) => actions.hour(api, event.target.value));
document.getElementById('second').addEventListener('change', (event) => actions.second(api, event.target.value));
document.getElementById('allowed').addEventListener('change', (event) => actions.allowed(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.hour(api, event.target.value)}
>
<option value="1">1시간</option>
<option value="3">3시간</option>
<option value="6">6시간</option>
</select>
<select defaultValue="1"
aria-label="초 간격"
disabled={!api}
onChange={(event) => api && actions.second(api, event.target.value)}
>
<option value="1">1초</option>
<option value="15">15초</option>
<option value="30">30초</option>
</select>
<select defaultValue="1"
aria-label="허용 시간"
disabled={!api}
onChange={(event) => api && actions.allowed(api, event.target.value)}
>
<option value="all">모두</option>
<option value="work">근무 시간만</option>
</select>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// hourStep·secondStep은 목록 간격이고(분 간격은 step), allowedHours·allowedMinutes는 고를 수 있는 시·분이에요.
// 허용되지 않은 시각은 목록에서 흐리게 막히고 직접 써도 검증이 막아요.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: '일정', width: 150 },
{
id: 'at',
title: '시각',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: '회의', at: '09:30:00' },
{ id: 2, name: '점심', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};버튼을 누르면 이 예제의 코드가 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.hour(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>1시간</option>
<option value="3">3시간</option>
<option value="6">6시간</option>
</select>
<select
aria-label="초 간격"
:disabled="!api"
@change="api && actions.second(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>1초</option>
<option value="15">15초</option>
<option value="30">30초</option>
</select>
<select
aria-label="허용 시간"
:disabled="!api"
@change="api && actions.allowed(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>모두</option>
<option value="work">근무 시간만</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;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// hourStep·secondStep은 목록 간격이고(분 간격은 step), allowedHours·allowedMinutes는 고를 수 있는 시·분이에요.
// 허용되지 않은 시각은 목록에서 흐리게 막히고 직접 써도 검증이 막아요.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: '일정', width: 150 },
{
id: 'at',
title: '시각',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: '회의', at: '09:30:00' },
{ id: 2, name: '점심', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};버튼을 누르면 이 예제의 코드가 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.hour(api, $any($event.target).value)"
>
<option value="1" selected>1시간</option>
<option value="3">3시간</option>
<option value="6">6시간</option>
</select>
<select
aria-label="초 간격"
[disabled]="!api"
(change)="api && actions.second(api, $any($event.target).value)"
>
<option value="1" selected>1초</option>
<option value="15">15초</option>
<option value="30">30초</option>
</select>
<select
aria-label="허용 시간"
[disabled]="!api"
(change)="api && actions.allowed(api, $any($event.target).value)"
>
<option value="all" selected>모두</option>
<option value="work">근무 시간만</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;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => (document.documentElement.dataset.lang === 'en' ? 'en' : 'ko');
// hourStep·secondStep은 목록 간격이고(분 간격은 step), allowedHours·allowedMinutes는 고를 수 있는 시·분이에요.
// 허용되지 않은 시각은 목록에서 흐리게 막히고 직접 써도 검증이 막아요.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: '일정', width: 150 },
{
id: 'at',
title: '시각',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: '회의', at: '09:30:00' },
{ id: 2, name: '점심', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};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="Hour step" id="hour">
<option value="1" selected>1 h</option>
<option value="3">3 h</option>
<option value="6">6 h</option>
</select>
<select aria-label="Second step" id="second">
<option value="1" selected>1 s</option>
<option value="15">15 s</option>
<option value="30">30 s</option>
</select>
<select aria-label="Allowed times" id="allowed">
<option value="all" selected>All</option>
<option value="work">Work hours only</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('hour').addEventListener('change', (event) => actions.hour(api, event.target.value));
document.getElementById('second').addEventListener('change', (event) => actions.second(api, event.target.value));
document.getElementById('allowed').addEventListener('change', (event) => actions.allowed(api, event.target.value));const pageLang = () => 'en';
// hourStep and secondStep are list steps (the minute step is step); allowedHours and allowedMinutes are the selectable hours and minutes.
// Times that are not allowed are dimmed in the list, and validation refuses them when typed.
const columns = (hour, second, work) => [
{ id: 'name', title: 'Event', width: 150 },
{
id: 'at',
title: 'Time',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current) => current.setColumns(columns(state.hour, state.second, state.work));
export const options = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: 'Meeting', at: '09:30:00' },
{ id: 2, name: 'Lunch', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current, log) {
const off = current.on('editCommitted', ({ rowKey, newValue }) => log(`row ${rowKey} = ${String(newValue)}`));
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current) => current.startEdit(1, 'at'),
hour: (current, value) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current, value) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current, value) => {
state.work = value === 'work';
apply(current);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hour and second steps and allowed times</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="edit">Edit first row</button>
<select aria-label="Hour step" id="hour">
<option value="1" selected>1 h</option>
<option value="3">3 h</option>
<option value="6">6 h</option>
</select>
<select aria-label="Second step" id="second">
<option value="1" selected>1 s</option>
<option value="15">15 s</option>
<option value="30">30 s</option>
</select>
<select aria-label="Allowed times" id="allowed">
<option value="all" selected>All</option>
<option value="work">Work hours only</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>
const pageLang = () => 'en';
// hourStep and secondStep are list steps (the minute step is step); allowedHours and allowedMinutes are the selectable hours and minutes.
// Times that are not allowed are dimmed in the list, and validation refuses them when typed.
const columns = (hour, second, work) => [
{ id: 'name', title: 'Event', width: 150 },
{
id: 'at',
title: 'Time',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current) => current.setColumns(columns(state.hour, state.second, state.work));
const options = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: 'Meeting', at: '09:30:00' },
{ id: 2, name: 'Lunch', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
function setup(current, log) {
const off = current.on('editCommitted', ({ rowKey, newValue }) => log(`row ${rowKey} = ${String(newValue)}`));
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
const actions = {
edit: (current) => current.startEdit(1, 'at'),
hour: (current, value) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current, value) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current, value) => {
state.work = value === 'work';
apply(current);
},
};
options.ariaLabel = "Hour and second steps and allowed times";
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('hour').addEventListener('change', (event) => actions.hour(api, event.target.value));
document.getElementById('second').addEventListener('change', (event) => actions.second(api, event.target.value));
document.getElementById('allowed').addEventListener('change', (event) => actions.allowed(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="Hour step"
disabled={!api}
onChange={(event) => api && actions.hour(api, event.target.value)}
>
<option value="1">1 h</option>
<option value="3">3 h</option>
<option value="6">6 h</option>
</select>
<select defaultValue="1"
aria-label="Second step"
disabled={!api}
onChange={(event) => api && actions.second(api, event.target.value)}
>
<option value="1">1 s</option>
<option value="15">15 s</option>
<option value="30">30 s</option>
</select>
<select defaultValue="1"
aria-label="Allowed times"
disabled={!api}
onChange={(event) => api && actions.allowed(api, event.target.value)}
>
<option value="all">All</option>
<option value="work">Work hours only</option>
</select>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => 'en';
// hourStep and secondStep are list steps (the minute step is step); allowedHours and allowedMinutes are the selectable hours and minutes.
// Times that are not allowed are dimmed in the list, and validation refuses them when typed.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: 'Event', width: 150 },
{
id: 'at',
title: 'Time',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: 'Meeting', at: '09:30:00' },
{ id: 2, name: 'Lunch', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};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="Hour step"
:disabled="!api"
@change="api && actions.hour(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>1 h</option>
<option value="3">3 h</option>
<option value="6">6 h</option>
</select>
<select
aria-label="Second step"
:disabled="!api"
@change="api && actions.second(api, ($event.target as HTMLSelectElement).value)"
>
<option value="1" selected>1 s</option>
<option value="15">15 s</option>
<option value="30">30 s</option>
</select>
<select
aria-label="Allowed times"
:disabled="!api"
@change="api && actions.allowed(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>All</option>
<option value="work">Work hours only</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;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => 'en';
// hourStep and secondStep are list steps (the minute step is step); allowedHours and allowedMinutes are the selectable hours and minutes.
// Times that are not allowed are dimmed in the list, and validation refuses them when typed.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: 'Event', width: 150 },
{
id: 'at',
title: 'Time',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: 'Meeting', at: '09:30:00' },
{ id: 2, name: 'Lunch', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};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="Hour step"
[disabled]="!api"
(change)="api && actions.hour(api, $any($event.target).value)"
>
<option value="1" selected>1 h</option>
<option value="3">3 h</option>
<option value="6">6 h</option>
</select>
<select
aria-label="Second step"
[disabled]="!api"
(change)="api && actions.second(api, $any($event.target).value)"
>
<option value="1" selected>1 s</option>
<option value="15">15 s</option>
<option value="30">30 s</option>
</select>
<select
aria-label="Allowed times"
[disabled]="!api"
(change)="api && actions.allowed(api, $any($event.target).value)"
>
<option value="all" selected>All</option>
<option value="work">Work hours only</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;
name: string;
at: string;
}
const pageLang = (): 'ko' | 'en' => 'en';
// hourStep and secondStep are list steps (the minute step is step); allowedHours and allowedMinutes are the selectable hours and minutes.
// Times that are not allowed are dimmed in the list, and validation refuses them when typed.
const columns = (hour: number, second: number, work: boolean): ColumnDef<Row>[] => [
{ id: 'name', title: 'Event', width: 150 },
{
id: 'at',
title: 'Time',
kind: 'time',
width: 150,
editable: true,
dateTime: {
seconds: true,
hour12: false,
hourStep: hour,
secondStep: second,
...(work
? { allowedHours: [9, 10, 11, 12, 13, 14, 15, 16, 17], allowedMinutes: [0, 30] }
: {}),
},
},
];
const state = { hour: 1, second: 1, work: false };
const apply = (current: GridApi<Row>): void =>
current.setColumns(columns(state.hour, state.second, state.work));
export const options: GridOptions<Row> = {
columns: columns(1, 1, false),
rows: [
{ id: 1, name: 'Meeting', at: '09:30:00' },
{ id: 2, name: 'Lunch', at: '12:00:00' },
],
rowKey: 'id',
locale: pageLang(),
};
export function setup(current: GridApi<Row>, log: (message: string) => void) {
const off = current.on('editCommitted', ({ rowKey, newValue }) =>
log(`row ${rowKey} = ${String(newValue)}`),
);
const fail = current.on('validationFailed', ({ message }) => log(message));
const watcher = new MutationObserver(() => current.setOptions({ locale: pageLang() }));
watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
return () => {
off();
fail();
watcher.disconnect();
};
}
export const actions = {
edit: (current: GridApi<Row>) => current.startEdit(1, 'at'),
hour: (current: GridApi<Row>, value?: string) => {
state.hour = Number(value) || 1;
apply(current);
},
second: (current: GridApi<Row>, value?: string) => {
state.second = Number(value) || 1;
apply(current);
},
allowed: (current: GridApi<Row>, value?: string) => {
state.work = value === 'work';
apply(current);
},
};