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

날짜를 분기·주·일 단위로 묶기Group dates by quarter, week or day

groupBy에 'quarter'·'week'·'month'·'day' 한 단계만 주면 그 단위로 한 번에 묶어요. 그룹 값은 2026-Q4, 2026-W47처럼 안정적인 글자이고, 연도가 위에 없으면 라벨에 연도가 붙어요.A single groupBy value ('quarter', 'week', 'month' or 'day') groups by that unit at once. Group values are stable strings like 2026-Q4 and 2026-W47, and the label carries the year because no year level is above it.

입문Beginner
직접 써 보기Live preview날짜를 분기·주·일 단위로 묶기Group dates by quarter, week or day

코드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">
    <select aria-label="묶음 단위" id="unit">
      <option value="quarter" selected>분기</option>
      <option value="month">월</option>
      <option value="week">주</option>
      <option value="day">일</option>
    </select>
  </div>
  <div id="grid" style="height: 320px"></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('unit').addEventListener('change', (event) => actions.unit(api, event.target.value));
example.js
const customers = ['한빛상사', '새봄유통', '늘푸른식품', '바다물산', '하늘전자'];
// 2025-01-03부터 2026년 말까지 흩뿌린 주문이에요(날짜 순서가 아니라 섞여 있어요).
const rows = Array.from({ length: 72 }, (_, i) => {
  const day = (i * 29) % 700;
  const date = new Date(2025, 0, 3 + day);
  return {
    id: i + 1,
    customer: customers[i % customers.length],
    date: i % 17 === 16
      ? null
      : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
    amount: 20 + ((i * 37) % 180),
  };
});
// groupBy에 한 단계만 주면 그 단위로 한 번에 묶어요: 'quarter'는 "2026 4분기", 'week'는 ISO 주(2026-W47), 'day'는 날짜 하루예요.
export const options = {
  columns: [
    { id: 'customer', title: '고객', width: 150 },
    { id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: 'quarter' },
    { id: 'amount', title: '금액 ($)', kind: 'number', width: 120, align: 'end', aggregate: 'sum' },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api, log) {
  log({
    ko: '분기 단위로 묶였어요. "묶음 단위"를 주·월·일로 바꿔 보세요.',
    en: 'Grouped by quarter. Change "Grouping unit" to week, month or day.',
  });
  return () => undefined;
}
export const actions = {
  unit: (api, value) => api.updateColumn('date', {
    groupBy: (value ?? 'quarter'),
  }),
};

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">
    <select aria-label="Grouping unit" id="unit">
      <option value="quarter" selected>Quarter</option>
      <option value="month">Month</option>
      <option value="week">Week</option>
      <option value="day">Day</option>
    </select>
  </div>
  <div id="grid" style="height: 320px"></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('unit').addEventListener('change', (event) => actions.unit(api, event.target.value));
example.js
const customers = [
  'Harbor Trading',
  'Spring Goods',
  'Evergreen Foods',
  'Ocean Supply',
  'Skyline Tech',
];
// Orders scattered from 2025-01-03 to the end of 2026, not in date order.
const rows = Array.from({ length: 72 }, (_, i) => {
  const day = (i * 29) % 700;
  const date = new Date(2025, 0, 3 + day);
  return {
    id: i + 1,
    customer: customers[i % customers.length],
    date: i % 17 === 16
      ? null
      : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
    amount: 20 + ((i * 37) % 180),
  };
});
// A single groupBy value groups by that unit at once: 'quarter' gives "2026 Q4", 'week' the ISO week (2026-W47) and 'day' a single day.
export const options = {
  columns: [
    { id: 'customer', title: 'Customer', width: 150 },
    { id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: 'quarter' },
    {
      id: 'amount',
      title: 'Amount ($)',
      kind: 'number',
      width: 120,
      align: 'end',
      aggregate: 'sum',
    },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api, log) {
  log('Grouped by quarter. Change "Grouping unit" to week, month or day.');
  return () => undefined;
}
export const actions = {
  unit: (api, value) => api.updateColumn('date', {
    groupBy: (value ?? 'quarter'),
  }),
};