날짜를 연 > 월로 묶기Group dates by year > month
날짜 컬럼의 groupBy에 ['year', 'month']처럼 굵은 단위부터 배열을 주면, 그 컬럼으로 묶을 때 2026 > 11월 같은 중첩 그룹이 만들어져요. 그룹은 시간 순서로 놓이고 합계도 단계마다 나와요.Give a date column groupBy: ['year', 'month'] (coarse to fine) and grouping by it creates nested groups such as 2026 > November. Groups are in chronological order and show totals at every level.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="묶음 단위" id="unit">
<option value="ym" selected>연 > 월</option>
<option value="yq">연 > 분기 > 월</option>
<option value="year">연</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 320px"></div>
</div>
<script type="module" src="./main.js"></script>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));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));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: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// 날짜 컬럼에 groupBy 배열을 주면 그 컬럼으로 묶을 때 연 > 월처럼 중첩 그룹이 만들어져요. 그룹 값은 2026, 2026-11처럼 안정적인 글자이고 시간 순서로 놓여요.
export const options = {
columns: [
{ id: 'customer', title: '고객', width: 150 },
{ id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{ 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: 'The date column is grouped year > month. Expand a group and change "Grouping unit".',
});
return () => undefined;
}
export const actions = {
unit: (api, value) => {
const by = (value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']);
api.updateColumn('date', { groupBy: by });
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>날짜를 연 > 월로 묶기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="묶음 단위" id="unit">
<option value="ym" selected>연 > 월</option>
<option value="yq">연 > 분기 > 월</option>
<option value="year">연</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// 날짜 컬럼에 groupBy 배열을 주면 그 컬럼으로 묶을 때 연 > 월처럼 중첩 그룹이 만들어져요. 그룹 값은 2026, 2026-11처럼 안정적인 글자이고 시간 순서로 놓여요.
const options = {
columns: [
{ id: 'customer', title: '고객', width: 150 },
{ id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{ id: 'amount', title: '금액 ($)', kind: 'number', width: 120, align: 'end', aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
function setup(_api, log) {
log({
ko: '날짜 컬럼이 연 > 월로 묶였어요. 그룹을 펼쳐 보고 "묶음 단위"를 바꿔 보세요.',
en: 'The date column is grouped year > month. Expand a group and change "Grouping unit".',
});
return () => undefined;
}
const actions = {
unit: (api, value) => {
const by = (value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']);
api.updateColumn('date', { groupBy: by });
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "날짜를 연 > 월로 묶기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('unit').addEventListener('change', (event) => actions.unit(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="묶음 단위"
disabled={!api}
onChange={(event) => api && actions.unit(api, event.target.value)}
>
<option value="ym">연 > 월</option>
<option value="yq">연 > 분기 > 월</option>
<option value="year">연</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>모두 펼치기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>모두 접기</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
const customers = ['한빛상사', '새봄유통', '늘푸른식품', '바다물산', '하늘전자'];
// 2025-01-03부터 2026년 말까지 흩뿌린 주문이에요(날짜 순서가 아니라 섞여 있어요).
const rows: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// 날짜 컬럼에 groupBy 배열을 주면 그 컬럼으로 묶을 때 연 > 월처럼 중첩 그룹이 만들어져요. 그룹 값은 2026, 2026-11처럼 안정적인 글자이고 시간 순서로 놓여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객', width: 150 },
{ id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{ id: 'amount', title: '금액 ($)', kind: 'number', width: 120, align: 'end', aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '날짜 컬럼이 연 > 월로 묶였어요. 그룹을 펼쳐 보고 "묶음 단위"를 바꿔 보세요.',
en: 'The date column is grouped year > month. Expand a group and change "Grouping unit".',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="묶음 단위"
:disabled="!api"
@change="api && actions.unit(api, ($event.target as HTMLSelectElement).value)"
>
<option value="ym" selected>연 > 월</option>
<option value="yq">연 > 분기 > 월</option>
<option value="year">연</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
const customers = ['한빛상사', '새봄유통', '늘푸른식품', '바다물산', '하늘전자'];
// 2025-01-03부터 2026년 말까지 흩뿌린 주문이에요(날짜 순서가 아니라 섞여 있어요).
const rows: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// 날짜 컬럼에 groupBy 배열을 주면 그 컬럼으로 묶을 때 연 > 월처럼 중첩 그룹이 만들어져요. 그룹 값은 2026, 2026-11처럼 안정적인 글자이고 시간 순서로 놓여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객', width: 150 },
{ id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{ id: 'amount', title: '금액 ($)', kind: 'number', width: 120, align: 'end', aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '날짜 컬럼이 연 > 월로 묶였어요. 그룹을 펼쳐 보고 "묶음 단위"를 바꿔 보세요.',
en: 'The date column is grouped year > month. Expand a group and change "Grouping unit".',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="묶음 단위"
[disabled]="!api"
(change)="api && actions.unit(api, $any($event.target).value)"
>
<option value="ym" selected>연 > 월</option>
<option value="yq">연 > 분기 > 월</option>
<option value="year">연</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>모두 접기</button>
</div>
<mx-grid style="height: 320px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
const customers = ['한빛상사', '새봄유통', '늘푸른식품', '바다물산', '하늘전자'];
// 2025-01-03부터 2026년 말까지 흩뿌린 주문이에요(날짜 순서가 아니라 섞여 있어요).
const rows: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// 날짜 컬럼에 groupBy 배열을 주면 그 컬럼으로 묶을 때 연 > 월처럼 중첩 그룹이 만들어져요. 그룹 값은 2026, 2026-11처럼 안정적인 글자이고 시간 순서로 놓여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객', width: 150 },
{ id: 'date', title: '주문일', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{ id: 'amount', title: '금액 ($)', kind: 'number', width: 120, align: 'end', aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '날짜 컬럼이 연 > 월로 묶였어요. 그룹을 펼쳐 보고 "묶음 단위"를 바꿔 보세요.',
en: 'The date column is grouped year > month. Expand a group and change "Grouping unit".',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Grouping unit" id="unit">
<option value="ym" selected>Year > month</option>
<option value="yq">Year > quarter > month</option>
<option value="year">Year</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 320px"></div>
</div>
<script type="module" src="./main.js"></script>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));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));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: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// A groupBy array on a date column makes nested groups (year > month) when you group by that column. Group values are stable strings such as 2026 and 2026-11, in chronological order.
export const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{
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('The date column is grouped year > month. Expand a group and change "Grouping unit".');
return () => undefined;
}
export const actions = {
unit: (api, value) => {
const by = (value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']);
api.updateColumn('date', { groupBy: by });
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Group dates by year > month</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Grouping unit" id="unit">
<option value="ym" selected>Year > month</option>
<option value="yq">Year > quarter > month</option>
<option value="year">Year</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// A groupBy array on a date column makes nested groups (year > month) when you group by that column. Group values are stable strings such as 2026 and 2026-11, in chronological order.
const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
function setup(_api, log) {
log('The date column is grouped year > month. Expand a group and change "Grouping unit".');
return () => undefined;
}
const actions = {
unit: (api, value) => {
const by = (value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']);
api.updateColumn('date', { groupBy: by });
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "Group dates by year > month";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('unit').addEventListener('change', (event) => actions.unit(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Grouping unit"
disabled={!api}
onChange={(event) => api && actions.unit(api, event.target.value)}
>
<option value="ym">Year > month</option>
<option value="yq">Year > quarter > month</option>
<option value="year">Year</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>Expand all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>Collapse all</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
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: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// A groupBy array on a date column makes nested groups (year > month) when you group by that column. Group values are stable strings such as 2026 and 2026-11, in chronological order.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('The date column is grouped year > month. Expand a group and change "Grouping unit".');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Grouping unit"
:disabled="!api"
@change="api && actions.unit(api, ($event.target as HTMLSelectElement).value)"
>
<option value="ym" selected>Year > month</option>
<option value="yq">Year > quarter > month</option>
<option value="year">Year</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
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: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// A groupBy array on a date column makes nested groups (year > month) when you group by that column. Group values are stable strings such as 2026 and 2026-11, in chronological order.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('The date column is grouped year > month. Expand a group and change "Grouping unit".');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Grouping unit"
[disabled]="!api"
(change)="api && actions.unit(api, $any($event.target).value)"
>
<option value="ym" selected>Year > month</option>
<option value="yq">Year > quarter > month</option>
<option value="year">Year</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>Collapse all</button>
</div>
<mx-grid style="height: 320px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { DateGroupBy, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string;
amount: number;
}
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: Row[] = 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] as string,
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`,
amount: 20 + ((i * 37) % 180),
};
});
// A groupBy array on a date column makes nested groups (year > month) when you group by that column. Group values are stable strings such as 2026 and 2026-11, in chronological order.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'date', title: 'Order date', kind: 'date', width: 150, groupBy: ['year', 'month'] },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['date'], expandDepth: 1 },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('The date column is grouped year > month. Expand a group and change "Grouping unit".');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) => {
const by = (
value === 'yq'
? ['year', 'quarter', 'month']
: value === 'year'
? ['year']
: ['year', 'month']
) as DateGroupBy;
api.updateColumn('date', { groupBy: by });
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};