날짜를 분기·주·일 단위로 묶기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.
코드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="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>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));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'),
}),
};<!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="quarter" selected>분기</option>
<option value="month">월</option>
<option value="week">주</option>
<option value="day">일</option>
</select>
</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: 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'는 날짜 하루예요.
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 },
};
function setup(_api, log) {
log({
ko: '분기 단위로 묶였어요. "묶음 단위"를 주·월·일로 바꿔 보세요.',
en: 'Grouped by quarter. Change "Grouping unit" to week, month or day.',
});
return () => undefined;
}
const actions = {
unit: (api, value) => api.updateColumn('date', {
groupBy: (value ?? 'quarter'),
}),
};
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));
</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="quarter">분기</option>
<option value="month">월</option>
<option value="week">주</option>
<option value="day">일</option>
</select>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '분기 단위로 묶였어요. "묶음 단위"를 주·월·일로 바꿔 보세요.',
en: 'Grouped by quarter. Change "Grouping unit" to week, month or day.',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};버튼을 누르면 이 예제의 코드가 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="quarter" selected>분기</option>
<option value="month">월</option>
<option value="week">주</option>
<option value="day">일</option>
</select>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '분기 단위로 묶였어요. "묶음 단위"를 주·월·일로 바꿔 보세요.',
en: 'Grouped by quarter. Change "Grouping unit" to week, month or day.',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};버튼을 누르면 이 예제의 코드가 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="quarter" selected>분기</option>
<option value="month">월</option>
<option value="week">주</option>
<option value="day">일</option>
</select>
</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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '분기 단위로 묶였어요. "묶음 단위"를 주·월·일로 바꿔 보세요.',
en: 'Grouped by quarter. Change "Grouping unit" to week, month or day.',
});
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};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="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>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));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'),
}),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Group dates by quarter, week or day</title>
</head>
<body>
<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>
<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: 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.
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 },
};
function setup(_api, log) {
log('Grouped by quarter. Change "Grouping unit" to week, month or day.');
return () => undefined;
}
const actions = {
unit: (api, value) => api.updateColumn('date', {
groupBy: (value ?? 'quarter'),
}),
};
options.ariaLabel = "Group dates by quarter, week or day";
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));
</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="quarter">Quarter</option>
<option value="month">Month</option>
<option value="week">Week</option>
<option value="day">Day</option>
</select>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log('Grouped by quarter. Change "Grouping unit" to week, month or day.');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};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="quarter" selected>Quarter</option>
<option value="month">Month</option>
<option value="week">Week</option>
<option value="day">Day</option>
</select>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log('Grouped by quarter. Change "Grouping unit" to week, month or day.');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};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="quarter" selected>Quarter</option>
<option value="month">Month</option>
<option value="week">Week</option>
<option value="day">Day</option>
</select>
</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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
customer: string;
date: string | null;
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:
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
log('Grouped by quarter. Change "Grouping unit" to week, month or day.');
return () => undefined;
}
export const actions = {
unit: (api: GridApi<Row>, value?: string) =>
api.updateColumn('date', {
groupBy: (value ?? 'quarter') as 'quarter' | 'week' | 'month' | 'day',
}),
};