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

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.

활용Intermediate
직접 써 보기Live previewYYYYMMDD로 저장된 날짜 다루기Work with dates stored as YYYYMMDD

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="edit">날짜 편집</button>
    <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>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('edit').addEventListener('click', () => actions.edit(api));
document.getElementById('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
example.js
// 서버가 날짜를 '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'),
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="edit">Edit 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>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('edit').addEventListener('click', () => actions.edit(api));
document.getElementById('paste').addEventListener('click', () => actions.paste(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
example.js
// 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'),
};