묶음 헤더가 있는 예산 트리A budget tree with grouped headers
컬럼 위에 "상반기 > 1분기·2분기" 같은 묶음 헤더를 달고, 본부·팀 줄에는 아래 항목의 합계를 보여 줘요. 분기 묶음은 헤더에서 접을 수 있어요.Put grouped headers such as "H1 > Q1, Q2" above the columns, and let department rows show the sum of their items. Quarter groups fold from the header.
코드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="quarter">
<option value="open" selected>펼치기</option>
<option value="closed">접기</option>
</select>
<button type="button" id="expandAll">모두 열기</button>
<button type="button" id="collapseAll">모두 닫기</button>
</div>
<div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('quarter').addEventListener('change', (event) => actions.quarter(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));// 본부 > 팀 > 항목 세 단계의 월별 예산(백만원)이에요. 맨 아래 항목만 숫자를 갖고, 본부·팀 줄은 아래 줄의 합계를 보여 줘요.
const leaves = [
['B111', 'B11', '인건비'],
['B112', 'B11', '광고비'],
['B121', 'B12', '출장비'],
['B122', 'B12', '수수료'],
['B211', 'B21', '서버 비용'],
['B212', 'B21', '도구 구독'],
['B221', 'B22', '외주비'],
['B222', 'B22', '교육비'],
];
const month = (i, k) => 20 + ((i * 17 + k * 9) % 60);
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows = [
{ id: 'B1', parentId: null, name: '영업본부', ...empty },
{ id: 'B11', parentId: 'B1', name: '국내영업', ...empty },
{ id: 'B12', parentId: 'B1', name: '해외영업', ...empty },
{ id: 'B2', parentId: null, name: '개발본부', ...empty },
{ id: 'B21', parentId: 'B2', name: '플랫폼팀', ...empty },
{ id: 'B22', parentId: 'B2', name: '앱개발팀', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('ko-KR');
export const options = {
columns: [
{ id: 'name', title: '항목', width: 160 },
...months.map((id, i) => ({
id,
title: `${i + 1}월`,
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: '합계',
kind: 'number',
width: 110,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// 컬럼을 묶는 헤더예요. 묶음 안에 묶음을 넣을 수 있고, collapsible이면 헤더의 토글로 접을 수 있어요.
headerGroups: [
{
id: 'h1',
title: '2026 상반기',
children: [
{ id: 'q1', title: '1분기', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: '2분기', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: 부모 줄은 자기 값 대신 아래 줄들의 합계(aggregate: 'sum')를 보여 줘요.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api, value) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
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="quarter">
<option value="open" selected>펼치기</option>
<option value="closed">접기</option>
</select>
<button type="button" id="expandAll">모두 열기</button>
<button type="button" id="collapseAll">모두 닫기</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 본부 > 팀 > 항목 세 단계의 월별 예산(백만원)이에요. 맨 아래 항목만 숫자를 갖고, 본부·팀 줄은 아래 줄의 합계를 보여 줘요.
const leaves = [
['B111', 'B11', '인건비'],
['B112', 'B11', '광고비'],
['B121', 'B12', '출장비'],
['B122', 'B12', '수수료'],
['B211', 'B21', '서버 비용'],
['B212', 'B21', '도구 구독'],
['B221', 'B22', '외주비'],
['B222', 'B22', '교육비'],
];
const month = (i, k) => 20 + ((i * 17 + k * 9) % 60);
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows = [
{ id: 'B1', parentId: null, name: '영업본부', ...empty },
{ id: 'B11', parentId: 'B1', name: '국내영업', ...empty },
{ id: 'B12', parentId: 'B1', name: '해외영업', ...empty },
{ id: 'B2', parentId: null, name: '개발본부', ...empty },
{ id: 'B21', parentId: 'B2', name: '플랫폼팀', ...empty },
{ id: 'B22', parentId: 'B2', name: '앱개발팀', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('ko-KR');
const options = {
columns: [
{ id: 'name', title: '항목', width: 160 },
...months.map((id, i) => ({
id,
title: `${i + 1}월`,
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: '합계',
kind: 'number',
width: 110,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// 컬럼을 묶는 헤더예요. 묶음 안에 묶음을 넣을 수 있고, collapsible이면 헤더의 토글로 접을 수 있어요.
headerGroups: [
{
id: 'h1',
title: '2026 상반기',
children: [
{ id: 'q1', title: '1분기', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: '2분기', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: 부모 줄은 자기 값 대신 아래 줄들의 합계(aggregate: 'sum')를 보여 줘요.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
const actions = {
quarter: (api, value) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "묶음 헤더가 있는 예산 트리";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('quarter').addEventListener('change', (event) => actions.quarter(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 { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="분기 묶음"
disabled={!api}
onChange={(event) => api && actions.quarter(api, event.target.value)}
>
<option value="open">펼치기</option>
<option value="closed">접기</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: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// 본부 > 팀 > 항목 세 단계의 월별 예산(백만원)이에요. 맨 아래 항목만 숫자를 갖고, 본부·팀 줄은 아래 줄의 합계를 보여 줘요.
const leaves: [string, string, string][] = [
['B111', 'B11', '인건비'],
['B112', 'B11', '광고비'],
['B121', 'B12', '출장비'],
['B122', 'B12', '수수료'],
['B211', 'B21', '서버 비용'],
['B212', 'B21', '도구 구독'],
['B221', 'B22', '외주비'],
['B222', 'B22', '교육비'],
];
const month = (i: number, k: number) => 20 + ((i * 17 + k * 9) % 60);
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: '영업본부', ...empty },
{ id: 'B11', parentId: 'B1', name: '국내영업', ...empty },
{ id: 'B12', parentId: 'B1', name: '해외영업', ...empty },
{ id: 'B2', parentId: null, name: '개발본부', ...empty },
{ id: 'B21', parentId: 'B2', name: '플랫폼팀', ...empty },
{ id: 'B22', parentId: 'B2', name: '앱개발팀', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '항목', width: 160 },
...months.map((id, i) => ({
id,
title: `${i + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: '합계',
kind: 'number',
width: 110,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// 컬럼을 묶는 헤더예요. 묶음 안에 묶음을 넣을 수 있고, collapsible이면 헤더의 토글로 접을 수 있어요.
headerGroups: [
{
id: 'h1',
title: '2026 상반기',
children: [
{ id: 'q1', title: '1분기', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: '2분기', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: 부모 줄은 자기 값 대신 아래 줄들의 합계(aggregate: 'sum')를 보여 줘요.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="분기 묶음"
:disabled="!api"
@change="api && actions.quarter(api, ($event.target as HTMLSelectElement).value)"
>
<option value="open" selected>펼치기</option>
<option value="closed">접기</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: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// 본부 > 팀 > 항목 세 단계의 월별 예산(백만원)이에요. 맨 아래 항목만 숫자를 갖고, 본부·팀 줄은 아래 줄의 합계를 보여 줘요.
const leaves: [string, string, string][] = [
['B111', 'B11', '인건비'],
['B112', 'B11', '광고비'],
['B121', 'B12', '출장비'],
['B122', 'B12', '수수료'],
['B211', 'B21', '서버 비용'],
['B212', 'B21', '도구 구독'],
['B221', 'B22', '외주비'],
['B222', 'B22', '교육비'],
];
const month = (i: number, k: number) => 20 + ((i * 17 + k * 9) % 60);
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: '영업본부', ...empty },
{ id: 'B11', parentId: 'B1', name: '국내영업', ...empty },
{ id: 'B12', parentId: 'B1', name: '해외영업', ...empty },
{ id: 'B2', parentId: null, name: '개발본부', ...empty },
{ id: 'B21', parentId: 'B2', name: '플랫폼팀', ...empty },
{ id: 'B22', parentId: 'B2', name: '앱개발팀', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '항목', width: 160 },
...months.map((id, i) => ({
id,
title: `${i + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: '합계',
kind: 'number',
width: 110,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// 컬럼을 묶는 헤더예요. 묶음 안에 묶음을 넣을 수 있고, collapsible이면 헤더의 토글로 접을 수 있어요.
headerGroups: [
{
id: 'h1',
title: '2026 상반기',
children: [
{ id: 'q1', title: '1분기', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: '2분기', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: 부모 줄은 자기 값 대신 아래 줄들의 합계(aggregate: 'sum')를 보여 줘요.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, 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.quarter(api, $any($event.target).value)"
>
<option value="open" selected>펼치기</option>
<option value="closed">접기</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: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// 본부 > 팀 > 항목 세 단계의 월별 예산(백만원)이에요. 맨 아래 항목만 숫자를 갖고, 본부·팀 줄은 아래 줄의 합계를 보여 줘요.
const leaves: [string, string, string][] = [
['B111', 'B11', '인건비'],
['B112', 'B11', '광고비'],
['B121', 'B12', '출장비'],
['B122', 'B12', '수수료'],
['B211', 'B21', '서버 비용'],
['B212', 'B21', '도구 구독'],
['B221', 'B22', '외주비'],
['B222', 'B22', '교육비'],
];
const month = (i: number, k: number) => 20 + ((i * 17 + k * 9) % 60);
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: '영업본부', ...empty },
{ id: 'B11', parentId: 'B1', name: '국내영업', ...empty },
{ id: 'B12', parentId: 'B1', name: '해외영업', ...empty },
{ id: 'B2', parentId: null, name: '개발본부', ...empty },
{ id: 'B21', parentId: 'B2', name: '플랫폼팀', ...empty },
{ id: 'B22', parentId: 'B2', name: '앱개발팀', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '항목', width: 160 },
...months.map((id, i) => ({
id,
title: `${i + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: '합계',
kind: 'number',
width: 110,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// 컬럼을 묶는 헤더예요. 묶음 안에 묶음을 넣을 수 있고, collapsible이면 헤더의 토글로 접을 수 있어요.
headerGroups: [
{
id: 'h1',
title: '2026 상반기',
children: [
{ id: 'q1', title: '1분기', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: '2분기', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: 부모 줄은 자기 값 대신 아래 줄들의 합계(aggregate: 'sum')를 보여 줘요.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
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="Quarter groups" id="quarter">
<option value="open" selected>Open</option>
<option value="closed">Fold</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('quarter').addEventListener('change', (event) => actions.quarter(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));// Monthly budget (in US dollars) in three levels: division > team > item. Only the bottom items hold numbers; division and team rows show the sum of the rows below.
const leaves = [
['B111', 'B11', 'Payroll'],
['B112', 'B11', 'Advertising'],
['B121', 'B12', 'Travel'],
['B122', 'B12', 'Fees'],
['B211', 'B21', 'Server costs'],
['B212', 'B21', 'Tool subscriptions'],
['B221', 'B22', 'Outsourcing'],
['B222', 'B22', 'Training'],
];
const month = (i, k) => (20 + ((i * 17 + k * 9) % 60)) * 1000;
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows = [
{ id: 'B1', parentId: null, name: 'Sales Division', ...empty },
{ id: 'B11', parentId: 'B1', name: 'Domestic Sales', ...empty },
{ id: 'B12', parentId: 'B1', name: 'Overseas Sales', ...empty },
{ id: 'B2', parentId: null, name: 'Dev Division', ...empty },
{ id: 'B21', parentId: 'B2', name: 'Platform Team', ...empty },
{ id: 'B22', parentId: 'B2', name: 'App Dev Team', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const money = (value) => Number(value).toLocaleString('en-US');
export const options = {
columns: [
{ id: 'name', title: 'Item', width: 200 },
...months.map((id, i) => ({
id,
title: monthNames[i],
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: 'Total',
kind: 'number',
width: 130,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// Headers that group columns. Groups can nest, and a collapsible group folds with the toggle in its header.
headerGroups: [
{
id: 'h1',
title: '2026 H1',
children: [
{ id: 'q1', title: 'Q1', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: 'Q2', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: a parent row shows the sum (aggregate: 'sum') of the rows below instead of its own value.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api, value) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
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>A budget tree with grouped headers</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Quarter groups" id="quarter">
<option value="open" selected>Open</option>
<option value="closed">Fold</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// Monthly budget (in US dollars) in three levels: division > team > item. Only the bottom items hold numbers; division and team rows show the sum of the rows below.
const leaves = [
['B111', 'B11', 'Payroll'],
['B112', 'B11', 'Advertising'],
['B121', 'B12', 'Travel'],
['B122', 'B12', 'Fees'],
['B211', 'B21', 'Server costs'],
['B212', 'B21', 'Tool subscriptions'],
['B221', 'B22', 'Outsourcing'],
['B222', 'B22', 'Training'],
];
const month = (i, k) => (20 + ((i * 17 + k * 9) % 60)) * 1000;
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows = [
{ id: 'B1', parentId: null, name: 'Sales Division', ...empty },
{ id: 'B11', parentId: 'B1', name: 'Domestic Sales', ...empty },
{ id: 'B12', parentId: 'B1', name: 'Overseas Sales', ...empty },
{ id: 'B2', parentId: null, name: 'Dev Division', ...empty },
{ id: 'B21', parentId: 'B2', name: 'Platform Team', ...empty },
{ id: 'B22', parentId: 'B2', name: 'App Dev Team', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const money = (value) => Number(value).toLocaleString('en-US');
const options = {
columns: [
{ id: 'name', title: 'Item', width: 200 },
...months.map((id, i) => ({
id,
title: monthNames[i],
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: 'Total',
kind: 'number',
width: 130,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// Headers that group columns. Groups can nest, and a collapsible group folds with the toggle in its header.
headerGroups: [
{
id: 'h1',
title: '2026 H1',
children: [
{ id: 'q1', title: 'Q1', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: 'Q2', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: a parent row shows the sum (aggregate: 'sum') of the rows below instead of its own value.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
const actions = {
quarter: (api, value) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "A budget tree with grouped headers";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('quarter').addEventListener('change', (event) => actions.quarter(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 { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Quarter groups"
disabled={!api}
onChange={(event) => api && actions.quarter(api, event.target.value)}
>
<option value="open">Open</option>
<option value="closed">Fold</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: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// Monthly budget (in US dollars) in three levels: division > team > item. Only the bottom items hold numbers; division and team rows show the sum of the rows below.
const leaves: [string, string, string][] = [
['B111', 'B11', 'Payroll'],
['B112', 'B11', 'Advertising'],
['B121', 'B12', 'Travel'],
['B122', 'B12', 'Fees'],
['B211', 'B21', 'Server costs'],
['B212', 'B21', 'Tool subscriptions'],
['B221', 'B22', 'Outsourcing'],
['B222', 'B22', 'Training'],
];
const month = (i: number, k: number) => (20 + ((i * 17 + k * 9) % 60)) * 1000;
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: 'Sales Division', ...empty },
{ id: 'B11', parentId: 'B1', name: 'Domestic Sales', ...empty },
{ id: 'B12', parentId: 'B1', name: 'Overseas Sales', ...empty },
{ id: 'B2', parentId: null, name: 'Dev Division', ...empty },
{ id: 'B21', parentId: 'B2', name: 'Platform Team', ...empty },
{ id: 'B22', parentId: 'B2', name: 'App Dev Team', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Item', width: 200 },
...months.map((id, i) => ({
id,
title: monthNames[i],
kind: 'number' as const,
width: 110,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: 'Total',
kind: 'number',
width: 130,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// Headers that group columns. Groups can nest, and a collapsible group folds with the toggle in its header.
headerGroups: [
{
id: 'h1',
title: '2026 H1',
children: [
{ id: 'q1', title: 'Q1', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: 'Q2', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: a parent row shows the sum (aggregate: 'sum') of the rows below instead of its own value.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
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 { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Quarter groups"
:disabled="!api"
@change="api && actions.quarter(api, ($event.target as HTMLSelectElement).value)"
>
<option value="open" selected>Open</option>
<option value="closed">Fold</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: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// Monthly budget (in US dollars) in three levels: division > team > item. Only the bottom items hold numbers; division and team rows show the sum of the rows below.
const leaves: [string, string, string][] = [
['B111', 'B11', 'Payroll'],
['B112', 'B11', 'Advertising'],
['B121', 'B12', 'Travel'],
['B122', 'B12', 'Fees'],
['B211', 'B21', 'Server costs'],
['B212', 'B21', 'Tool subscriptions'],
['B221', 'B22', 'Outsourcing'],
['B222', 'B22', 'Training'],
];
const month = (i: number, k: number) => (20 + ((i * 17 + k * 9) % 60)) * 1000;
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: 'Sales Division', ...empty },
{ id: 'B11', parentId: 'B1', name: 'Domestic Sales', ...empty },
{ id: 'B12', parentId: 'B1', name: 'Overseas Sales', ...empty },
{ id: 'B2', parentId: null, name: 'Dev Division', ...empty },
{ id: 'B21', parentId: 'B2', name: 'Platform Team', ...empty },
{ id: 'B22', parentId: 'B2', name: 'App Dev Team', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Item', width: 200 },
...months.map((id, i) => ({
id,
title: monthNames[i],
kind: 'number' as const,
width: 110,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: 'Total',
kind: 'number',
width: 130,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// Headers that group columns. Groups can nest, and a collapsible group folds with the toggle in its header.
headerGroups: [
{
id: 'h1',
title: '2026 H1',
children: [
{ id: 'q1', title: 'Q1', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: 'Q2', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: a parent row shows the sum (aggregate: 'sum') of the rows below instead of its own value.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
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 } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Quarter groups"
[disabled]="!api"
(change)="api && actions.quarter(api, $any($event.target).value)"
>
<option value="open" selected>Open</option>
<option value="closed">Fold</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: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: string;
parentId: string | null;
name: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
// Monthly budget (in US dollars) in three levels: division > team > item. Only the bottom items hold numbers; division and team rows show the sum of the rows below.
const leaves: [string, string, string][] = [
['B111', 'B11', 'Payroll'],
['B112', 'B11', 'Advertising'],
['B121', 'B12', 'Travel'],
['B122', 'B12', 'Fees'],
['B211', 'B21', 'Server costs'],
['B212', 'B21', 'Tool subscriptions'],
['B221', 'B22', 'Outsourcing'],
['B222', 'B22', 'Training'],
];
const month = (i: number, k: number) => (20 + ((i * 17 + k * 9) % 60)) * 1000;
const empty = { m1: 0, m2: 0, m3: 0, m4: 0, m5: 0, m6: 0 };
const rows: Row[] = [
{ id: 'B1', parentId: null, name: 'Sales Division', ...empty },
{ id: 'B11', parentId: 'B1', name: 'Domestic Sales', ...empty },
{ id: 'B12', parentId: 'B1', name: 'Overseas Sales', ...empty },
{ id: 'B2', parentId: null, name: 'Dev Division', ...empty },
{ id: 'B21', parentId: 'B2', name: 'Platform Team', ...empty },
{ id: 'B22', parentId: 'B2', name: 'App Dev Team', ...empty },
...leaves.map(([id, parentId, name], i) => ({
id,
parentId,
name,
m1: month(i, 1),
m2: month(i, 2),
m3: month(i, 3),
m4: month(i, 4),
m5: month(i, 5),
m6: month(i, 6),
})),
];
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Item', width: 200 },
...months.map((id, i) => ({
id,
title: monthNames[i],
kind: 'number' as const,
width: 110,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
{
id: 'total',
title: 'Total',
kind: 'number',
width: 130,
align: 'end',
getValue: (row) => months.reduce((sum, key) => sum + row[key], 0),
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
},
],
// Headers that group columns. Groups can nest, and a collapsible group folds with the toggle in its header.
headerGroups: [
{
id: 'h1',
title: '2026 H1',
children: [
{ id: 'q1', title: 'Q1', collapsible: true, children: ['m1', 'm2', 'm3'] },
{ id: 'q2', title: 'Q2', collapsible: true, children: ['m4', 'm5', 'm6'] },
],
},
],
rows,
rowKey: 'id',
// parentAggregates: a parent row shows the sum (aggregate: 'sum') of the rows below instead of its own value.
tree: { parentKey: 'parentId', column: 'name', expandDepth: 1, parentAggregates: true },
};
export const actions = {
quarter: (api: GridApi<Row>, value?: string) => {
api.setHeaderGroupCollapsed('q1', value === 'closed');
api.setHeaderGroupCollapsed('q2', value === 'closed');
},
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};