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

날짜·시각 표시 패턴 정하기Set the date and time display pattern

format.date.pattern으로 날짜와 시각이 보이는 모양을 정해요. 토큰은 YYYY YY MM M DD D HH H mm ss A예요. 값은 그대로라 편집기·정렬·내보내기에는 영향이 없어요.format.date.pattern sets how dates and times look. Tokens are YYYY YY MM M DD D HH H mm ss A. The value stays the same, so the editor, sort and export are unaffected.

입문Beginner
직접 써 보기Live preview날짜·시각 표시 패턴 정하기Set the date and time display pattern

코드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="pattern24">24시간 패턴</button>
    <button type="button" id="reset">처음 패턴</button>
  </div>
  <div id="grid" style="height: 200px"></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('pattern24').addEventListener('click', () => actions.pattern24(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
example.js
const rows = [
  { id: 1, task: '설계', due: '2026-03-05', at: '2026-03-05 09:30' },
  { id: 2, task: '구현', due: '2024-02-29', at: '2024-02-29 14:05' },
  { id: 3, task: '검수', due: '2026-12-31', at: '2026-12-31 23:59' },
];
// format.date.pattern은 보이는 모양만 바꾸고 값(YYYY-MM-DD)은 그대로예요. 달력·정렬·내보내기는 표준 값을 써요.
export const options = {
  columns: [
    { id: 'id', title: '번호', kind: 'number', width: 70 },
    { id: 'task', title: '작업', width: 100 },
    {
      id: 'due',
      title: '마감',
      kind: 'date',
      width: 150,
      editable: true,
      format: { date: { pattern: 'YYYY.MM.DD' } },
    },
    {
      id: 'at',
      title: '시각',
      kind: 'datetime',
      width: 190,
      editable: true,
      format: { date: { pattern: 'M/D A H시' } },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(_api, log) {
  log({
    ko: '시각 패턴의 A는 언어에 맞는 오전·오후예요(24시간 토큰은 H, HH).',
    en: 'A in the pattern is the AM/PM text of the locale (24-hour tokens are H and HH).',
  });
  return () => undefined;
}
export const actions = {
  pattern24: (api) => api.setColumns(options.columns.map((c) => c.id === 'at' ? { ...c, format: { date: { pattern: 'YYYY-MM-DD HH:mm' } } } : c)),
  reset: (api) => api.setColumns(options.columns),
};

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="pattern24">24-hour pattern</button>
    <button type="button" id="reset">Original pattern</button>
  </div>
  <div id="grid" style="height: 200px"></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('pattern24').addEventListener('click', () => actions.pattern24(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
example.js
const rows = [
  { id: 1, task: 'Design', due: '2026-03-05', at: '2026-03-05 09:30' },
  { id: 2, task: 'Build', due: '2024-02-29', at: '2024-02-29 14:05' },
  { id: 3, task: 'Review', due: '2026-12-31', at: '2026-12-31 23:59' },
];
// format.date.pattern only changes the displayed shape; the value (YYYY-MM-DD) stays the same. Calendar, sort and export use the standard value.
export const options = {
  columns: [
    { id: 'id', title: 'No.', kind: 'number', width: 70 },
    { id: 'task', title: 'Task', width: 100 },
    {
      id: 'due',
      title: 'Due',
      kind: 'date',
      width: 150,
      editable: true,
      format: { date: { pattern: 'MM/DD/YYYY' } },
    },
    {
      id: 'at',
      title: 'Time',
      kind: 'datetime',
      width: 190,
      editable: true,
      format: { date: { pattern: 'M/D A H:mm' } },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(_api, log) {
  log('A in the pattern is the AM/PM text of the locale (24-hour tokens are H and HH).');
  return () => undefined;
}
export const actions = {
  pattern24: (api) => api.setColumns(options.columns.map((c) => c.id === 'at' ? { ...c, format: { date: { pattern: 'YYYY-MM-DD HH:mm' } } } : c)),
  reset: (api) => api.setColumns(options.columns),
};