분류 아래 상품, 소계는 분류 줄에Products under categories, totals on the category row
분류를 숨기고 '상품 / 분류' 한 칸에 분류 이름과 상품을 들여쓰기로 이어 보여 줘요. 소계는 별도 줄 없이 분류 줄에 함께 나와서, 접으면 분류별 판매량과 매출만 깔끔하게 남아요.The category column is hidden and category names with their products indent inside one Product / Category column. Subtotals live on the category rows, so folding leaves a clean list of totals.
코드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="fold">
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<div id="grid" style="height: 440px"></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('fold').addEventListener('change', (event) => actions.fold(api, event.target.value));// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA = [
['음료', ['아메리카노', '카페라떼', '녹차라떼']],
['베이커리', ['크루아상', '치즈케이크']],
['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 4500 * (12 + ((id * 17) % 80)),
});
}
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
export const options = {
columns: [
{ id: 'category', title: '분류', width: 100, hidden: true },
{ id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
{ id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '매출(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: '전체 합계' },
};
export const actions = {
fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};<!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="fold">
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<div id="grid" style="height: 440px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA = [
['음료', ['아메리카노', '카페라떼', '녹차라떼']],
['베이커리', ['크루아상', '치즈케이크']],
['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 4500 * (12 + ((id * 17) % 80)),
});
}
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
const options = {
columns: [
{ id: 'category', title: '분류', width: 100, hidden: true },
{ id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
{ id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '매출(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: '전체 합계' },
};
const actions = {
fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};
options.ariaLabel = "분류 아래 상품, 소계는 분류 줄에";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('fold').addEventListener('change', (event) => actions.fold(api, event.target.value));
</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.fold(api, event.target.value)}
>
<option value="all">모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA: [string, string[]][] = [
['음료', ['아메리카노', '카페라떼', '녹차라떼']],
['베이커리', ['크루아상', '치즈케이크']],
['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 4500 * (12 + ((id * 17) % 80)),
});
}
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: '분류', width: 100, hidden: true },
{ id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
{ id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '매출(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: '전체 합계' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};버튼을 누르면 이 예제의 코드가 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.fold(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<Grid style="height: 440px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA: [string, string[]][] = [
['음료', ['아메리카노', '카페라떼', '녹차라떼']],
['베이커리', ['크루아상', '치즈케이크']],
['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 4500 * (12 + ((id * 17) % 80)),
});
}
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: '분류', width: 100, hidden: true },
{ id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
{ id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '매출(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: '전체 합계' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};버튼을 누르면 이 예제의 코드가 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.fold(api, $any($event.target).value)"
>
<option value="all" selected>모두 펼치기</option>
<option value="none">모두 접기</option>
</select>
</div>
<mx-grid style="height: 440px" [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: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA: [string, string[]][] = [
['음료', ['아메리카노', '카페라떼', '녹차라떼']],
['베이커리', ['크루아상', '치즈케이크']],
['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 4500 * (12 + ((id * 17) % 80)),
});
}
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: '분류', width: 100, hidden: true },
{ id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
{ id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '매출(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: '전체 합계' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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="Expansion" id="fold">
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<div id="grid" style="height: 440px"></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('fold').addEventListener('change', (event) => actions.fold(api, event.target.value));// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA = [
['Drinks', ['Americano', 'Latte', 'Green tea latte']],
['Bakery', ['Croissant', 'Cheesecake']],
['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 5 * (12 + ((id * 17) % 80)),
});
}
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
export const options = {
columns: [
{ id: 'category', title: 'Category', width: 100, hidden: true },
{ id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
{
id: 'quantity',
title: 'Units sold',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
},
{
id: 'amount',
title: 'Revenue ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: 'Grand total' },
};
export const actions = {
fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Products under categories, totals on the category row</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Expansion" id="fold">
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<div id="grid" style="height: 440px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA = [
['Drinks', ['Americano', 'Latte', 'Green tea latte']],
['Bakery', ['Croissant', 'Cheesecake']],
['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 5 * (12 + ((id * 17) % 80)),
});
}
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
const options = {
columns: [
{ id: 'category', title: 'Category', width: 100, hidden: true },
{ id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
{
id: 'quantity',
title: 'Units sold',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
},
{
id: 'amount',
title: 'Revenue ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: 'Grand total' },
};
const actions = {
fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};
options.ariaLabel = "Products under categories, totals on the category row";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('fold').addEventListener('change', (event) => actions.fold(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 { 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="Expansion"
disabled={!api}
onChange={(event) => api && actions.fold(api, event.target.value)}
>
<option value="all">Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<Grid style={{ height: 440 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA: [string, string[]][] = [
['Drinks', ['Americano', 'Latte', 'Green tea latte']],
['Bakery', ['Croissant', 'Cheesecake']],
['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 5 * (12 + ((id * 17) % 80)),
});
}
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: 'Category', width: 100, hidden: true },
{ id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
{
id: 'quantity',
title: 'Units sold',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
},
{
id: 'amount',
title: 'Revenue ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: 'Grand total' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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="Expansion"
:disabled="!api"
@change="api && actions.fold(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<Grid style="height: 440px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA: [string, string[]][] = [
['Drinks', ['Americano', 'Latte', 'Green tea latte']],
['Bakery', ['Croissant', 'Cheesecake']],
['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 5 * (12 + ((id * 17) % 80)),
});
}
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: 'Category', width: 100, hidden: true },
{ id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
{
id: 'quantity',
title: 'Units sold',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
},
{
id: 'amount',
title: 'Revenue ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: 'Grand total' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};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="Expansion"
[disabled]="!api"
(change)="api && actions.fold(api, $any($event.target).value)"
>
<option value="all" selected>Expand all</option>
<option value="none">Collapse all</option>
</select>
</div>
<mx-grid style="height: 440px" [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: number;
category: string;
product: string;
quantity: number;
amount: number;
}
// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA: [string, string[]][] = [
['Drinks', ['Americano', 'Latte', 'Green tea latte']],
['Bakery', ['Croissant', 'Cheesecake']],
['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows: Row[] = [];
for (const [category, products] of DATA) {
for (const product of products) {
const id = rows.length + 1;
rows.push({
id,
category,
product,
quantity: 12 + ((id * 17) % 80),
amount: 5 * (12 + ((id * 17) % 80)),
});
}
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
export const options: GridOptions<Row> = {
columns: [
{ id: 'category', title: 'Category', width: 100, hidden: true },
{ id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
{
id: 'quantity',
title: 'Units sold',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
},
{
id: 'amount',
title: 'Revenue ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows,
rowKey: 'id',
grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
summary: { label: 'Grand total' },
};
export const actions = {
fold: (api: GridApi<Row>, value?: string) =>
value === 'none' ? api.collapseAll() : api.expandAll(),
};