합계 줄에 원하는 글자 넣기Put your own wording in the total row
합계 줄의 숫자 앞뒤에 "합계", "평균", "곳" 같은 말을 붙이고, 맨 앞 칸의 문구도 바꿀 수 있어요. 컬럼마다 다른 계산을 쓸 수도 있어요.Add words such as "Sum", "Average" or a unit before or after the totals, and change the label in the first cell. Each column can use a different calculation.
코드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="decorate">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<input
type="text"
aria-label="맨 앞 문구"
placeholder="맨 앞 문구 (예: ∑ 합계)"
id="first"
/>
</div>
<div id="grid" style="height: 360px"></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('decorate').addEventListener('change', (event) => actions.decorate(api, event.target.value));
document.getElementById('first').addEventListener('input', (event) => actions.first(api, event.target.value));const branches = [
'서울 본점',
'강남점',
'부산점',
'대구점',
'인천점',
'광주점',
'대전점',
'제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value) => Number(value).toLocaleString('ko-KR');
// 합계 줄의 글자는 컬럼마다 aggregateFormat으로 정해요. 계산 결과를 받아서 원하는 문장으로 돌려주면 돼요.
// 계산(aggregate)은 그대로 두고 글자만 꾸미는 거라, 앞에 "약", 뒤에 "곳" 같은 말도 붙일 수 있어요.
let decorate = true;
let first = '∑ 합계';
const plain = (value) => Number(value).toLocaleString('ko-KR', { maximumFractionDigits: 1 });
const text = (make) => (value) => decorate ? make(plain(value)) : plain(value);
const columns = () => [
{ id: 'branch', title: '지점', width: 120 },
{
id: 'm1',
title: '1월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `합계 ${v}`),
},
{
id: 'm2',
title: '2월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `평균 ${v}`),
},
{
id: 'm3',
title: '3월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `최대 ${v}`),
},
{
id: 'm4',
title: '4월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `최소 ${v}`),
},
{
id: 'm5',
title: '5월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v}곳`),
},
{
id: 'm6',
title: '6월',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `약 ${v}백만원`),
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api, value) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// 합계 줄 맨 앞 칸(첫 컬럼)의 문구예요. 비우면 기본 글자("합계")가 나와요.
first: (api, value) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};<!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="decorate">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<input
type="text"
aria-label="맨 앞 문구"
placeholder="맨 앞 문구 (예: ∑ 합계)"
id="first"
/>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const branches = [
'서울 본점',
'강남점',
'부산점',
'대구점',
'인천점',
'광주점',
'대전점',
'제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value) => Number(value).toLocaleString('ko-KR');
// 합계 줄의 글자는 컬럼마다 aggregateFormat으로 정해요. 계산 결과를 받아서 원하는 문장으로 돌려주면 돼요.
// 계산(aggregate)은 그대로 두고 글자만 꾸미는 거라, 앞에 "약", 뒤에 "곳" 같은 말도 붙일 수 있어요.
let decorate = true;
let first = '∑ 합계';
const plain = (value) => Number(value).toLocaleString('ko-KR', { maximumFractionDigits: 1 });
const text = (make) => (value) => decorate ? make(plain(value)) : plain(value);
const columns = () => [
{ id: 'branch', title: '지점', width: 120 },
{
id: 'm1',
title: '1월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `합계 ${v}`),
},
{
id: 'm2',
title: '2월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `평균 ${v}`),
},
{
id: 'm3',
title: '3월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `최대 ${v}`),
},
{
id: 'm4',
title: '4월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `최소 ${v}`),
},
{
id: 'm5',
title: '5월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v}곳`),
},
{
id: 'm6',
title: '6월',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `약 ${v}백만원`),
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
const actions = {
decorate: (api, value) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// 합계 줄 맨 앞 칸(첫 컬럼)의 문구예요. 비우면 기본 글자("합계")가 나와요.
first: (api, value) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};
options.ariaLabel = "합계 줄에 원하는 글자 넣기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('decorate').addEventListener('change', (event) => actions.decorate(api, event.target.value));
document.getElementById('first').addEventListener('input', (event) => actions.first(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.decorate(api, event.target.value)}
>
<option value="on">켜기</option>
<option value="off">끄기</option>
</select>
<input
type="text"
aria-label="맨 앞 문구"
placeholder="맨 앞 문구 (예: ∑ 합계)"
disabled={!api}
onChange={(event) => api && actions.first(api, event.target.value)}
/>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = [
'서울 본점',
'강남점',
'부산점',
'대구점',
'인천점',
'광주점',
'대전점',
'제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
// 합계 줄의 글자는 컬럼마다 aggregateFormat으로 정해요. 계산 결과를 받아서 원하는 문장으로 돌려주면 돼요.
// 계산(aggregate)은 그대로 두고 글자만 꾸미는 거라, 앞에 "약", 뒤에 "곳" 같은 말도 붙일 수 있어요.
let decorate = true;
let first = '∑ 합계';
const plain = (value: unknown) =>
Number(value).toLocaleString('ko-KR', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: '지점', width: 120 },
{
id: 'm1',
title: '1월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `합계 ${v}`),
},
{
id: 'm2',
title: '2월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `평균 ${v}`),
},
{
id: 'm3',
title: '3월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `최대 ${v}`),
},
{
id: 'm4',
title: '4월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `최소 ${v}`),
},
{
id: 'm5',
title: '5월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v}곳`),
},
{
id: 'm6',
title: '6월',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `약 ${v}백만원`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// 합계 줄 맨 앞 칸(첫 컬럼)의 문구예요. 비우면 기본 글자("합계")가 나와요.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};버튼을 누르면 이 예제의 코드가 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.decorate(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<input
type="text"
aria-label="맨 앞 문구"
placeholder="맨 앞 문구 (예: ∑ 합계)"
:disabled="!api"
@input="api && actions.first(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = [
'서울 본점',
'강남점',
'부산점',
'대구점',
'인천점',
'광주점',
'대전점',
'제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
// 합계 줄의 글자는 컬럼마다 aggregateFormat으로 정해요. 계산 결과를 받아서 원하는 문장으로 돌려주면 돼요.
// 계산(aggregate)은 그대로 두고 글자만 꾸미는 거라, 앞에 "약", 뒤에 "곳" 같은 말도 붙일 수 있어요.
let decorate = true;
let first = '∑ 합계';
const plain = (value: unknown) =>
Number(value).toLocaleString('ko-KR', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: '지점', width: 120 },
{
id: 'm1',
title: '1월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `합계 ${v}`),
},
{
id: 'm2',
title: '2월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `평균 ${v}`),
},
{
id: 'm3',
title: '3월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `최대 ${v}`),
},
{
id: 'm4',
title: '4월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `최소 ${v}`),
},
{
id: 'm5',
title: '5월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v}곳`),
},
{
id: 'm6',
title: '6월',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `약 ${v}백만원`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// 합계 줄 맨 앞 칸(첫 컬럼)의 문구예요. 비우면 기본 글자("합계")가 나와요.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};버튼을 누르면 이 예제의 코드가 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.decorate(api, $any($event.target).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<input
type="text"
aria-label="맨 앞 문구"
placeholder="맨 앞 문구 (예: ∑ 합계)"
[disabled]="!api"
(input)="api && actions.first(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 360px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = [
'서울 본점',
'강남점',
'부산점',
'대구점',
'인천점',
'광주점',
'대전점',
'제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('ko-KR');
// 합계 줄의 글자는 컬럼마다 aggregateFormat으로 정해요. 계산 결과를 받아서 원하는 문장으로 돌려주면 돼요.
// 계산(aggregate)은 그대로 두고 글자만 꾸미는 거라, 앞에 "약", 뒤에 "곳" 같은 말도 붙일 수 있어요.
let decorate = true;
let first = '∑ 합계';
const plain = (value: unknown) =>
Number(value).toLocaleString('ko-KR', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: '지점', width: 120 },
{
id: 'm1',
title: '1월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `합계 ${v}`),
},
{
id: 'm2',
title: '2월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `평균 ${v}`),
},
{
id: 'm3',
title: '3월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `최대 ${v}`),
},
{
id: 'm4',
title: '4월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `최소 ${v}`),
},
{
id: 'm5',
title: '5월',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v}곳`),
},
{
id: 'm6',
title: '6월',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `약 ${v}백만원`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// 합계 줄 맨 앞 칸(첫 컬럼)의 문구예요. 비우면 기본 글자("합계")가 나와요.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};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="Decorations" id="decorate">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<input
type="text"
aria-label="First label"
placeholder="First label (e.g. Total)"
id="first"
/>
</div>
<div id="grid" style="height: 360px"></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('decorate').addEventListener('change', (event) => actions.decorate(api, event.target.value));
document.getElementById('first').addEventListener('input', (event) => actions.first(api, event.target.value));const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
'Capital',
'Capital',
'Yeongnam',
'Yeongnam',
'Capital',
'Honam',
'Chungcheong',
'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value) => Number(value).toLocaleString('en-US');
// The text of the summary row is set per column with aggregateFormat. Take the calculated result and return any sentence you like.
// The calculation (aggregate) stays the same and only the text is decorated, so you can add words such as "about" before or "branches" after.
let decorate = true;
let first = '∑ Total';
const plain = (value) => Number(value).toLocaleString('en-US', { maximumFractionDigits: 1 });
const text = (make) => (value) => decorate ? make(plain(value)) : plain(value);
const columns = () => [
{ id: 'branch', title: 'Branch', width: 120 },
{
id: 'm1',
title: 'Jan',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `Total ${v}`),
},
{
id: 'm2',
title: 'Feb',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `Avg ${v}`),
},
{
id: 'm3',
title: 'Mar',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `Max ${v}`),
},
{
id: 'm4',
title: 'Apr',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `Min ${v}`),
},
{
id: 'm5',
title: 'May',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v} branches`),
},
{
id: 'm6',
title: 'Jun',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `About $${v}K`),
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api, value) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// The text of the first cell (first column) of the summary row. If empty, the default text ("Total") is shown.
first: (api, value) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Put your own wording in the total row</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Decorations" id="decorate">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<input
type="text"
aria-label="First label"
placeholder="First label (e.g. Total)"
id="first"
/>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
'Capital',
'Capital',
'Yeongnam',
'Yeongnam',
'Capital',
'Honam',
'Chungcheong',
'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value) => Number(value).toLocaleString('en-US');
// The text of the summary row is set per column with aggregateFormat. Take the calculated result and return any sentence you like.
// The calculation (aggregate) stays the same and only the text is decorated, so you can add words such as "about" before or "branches" after.
let decorate = true;
let first = '∑ Total';
const plain = (value) => Number(value).toLocaleString('en-US', { maximumFractionDigits: 1 });
const text = (make) => (value) => decorate ? make(plain(value)) : plain(value);
const columns = () => [
{ id: 'branch', title: 'Branch', width: 120 },
{
id: 'm1',
title: 'Jan',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `Total ${v}`),
},
{
id: 'm2',
title: 'Feb',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `Avg ${v}`),
},
{
id: 'm3',
title: 'Mar',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `Max ${v}`),
},
{
id: 'm4',
title: 'Apr',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `Min ${v}`),
},
{
id: 'm5',
title: 'May',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v} branches`),
},
{
id: 'm6',
title: 'Jun',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `About $${v}K`),
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
const actions = {
decorate: (api, value) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// The text of the first cell (first column) of the summary row. If empty, the default text ("Total") is shown.
first: (api, value) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};
options.ariaLabel = "Put your own wording in the total row";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('decorate').addEventListener('change', (event) => actions.decorate(api, event.target.value));
document.getElementById('first').addEventListener('input', (event) => actions.first(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="Decorations"
disabled={!api}
onChange={(event) => api && actions.decorate(api, event.target.value)}
>
<option value="on">On</option>
<option value="off">Off</option>
</select>
<input
type="text"
aria-label="First label"
placeholder="First label (e.g. Total)"
disabled={!api}
onChange={(event) => api && actions.first(api, event.target.value)}
/>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
'Capital',
'Capital',
'Yeongnam',
'Yeongnam',
'Capital',
'Honam',
'Chungcheong',
'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('en-US');
// The text of the summary row is set per column with aggregateFormat. Take the calculated result and return any sentence you like.
// The calculation (aggregate) stays the same and only the text is decorated, so you can add words such as "about" before or "branches" after.
let decorate = true;
let first = '∑ Total';
const plain = (value: unknown) =>
Number(value).toLocaleString('en-US', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: 'Branch', width: 120 },
{
id: 'm1',
title: 'Jan',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `Total ${v}`),
},
{
id: 'm2',
title: 'Feb',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `Avg ${v}`),
},
{
id: 'm3',
title: 'Mar',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `Max ${v}`),
},
{
id: 'm4',
title: 'Apr',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `Min ${v}`),
},
{
id: 'm5',
title: 'May',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v} branches`),
},
{
id: 'm6',
title: 'Jun',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `About $${v}K`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// The text of the first cell (first column) of the summary row. If empty, the default text ("Total") is shown.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};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="Decorations"
:disabled="!api"
@change="api && actions.decorate(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<input
type="text"
aria-label="First label"
placeholder="First label (e.g. Total)"
:disabled="!api"
@input="api && actions.first(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
'Capital',
'Capital',
'Yeongnam',
'Yeongnam',
'Capital',
'Honam',
'Chungcheong',
'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('en-US');
// The text of the summary row is set per column with aggregateFormat. Take the calculated result and return any sentence you like.
// The calculation (aggregate) stays the same and only the text is decorated, so you can add words such as "about" before or "branches" after.
let decorate = true;
let first = '∑ Total';
const plain = (value: unknown) =>
Number(value).toLocaleString('en-US', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: 'Branch', width: 120 },
{
id: 'm1',
title: 'Jan',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `Total ${v}`),
},
{
id: 'm2',
title: 'Feb',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `Avg ${v}`),
},
{
id: 'm3',
title: 'Mar',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `Max ${v}`),
},
{
id: 'm4',
title: 'Apr',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `Min ${v}`),
},
{
id: 'm5',
title: 'May',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v} branches`),
},
{
id: 'm6',
title: 'Jun',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `About $${v}K`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// The text of the first cell (first column) of the summary row. If empty, the default text ("Total") is shown.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};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="Decorations"
[disabled]="!api"
(change)="api && actions.decorate(api, $any($event.target).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<input
type="text"
aria-label="First label"
placeholder="First label (e.g. Total)"
[disabled]="!api"
(input)="api && actions.first(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 360px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
branch: string;
region: string;
m1: number;
m2: number;
m3: number;
m4: number;
m5: number;
m6: number;
}
const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
'Capital',
'Capital',
'Yeongnam',
'Yeongnam',
'Capital',
'Honam',
'Chungcheong',
'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i: number, k: number) => 20 + ((i * 13 + k * 7) % 70);
const rows: Row[] = branches.map((branch, i) => ({
id: i + 1,
branch,
region: regions[i],
m1: sales(i, 1),
m2: sales(i, 2),
m3: sales(i, 3),
m4: sales(i, 4),
m5: sales(i, 5),
m6: sales(i, 6),
}));
const money = (value: unknown) => Number(value).toLocaleString('en-US');
// The text of the summary row is set per column with aggregateFormat. Take the calculated result and return any sentence you like.
// The calculation (aggregate) stays the same and only the text is decorated, so you can add words such as "about" before or "branches" after.
let decorate = true;
let first = '∑ Total';
const plain = (value: unknown) =>
Number(value).toLocaleString('en-US', { maximumFractionDigits: 1 });
const text = (make: (value: string) => string) => (value: unknown) =>
decorate ? make(plain(value)) : plain(value);
const columns = (): ColumnDef<Row>[] => [
{ id: 'branch', title: 'Branch', width: 120 },
{
id: 'm1',
title: 'Jan',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `Total ${v}`),
},
{
id: 'm2',
title: 'Feb',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'avg',
formatValue: money,
aggregateFormat: text((v) => `Avg ${v}`),
},
{
id: 'm3',
title: 'Mar',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'max',
formatValue: money,
aggregateFormat: text((v) => `Max ${v}`),
},
{
id: 'm4',
title: 'Apr',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'min',
formatValue: money,
aggregateFormat: text((v) => `Min ${v}`),
},
{
id: 'm5',
title: 'May',
kind: 'number',
width: 110,
align: 'end',
aggregate: 'count',
formatValue: money,
aggregateFormat: text((v) => `${v} branches`),
},
{
id: 'm6',
title: 'Jun',
kind: 'number',
width: 130,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: text((v) => `About $${v}K`),
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
summary: { label: first },
};
export const actions = {
decorate: (api: GridApi<Row>, value?: string) => {
decorate = value !== 'off';
api.setColumns(columns());
},
// The text of the first cell (first column) of the summary row. If empty, the default text ("Total") is shown.
first: (api: GridApi<Row>, value?: string) => {
first = (value ?? '').trim();
api.setOptions({ summary: first ? { label: first } : true });
},
};