YYYYMMDD로 저장된 날짜 다루기Work with dates stored as YYYYMMDD
format.date.stored를 알려 주면 행 데이터가 20260305 같은 문자열이어도 달력, 정렬, 검증, 붙여넣기가 표준 날짜로 동작하고 쓸 때만 저장 모양으로 바뀌어요.With format.date.stored the calendar, sort, validation and paste work on a standard date even when the row data holds strings like 20260305; only the write converts back to the stored shape.
코드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>
<button type="button" id="paste">날짜 붙여넣기</button>
<button type="button" id="fill">코드로 쓰기</button>
</div>
<div id="grid" style="height: 220px"></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('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));// 서버가 날짜를 'YYYYMMDD' 문자열로 주고받는 경우예요. stored를 알려 주면 달력·정렬·검증은 표준 날짜로 동작하고
// 행에는 저장 모양('20260305')으로 쓰여요.
const rows = [
{ id: 1, title: '계약', ymd: '20260305' },
{ id: 2, title: '납품', ymd: '20240229' },
{ id: 3, title: '정산', ymd: '20250101' },
{ id: 4, title: '미정', ymd: null },
];
export const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'title', title: '일', width: 100 },
{
id: 'ymd',
title: '날짜',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'YYYY년 M월 D일', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api, log) {
const off = [
api.on('editCommitted', (e) => log({
ko: `확정: ${String(e.oldValue)} → ${String(e.newValue)} (행에는 ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
en: `Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
})),
api.on('cellsPasted', (e) => log({
ko: `붙여넣기: ${e.pasted}칸, 건너뜀 ${e.skipped}칸`,
en: `Paste: ${e.pasted} cells, ${e.skipped} skipped`,
})),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api) => api.startEdit(1, 'ymd'),
paste: (api) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api) => api.setCellValue(3, 'ymd', '2030-12-24'),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>YYYYMMDD로 저장된 날짜 다루기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="edit">날짜 편집</button>
<button type="button" id="paste">날짜 붙여넣기</button>
<button type="button" id="fill">코드로 쓰기</button>
</div>
<div id="grid" style="height: 220px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 서버가 날짜를 'YYYYMMDD' 문자열로 주고받는 경우예요. stored를 알려 주면 달력·정렬·검증은 표준 날짜로 동작하고
// 행에는 저장 모양('20260305')으로 쓰여요.
const rows = [
{ id: 1, title: '계약', ymd: '20260305' },
{ id: 2, title: '납품', ymd: '20240229' },
{ id: 3, title: '정산', ymd: '20250101' },
{ id: 4, title: '미정', ymd: null },
];
const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'title', title: '일', width: 100 },
{
id: 'ymd',
title: '날짜',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'YYYY년 M월 D일', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
function setup(api, log) {
const off = [
api.on('editCommitted', (e) => log({
ko: `확정: ${String(e.oldValue)} → ${String(e.newValue)} (행에는 ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
en: `Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
})),
api.on('cellsPasted', (e) => log({
ko: `붙여넣기: ${e.pasted}칸, 건너뜀 ${e.skipped}칸`,
en: `Paste: ${e.pasted} cells, ${e.skipped} skipped`,
})),
];
return () => off.forEach((fn) => fn());
}
const actions = {
edit: (api) => api.startEdit(1, 'ymd'),
paste: (api) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api) => api.setCellValue(3, 'ymd', '2030-12-24'),
};
options.ariaLabel = "YYYYMMDD로 저장된 날짜 다루기";
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('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
</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>
<button
type="button"
disabled={!api}
onClick={() => api && actions.paste(api)}
>날짜 붙여넣기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>코드로 쓰기</button>
</div>
<Grid style={{ height: 220 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// 서버가 날짜를 'YYYYMMDD' 문자열로 주고받는 경우예요. stored를 알려 주면 달력·정렬·검증은 표준 날짜로 동작하고
// 행에는 저장 모양('20260305')으로 쓰여요.
const rows: Row[] = [
{ id: 1, title: '계약', ymd: '20260305' },
{ id: 2, title: '납품', ymd: '20240229' },
{ id: 3, title: '정산', ymd: '20250101' },
{ id: 4, title: '미정', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'title', title: '일', width: 100 },
{
id: 'ymd',
title: '날짜',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'YYYY년 M월 D일', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log({
ko: `확정: ${String(e.oldValue)} → ${String(e.newValue)} (행에는 ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
en: `Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
}),
),
api.on('cellsPasted', (e) =>
log({
ko: `붙여넣기: ${e.pasted}칸, 건너뜀 ${e.skipped}칸`,
en: `Paste: ${e.pasted} cells, ${e.skipped} skipped`,
}),
),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};버튼을 누르면 이 예제의 코드가 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>
<button type="button" :disabled="!api" @click="api && actions.paste(api)">날짜 붙여넣기</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">코드로 쓰기</button>
</div>
<Grid style="height: 220px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// 서버가 날짜를 'YYYYMMDD' 문자열로 주고받는 경우예요. stored를 알려 주면 달력·정렬·검증은 표준 날짜로 동작하고
// 행에는 저장 모양('20260305')으로 쓰여요.
const rows: Row[] = [
{ id: 1, title: '계약', ymd: '20260305' },
{ id: 2, title: '납품', ymd: '20240229' },
{ id: 3, title: '정산', ymd: '20250101' },
{ id: 4, title: '미정', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'title', title: '일', width: 100 },
{
id: 'ymd',
title: '날짜',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'YYYY년 M월 D일', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log({
ko: `확정: ${String(e.oldValue)} → ${String(e.newValue)} (행에는 ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
en: `Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
}),
),
api.on('cellsPasted', (e) =>
log({
ko: `붙여넣기: ${e.pasted}칸, 건너뜀 ${e.skipped}칸`,
en: `Paste: ${e.pasted} cells, ${e.skipped} skipped`,
}),
),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};버튼을 누르면 이 예제의 코드가 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>
<button
type="button"
[disabled]="!api"
(click)="api && actions.paste(api)"
>날짜 붙여넣기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>코드로 쓰기</button>
</div>
<mx-grid style="height: 220px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// 서버가 날짜를 'YYYYMMDD' 문자열로 주고받는 경우예요. stored를 알려 주면 달력·정렬·검증은 표준 날짜로 동작하고
// 행에는 저장 모양('20260305')으로 쓰여요.
const rows: Row[] = [
{ id: 1, title: '계약', ymd: '20260305' },
{ id: 2, title: '납품', ymd: '20240229' },
{ id: 3, title: '정산', ymd: '20250101' },
{ id: 4, title: '미정', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'title', title: '일', width: 100 },
{
id: 'ymd',
title: '날짜',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'YYYY년 M월 D일', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log({
ko: `확정: ${String(e.oldValue)} → ${String(e.newValue)} (행에는 ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
en: `Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
}),
),
api.on('cellsPasted', (e) =>
log({
ko: `붙여넣기: ${e.pasted}칸, 건너뜀 ${e.skipped}칸`,
en: `Paste: ${e.pasted} cells, ${e.skipped} skipped`,
}),
),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};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 date</button>
<button type="button" id="paste">Paste a date</button>
<button type="button" id="fill">Write from code</button>
</div>
<div id="grid" style="height: 220px"></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('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));// The server sends and receives dates as 'YYYYMMDD' strings. With stored declared, the calendar, sort and validation
// work on a standard date, while the row is written in the stored shape ('20260305').
const rows = [
{ id: 1, title: 'Contract', ymd: '20260305' },
{ id: 2, title: 'Delivery', ymd: '20240229' },
{ id: 3, title: 'Settlement', ymd: '20250101' },
{ id: 4, title: 'TBD', ymd: null },
];
export const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'title', title: 'Event', width: 100 },
{
id: 'ymd',
title: 'Date',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'MM/DD/YYYY', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api, log) {
const off = [
api.on('editCommitted', (e) => log(`Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`)),
api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells, ${e.skipped} skipped`)),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api) => api.startEdit(1, 'ymd'),
paste: (api) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api) => api.setCellValue(3, 'ymd', '2030-12-24'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Work with dates stored as YYYYMMDD</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="edit">Edit date</button>
<button type="button" id="paste">Paste a date</button>
<button type="button" id="fill">Write from code</button>
</div>
<div id="grid" style="height: 220px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// The server sends and receives dates as 'YYYYMMDD' strings. With stored declared, the calendar, sort and validation
// work on a standard date, while the row is written in the stored shape ('20260305').
const rows = [
{ id: 1, title: 'Contract', ymd: '20260305' },
{ id: 2, title: 'Delivery', ymd: '20240229' },
{ id: 3, title: 'Settlement', ymd: '20250101' },
{ id: 4, title: 'TBD', ymd: null },
];
const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'title', title: 'Event', width: 100 },
{
id: 'ymd',
title: 'Date',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'MM/DD/YYYY', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
function setup(api, log) {
const off = [
api.on('editCommitted', (e) => log(`Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`)),
api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells, ${e.skipped} skipped`)),
];
return () => off.forEach((fn) => fn());
}
const actions = {
edit: (api) => api.startEdit(1, 'ymd'),
paste: (api) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api) => api.setCellValue(3, 'ymd', '2030-12-24'),
};
options.ariaLabel = "Work with dates stored as YYYYMMDD";
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('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
</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 date</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.paste(api)}
>Paste a date</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>Write from code</button>
</div>
<Grid style={{ height: 220 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// The server sends and receives dates as 'YYYYMMDD' strings. With stored declared, the calendar, sort and validation
// work on a standard date, while the row is written in the stored shape ('20260305').
const rows: Row[] = [
{ id: 1, title: 'Contract', ymd: '20260305' },
{ id: 2, title: 'Delivery', ymd: '20240229' },
{ id: 3, title: 'Settlement', ymd: '20250101' },
{ id: 4, title: 'TBD', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'title', title: 'Event', width: 100 },
{
id: 'ymd',
title: 'Date',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'MM/DD/YYYY', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log(
`Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
),
),
api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells, ${e.skipped} skipped`)),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};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 date</button>
<button type="button" :disabled="!api" @click="api && actions.paste(api)">Paste a date</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">Write from code</button>
</div>
<Grid style="height: 220px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// The server sends and receives dates as 'YYYYMMDD' strings. With stored declared, the calendar, sort and validation
// work on a standard date, while the row is written in the stored shape ('20260305').
const rows: Row[] = [
{ id: 1, title: 'Contract', ymd: '20260305' },
{ id: 2, title: 'Delivery', ymd: '20240229' },
{ id: 3, title: 'Settlement', ymd: '20250101' },
{ id: 4, title: 'TBD', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'title', title: 'Event', width: 100 },
{
id: 'ymd',
title: 'Date',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'MM/DD/YYYY', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log(
`Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
),
),
api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells, ${e.skipped} skipped`)),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};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 date</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.paste(api)"
>Paste a date</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>Write from code</button>
</div>
<mx-grid style="height: 220px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
title: string;
ymd: string | null;
}
// The server sends and receives dates as 'YYYYMMDD' strings. With stored declared, the calendar, sort and validation
// work on a standard date, while the row is written in the stored shape ('20260305').
const rows: Row[] = [
{ id: 1, title: 'Contract', ymd: '20260305' },
{ id: 2, title: 'Delivery', ymd: '20240229' },
{ id: 3, title: 'Settlement', ymd: '20250101' },
{ id: 4, title: 'TBD', ymd: null },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'title', title: 'Event', width: 100 },
{
id: 'ymd',
title: 'Date',
kind: 'date',
width: 170,
editable: true,
format: { date: { pattern: 'MM/DD/YYYY', stored: 'YYYYMMDD' } },
},
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = [
api.on('editCommitted', (e) =>
log(
`Committed: ${String(e.oldValue)} -> ${String(e.newValue)} (row holds ${JSON.stringify(api.getRowByKey(e.rowKey)?.ymd)})`,
),
),
api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells, ${e.skipped} skipped`)),
];
return () => off.forEach((fn) => fn());
}
export const actions = {
edit: (api: GridApi<Row>) => api.startEdit(1, 'ymd'),
paste: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'ymd' });
api.pasteCells('2027/01/15');
},
fill: (api: GridApi<Row>) => api.setCellValue(3, 'ymd', '2030-12-24'),
};