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

목록에서 시각 고르기Pick a time from the lists

시간 컬럼(kind: time)을 고치면 시·분 목록이 열려요. 분 간격, 고를 수 있는 시간대, 24시간/오전·오후 표시를 옵션으로 정해요. 저장되는 값은 항상 24시간 'HH:mm'이에요.Editing a time column opens hour and minute lists. The minute step, the allowed range and 24-hour or AM/PM display are options. The stored value is always 24-hour 'HH:mm'.

입문Beginner
직접 써 보기Live preview목록에서 시각 고르기Pick a time from the lists

코드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="step">
      <option value="5">5분</option>
      <option value="15" selected>15분</option>
      <option value="30">30분</option>
    </select>
    <select aria-label="시간 표시" id="clock">
      <option value="24" selected>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('step').addEventListener('change', (event) => actions.step(api, event.target.value));
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();
}
// 값은 시간대 없는 'HH:mm' 문자열이에요(초가 필요하면 seconds: true). 24시간제로 저장돼요.
const columns = (step, hour12) => [
  { id: 'name', title: '이름', width: 120 },
  {
    id: 'start',
    title: '출근 시각',
    kind: 'time',
    width: 150,
    editable: true,
    dateTime: {
      step, // 분 간격(60의 약수)
      min: '09:00',
      max: '18:00',
      hour12, // 오전·오후 열을 쓸지. 생략하면 언어를 따라요
    },
  },
];
export const options = {
  columns: columns(15, false),
  rows: [
    { id: 1, name: '김서연', start: '09:00' },
    { id: 2, name: '이준호', start: '09:30' },
    { id: 3, name: '박민지', start: '10:30' },
    { id: 4, name: '최도윤', start: '13:30' },
  ],
  rowKey: 'id',
  locale: pageLang(),
};
let step = 15;
let hour12 = false;
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, 'start'),
  step: (api, value) => {
    step = Number(value) || 15;
    api.setColumns(columns(step, hour12));
  },
  clock: (api, value) => {
    hour12 = value === '12';
    api.setColumns(columns(step, hour12));
  },
};

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="Minute step" id="step">
      <option value="5">5 min</option>
      <option value="15" selected>15 min</option>
      <option value="30">30 min</option>
    </select>
    <select aria-label="Clock" id="clock">
      <option value="24" selected>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('step').addEventListener('change', (event) => actions.step(api, event.target.value));
document.getElementById('clock').addEventListener('change', (event) => actions.clock(api, event.target.value));
example.js
// The English sample always uses the 'en' grid locale. Sample data is in English.
const pageLang = () => 'en';
// Follows page language changes and updates the grid locale. Returns a dispose function.
function followPageLanguage(api) {
  const watcher = new MutationObserver(() => api.setOptions({ locale: pageLang() }));
  watcher.observe(document.documentElement, { attributes: true, attributeFilter: ['data-lang'] });
  return () => watcher.disconnect();
}
// The value is a timezone-free 'HH:mm' string (use seconds: true if seconds are needed). Stored in 24-hour form.
const columns = (step, hour12) => [
  { id: 'name', title: 'Name', width: 120 },
  {
    id: 'start',
    title: 'Start time',
    kind: 'time',
    width: 150,
    editable: true,
    dateTime: {
      step, // minute step (a divisor of 60)
      min: '09:00',
      max: '18:00',
      hour12, // whether to show the AM/PM column. Follows the language when omitted
    },
  },
];
export const options = {
  columns: columns(15, false),
  rows: [
    { id: 1, name: 'Liam Carter', start: '09:00' },
    { id: 2, name: 'Emma Stone', start: '09:30' },
    { id: 3, name: 'Olivia Park', start: '10:30' },
    { id: 4, name: 'Noah Kim', start: '13:30' },
  ],
  rowKey: 'id',
  locale: pageLang(),
};
let step = 15;
let hour12 = false;
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, 'start'),
  step: (api, value) => {
    step = Number(value) || 15;
    api.setColumns(columns(step, hour12));
  },
  clock: (api, value) => {
    hour12 = value === '12';
    api.setColumns(columns(step, hour12));
  },
};