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

달 칸 편집: 달 버튼에서 고르기Edit months from a month panel

kind: 'month' 컬럼은 날 격자 없이 12개 달 버튼이 열려요. 값은 YYYY-MM 글자이고 min·max 밖의 달은 고를 수 없어요.A kind: 'month' column opens twelve month buttons with no day grid. The value is a YYYY-MM string and months outside min and max cannot be picked.

입문Beginner
직접 써 보기Live preview달 칸 편집: 달 버튼에서 고르기Edit months from a month panel

코드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="openMonth">청구월 편집</button>
    <button type="button" id="outOfRange">범위 밖 값 넣기</button>
  </div>
  <div id="grid" style="height: 260px"></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('openMonth').addEventListener('click', () => actions.openMonth(api));
document.getElementById('outOfRange').addEventListener('click', () => actions.outOfRange(api));
example.js
const rows = [
  { id: 1, item: '클라우드 사용료', billMonth: '2026-03', closeMonth: '2026-04' },
  { id: 2, item: '사무실 임대료', billMonth: '2026-06', closeMonth: null },
  { id: 3, item: '소프트웨어 구독', billMonth: '2026-11', closeMonth: '2026-12' },
];
// kind: 'month' 컬럼은 날 격자 없이 12개 달 버튼이 바로 열려요. 값은 'YYYY-MM' 글자예요.
export const options = {
  columns: [
    { id: 'item', title: '항목', width: 150 },
    {
      id: 'billMonth',
      title: '청구월',
      kind: 'month',
      width: 130,
      editable: true,
      dateTime: { min: '2026-01', max: '2026-12' },
    },
    { id: 'closeMonth', title: '마감월', kind: 'month', width: 130, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: '청구월 칸을 더블클릭하세요. 화살표·PageUp/Down으로 달을 옮기고 Enter로 고르거나, 2026.7처럼 직접 써도 돼요.',
    en: 'Double-click a bill month. Move with the arrows and PageUp/Down, press Enter, or type 2026.7.',
  });
  const offs = [
    api.on('editCommitted', (e) => log({
      ko: `${e.rowKey}번 줄 ${e.columnId} → ${String(e.newValue)}`,
      en: `Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`,
    })),
    api.on('validationFailed', (e) => log({ ko: `확정하지 못했어요: ${e.message}`, en: `Could not confirm: ${e.message}` })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  openMonth: (api) => {
    api.startEdit(1, 'billMonth', { open: true });
  },
  // min·max(2026-01~2026-12) 밖의 달을 코드로 넣으면 검증이 막아요.
  outOfRange: (api) => {
    api.setCellValue(2, 'billMonth', '2027-02', { validate: true });
  },
};

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="openMonth">Edit bill month</button>
    <button type="button" id="outOfRange">Set an out-of-range value</button>
  </div>
  <div id="grid" style="height: 260px"></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('openMonth').addEventListener('click', () => actions.openMonth(api));
document.getElementById('outOfRange').addEventListener('click', () => actions.outOfRange(api));
example.js
const rows = [
  { id: 1, item: 'Cloud usage fee', billMonth: '2026-03', closeMonth: '2026-04' },
  { id: 2, item: 'Office rent', billMonth: '2026-06', closeMonth: null },
  { id: 3, item: 'Software subscription', billMonth: '2026-11', closeMonth: '2026-12' },
];
// A kind: 'month' column opens twelve month buttons right away, with no day grid. The value is a 'YYYY-MM' string.
export const options = {
  columns: [
    { id: 'item', title: 'Item', width: 190 },
    {
      id: 'billMonth',
      title: 'Bill month',
      kind: 'month',
      width: 130,
      editable: true,
      dateTime: { min: '2026-01', max: '2026-12' },
    },
    { id: 'closeMonth', title: 'Close month', kind: 'month', width: 130, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log('Double-click a bill month. Move with the arrows and PageUp/Down, press Enter, or type 2026.7.');
  const offs = [
    api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId} → ${String(e.newValue)}`)),
    api.on('validationFailed', (e) => log(`Could not confirm: ${e.message}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  openMonth: (api) => {
    api.startEdit(1, 'billMonth', { open: true });
  },
  // Setting a month outside min and max (2026-01 to 2026-12) from code is blocked by validation.
  outOfRange: (api) => {
    api.setCellValue(2, 'billMonth', '2027-02', { validate: true });
  },
};