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

날짜와 시간을 한 번에 고르기Pick a date and a time together

날짜+시간 컬럼(kind: datetime)을 고치면 달력과 시·분 목록이 함께 열리고 '확인'으로 한 번에 정해요. 저장되는 값은 'YYYY-MM-DD HH:mm' 글자 하나예요.Editing a datetime column opens a calendar and time lists together, and OK sets both at once. The stored value is one 'YYYY-MM-DD HH:mm' string.

입문Beginner
직접 써 보기Live preview날짜와 시간을 한 번에 고르기Pick a date and a time together

코드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>
    <select aria-label="시간 표시" id="clock">
      <option value="auto" selected>언어 기본</option>
      <option value="24">24시간</option>
      <option value="12">오전·오후</option>
    </select>
  </div>
  <div id="grid" style="height: 340px"></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('clock').addEventListener('change', (event) => actions.clock(api, event.target.value));
example.js
// 예제 틀이 알려 주는 페이지 언어(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 HH:mm' 문자열이에요. 정렬·필터·내보내기도 이 값 기준이에요.
// hour12를 생략하면 언어를 따라요(한국어는 오전·오후). 저장되는 값은 항상 24시간이에요.
const columns = (hour12) => [
  { id: 'event', title: '일정', width: 140 },
  {
    id: 'at',
    title: '시작',
    kind: 'datetime',
    width: 190,
    editable: true,
    dateTime: {
      step: 5,
      min: '2026-01-01 08:00',
      hour12,
      isTimeDisabled: (time) => time >= '12:00' && time < '13:00', // 점심시간은 못 골라요
    },
  },
];
export const options = {
  columns: columns(undefined),
  rows: [
    { id: 1, event: '주간 회의', at: '2026-11-10 10:00' },
    { id: 2, event: '고객 미팅', at: '2026-11-11 14:30' },
    { id: 3, event: '코드 리뷰', at: '2026-11-12 16:05' },
    { id: 4, event: '배포', at: '2026-11-13 09:00' },
  ],
  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, 'at'),
  clock: (api, value) => api.setColumns(columns(value === 'auto' ? undefined : value === '12')),
};

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 first row</button>
    <select aria-label="Clock" id="clock">
      <option value="auto" selected>Language default</option>
      <option value="24">24-hour</option>
      <option value="12">AM/PM</option>
    </select>
  </div>
  <div id="grid" style="height: 340px"></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('clock').addEventListener('change', (event) => actions.clock(api, event.target.value));
example.js
// The value is a 'YYYY-MM-DD HH:mm' string without a time zone. Sorting, filtering and export also use this value.
// If hour12 is omitted it follows the language (English uses AM/PM). The stored value is always 24-hour.
const columns = (hour12) => [
  { id: 'event', title: 'Event', width: 140 },
  {
    id: 'at',
    title: 'Start',
    kind: 'datetime',
    width: 190,
    editable: true,
    dateTime: {
      step: 5,
      min: '2026-01-01 08:00',
      hour12,
      isTimeDisabled: (time) => time >= '12:00' && time < '13:00', // Lunch hour cannot be picked
    },
  },
];
export const options = {
  columns: columns(undefined),
  rows: [
    { id: 1, event: 'Weekly meeting', at: '2026-11-10 10:00' },
    { id: 2, event: 'Client meeting', at: '2026-11-11 14:30' },
    { id: 3, event: 'Code review', at: '2026-11-12 16:05' },
    { id: 4, event: 'Release', at: '2026-11-13 09:00' },
  ],
  rowKey: 'id',
  locale: 'en',
};
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, 'at'),
  clock: (api, value) => api.setColumns(columns(value === 'auto' ? undefined : value === '12')),
};