그룹 줄의 이름·합계 모양과 펼침 아이콘 바꾸기Format group labels, totals and the toggle icon
묶음 줄에 "결제 완료"처럼 읽기 좋은 이름과 "1,200원" 같은 합계를 보여 주고, 펼침 아이콘을 화살표·폴더·더하기빼기로 바꿔요.Show readable group names and money totals on group rows and switch the toggle icon between arrow, folder and plus/minus.
코드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="icon">
<option value="arrow" selected>화살표</option>
<option value="folder">폴더</option>
<option value="plusMinus">더하기·빼기</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 300px"></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('icon').addEventListener('change', (event) => actions.icon(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));const statuses = ['paid', 'pending', 'refunded', ''];
const labels = {
paid: '결제 완료',
pending: '입금 대기',
refunded: '환불',
};
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회'];
const grouping = (toggleIcon) => ({ by: ['status'], expandDepth: 0, toggleIcon });
// 그룹 줄의 이름은 묶은 컬럼의 formatValue로 써요. 같은 함수가 그 컬럼의 일반 칸에도 쓰이니 빈 값도 안전하게 처리해요.
// aggregateFormat은 그룹 줄과 총계 줄에만 적용돼요.
export const options = {
columns: [
{
id: 'status',
title: '주문 상태',
width: 200,
formatValue: (value) => value === '' ? '상태 없음' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: '주문번호', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `${Number(value).toLocaleString('ko-KR')}원`,
aggregateFormat: (value, ctx) => ctx.scope === 'total'
? `전체 ${Number(value).toLocaleString('ko-KR')}원`
: `${Number(value).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4],
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4],
amount: 40000 + ((i * 53) % 210) * 1000 + 250 * (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: '모든 주문' },
};
export const actions = {
icon: (api, value) => api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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="icon">
<option value="arrow" selected>화살표</option>
<option value="folder">폴더</option>
<option value="plusMinus">더하기·빼기</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 300px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const statuses = ['paid', 'pending', 'refunded', ''];
const labels = {
paid: '결제 완료',
pending: '입금 대기',
refunded: '환불',
};
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회'];
const grouping = (toggleIcon) => ({ by: ['status'], expandDepth: 0, toggleIcon });
// 그룹 줄의 이름은 묶은 컬럼의 formatValue로 써요. 같은 함수가 그 컬럼의 일반 칸에도 쓰이니 빈 값도 안전하게 처리해요.
// aggregateFormat은 그룹 줄과 총계 줄에만 적용돼요.
const options = {
columns: [
{
id: 'status',
title: '주문 상태',
width: 200,
formatValue: (value) => value === '' ? '상태 없음' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: '주문번호', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `${Number(value).toLocaleString('ko-KR')}원`,
aggregateFormat: (value, ctx) => ctx.scope === 'total'
? `전체 ${Number(value).toLocaleString('ko-KR')}원`
: `${Number(value).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4],
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4],
amount: 40000 + ((i * 53) % 210) * 1000 + 250 * (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: '모든 주문' },
};
const actions = {
icon: (api, value) => api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "그룹 줄의 이름·합계 모양과 펼침 아이콘 바꾸기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('icon').addEventListener('change', (event) => actions.icon(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.icon(api, event.target.value)}
>
<option value="arrow">화살표</option>
<option value="folder">폴더</option>
<option value="plusMinus">더하기·빼기</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: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: '결제 완료',
pending: '입금 대기',
refunded: '환불',
};
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// 그룹 줄의 이름은 묶은 컬럼의 formatValue로 써요. 같은 함수가 그 컬럼의 일반 칸에도 쓰이니 빈 값도 안전하게 처리해요.
// aggregateFormat은 그룹 줄과 총계 줄에만 적용돼요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: '주문 상태',
width: 200,
formatValue: (value) =>
value === '' ? '상태 없음' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: '주문번호', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `${Number(value).toLocaleString('ko-KR')}원`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `전체 ${Number(value).toLocaleString('ko-KR')}원`
: `${Number(value).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40000 + ((i * 53) % 210) * 1000 + 250 * (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: '모든 주문' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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.icon(api, ($event.target as HTMLSelectElement).value)"
>
<option value="arrow" selected>화살표</option>
<option value="folder">폴더</option>
<option value="plusMinus">더하기·빼기</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: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: '결제 완료',
pending: '입금 대기',
refunded: '환불',
};
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// 그룹 줄의 이름은 묶은 컬럼의 formatValue로 써요. 같은 함수가 그 컬럼의 일반 칸에도 쓰이니 빈 값도 안전하게 처리해요.
// aggregateFormat은 그룹 줄과 총계 줄에만 적용돼요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: '주문 상태',
width: 200,
formatValue: (value) =>
value === '' ? '상태 없음' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: '주문번호', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `${Number(value).toLocaleString('ko-KR')}원`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `전체 ${Number(value).toLocaleString('ko-KR')}원`
: `${Number(value).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40000 + ((i * 53) % 210) * 1000 + 250 * (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: '모든 주문' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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.icon(api, $any($event.target).value)"
>
<option value="arrow" selected>화살표</option>
<option value="folder">폴더</option>
<option value="plusMinus">더하기·빼기</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: 300px" [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;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: '결제 완료',
pending: '입금 대기',
refunded: '환불',
};
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// 그룹 줄의 이름은 묶은 컬럼의 formatValue로 써요. 같은 함수가 그 컬럼의 일반 칸에도 쓰이니 빈 값도 안전하게 처리해요.
// aggregateFormat은 그룹 줄과 총계 줄에만 적용돼요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: '주문 상태',
width: 200,
formatValue: (value) =>
value === '' ? '상태 없음' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: '주문번호', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `${Number(value).toLocaleString('ko-KR')}원`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `전체 ${Number(value).toLocaleString('ko-KR')}원`
: `${Number(value).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40000 + ((i * 53) % 210) * 1000 + 250 * (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: '모든 주문' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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="Toggle icon" id="icon">
<option value="arrow" selected>Arrow</option>
<option value="folder">Folder</option>
<option value="plusMinus">Plus/minus</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 300px"></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('icon').addEventListener('change', (event) => actions.icon(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));const statuses = ['paid', 'pending', 'refunded', ''];
const labels = {
paid: 'Paid',
pending: 'Awaiting payment',
refunded: 'Refunded',
};
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Trading'];
const grouping = (toggleIcon) => ({ by: ['status'], expandDepth: 0, toggleIcon });
// A group row's name comes from the grouped column's formatValue. The same function also formats that column's normal cells, so it handles empty values safely.
// aggregateFormat applies only to group rows and the total row.
export const options = {
columns: [
{
id: 'status',
title: 'Order status',
width: 200,
formatValue: (value) => value === '' ? 'No status' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: 'Order no.', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: 'Customer', width: 130 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
aggregateFormat: (value, ctx) => ctx.scope === 'total'
? `Total $${Number(value).toLocaleString('en-US')}`
: `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4],
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4],
amount: 40 + ((i * 53) % 210) + (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: 'All orders' },
};
export const actions = {
icon: (api, value) => api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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>Format group labels, totals and the toggle icon</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Toggle icon" id="icon">
<option value="arrow" selected>Arrow</option>
<option value="folder">Folder</option>
<option value="plusMinus">Plus/minus</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 300px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const statuses = ['paid', 'pending', 'refunded', ''];
const labels = {
paid: 'Paid',
pending: 'Awaiting payment',
refunded: 'Refunded',
};
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Trading'];
const grouping = (toggleIcon) => ({ by: ['status'], expandDepth: 0, toggleIcon });
// A group row's name comes from the grouped column's formatValue. The same function also formats that column's normal cells, so it handles empty values safely.
// aggregateFormat applies only to group rows and the total row.
const options = {
columns: [
{
id: 'status',
title: 'Order status',
width: 200,
formatValue: (value) => value === '' ? 'No status' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: 'Order no.', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: 'Customer', width: 130 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
aggregateFormat: (value, ctx) => ctx.scope === 'total'
? `Total $${Number(value).toLocaleString('en-US')}`
: `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4],
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4],
amount: 40 + ((i * 53) % 210) + (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: 'All orders' },
};
const actions = {
icon: (api, value) => api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
expandAll: (api) => api.expandAll(),
collapseAll: (api) => api.collapseAll(),
};
options.ariaLabel = "Format group labels, totals and the toggle icon";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('icon').addEventListener('change', (event) => actions.icon(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="Toggle icon"
disabled={!api}
onChange={(event) => api && actions.icon(api, event.target.value)}
>
<option value="arrow">Arrow</option>
<option value="folder">Folder</option>
<option value="plusMinus">Plus/minus</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: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: 'Paid',
pending: 'Awaiting payment',
refunded: 'Refunded',
};
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Trading'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// A group row's name comes from the grouped column's formatValue. The same function also formats that column's normal cells, so it handles empty values safely.
// aggregateFormat applies only to group rows and the total row.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: 'Order status',
width: 200,
formatValue: (value) =>
value === '' ? 'No status' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: 'Order no.', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: 'Customer', width: 130 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `Total $${Number(value).toLocaleString('en-US')}`
: `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40 + ((i * 53) % 210) + (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: 'All orders' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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="Toggle icon"
:disabled="!api"
@change="api && actions.icon(api, ($event.target as HTMLSelectElement).value)"
>
<option value="arrow" selected>Arrow</option>
<option value="folder">Folder</option>
<option value="plusMinus">Plus/minus</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: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: 'Paid',
pending: 'Awaiting payment',
refunded: 'Refunded',
};
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Trading'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// A group row's name comes from the grouped column's formatValue. The same function also formats that column's normal cells, so it handles empty values safely.
// aggregateFormat applies only to group rows and the total row.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: 'Order status',
width: 200,
formatValue: (value) =>
value === '' ? 'No status' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: 'Order no.', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: 'Customer', width: 130 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `Total $${Number(value).toLocaleString('en-US')}`
: `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40 + ((i * 53) % 210) + (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: 'All orders' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
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="Toggle icon"
[disabled]="!api"
(change)="api && actions.icon(api, $any($event.target).value)"
>
<option value="arrow" selected>Arrow</option>
<option value="folder">Folder</option>
<option value="plusMinus">Plus/minus</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: 300px" [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;
status: string;
order: string;
customer: string;
amount: number;
}
const statuses = ['paid', 'pending', 'refunded', ''];
const labels: Record<string, string> = {
paid: 'Paid',
pending: 'Awaiting payment',
refunded: 'Refunded',
};
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Trading'];
type Icon = 'arrow' | 'folder' | 'plusMinus';
const grouping = (toggleIcon: Icon) => ({ by: ['status'], expandDepth: 0 as const, toggleIcon });
// A group row's name comes from the grouped column's formatValue. The same function also formats that column's normal cells, so it handles empty values safely.
// aggregateFormat applies only to group rows and the total row.
export const options: GridOptions<Row> = {
columns: [
{
id: 'status',
title: 'Order status',
width: 200,
formatValue: (value) =>
value === '' ? 'No status' : (labels[String(value)] ?? String(value)),
},
{ id: 'order', title: 'Order no.', width: 110, aggregate: 'rowCount' },
{ id: 'customer', title: 'Customer', width: 130 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 150,
align: 'end',
aggregate: 'sum',
formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
aggregateFormat: (value, ctx) =>
ctx.scope === 'total'
? `Total $${Number(value).toLocaleString('en-US')}`
: `$${Number(value).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
status: statuses[i % 4] as string,
order: `#${1000 + i}`,
customer: customers[(i + Math.floor(i / 4)) % 4] as string,
amount: 40 + ((i * 53) % 210) + (i % 4),
})),
rowKey: 'id',
grouping: grouping('arrow'),
summary: { label: 'All orders' },
};
export const actions = {
icon: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: grouping(value === 'folder' || value === 'plusMinus' ? value : 'arrow'),
}),
expandAll: (api: GridApi<Row>) => api.expandAll(),
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
};