합계 줄을 위쪽에 두기Put the total row at the top
합계 줄을 맨 아래 대신 헤더 바로 아래에 둘 수 있어요. 숫자가 많은 표에서 합계를 먼저 보여 주고 싶을 때 좋아요.Place the total row right under the header instead of at the bottom, handy when the total matters most in a long table.
코드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="position">
<option value="top" selected>위</option>
<option value="bottom">아래</option>
<option value="off">숨기기</option>
</select>
</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('position').addEventListener('change', (event) => actions.position(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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('ko-KR');
export const options = {
columns: [
{ id: 'branch', title: '지점', width: 120 },
...months.map((id, k) => ({
id,
title: `${k + 1}월`,
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
summary: { position: 'top', label: '합계' },
};
export const actions = {
position: (api, value) => api.setOptions({
summary: value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
}),
};<!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="position">
<option value="top" selected>위</option>
<option value="bottom">아래</option>
<option value="off">숨기기</option>
</select>
</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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('ko-KR');
const options = {
columns: [
{ id: 'branch', title: '지점', width: 120 },
...months.map((id, k) => ({
id,
title: `${k + 1}월`,
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
summary: { position: 'top', label: '합계' },
};
const actions = {
position: (api, value) => api.setOptions({
summary: value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
}),
};
options.ariaLabel = "합계 줄을 위쪽에 두기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('position').addEventListener('change', (event) => actions.position(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.position(api, event.target.value)}
>
<option value="top">위</option>
<option value="bottom">아래</option>
<option value="off">숨기기</option>
</select>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { 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 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: 'branch', title: '지점', width: 120 },
...months.map((id, k) => ({
id,
title: `${k + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
summary: { position: 'top', label: '합계' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
}),
};버튼을 누르면 이 예제의 코드가 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.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="top" selected>위</option>
<option value="bottom">아래</option>
<option value="off">숨기기</option>
</select>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { 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 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: 'branch', title: '지점', width: 120 },
...months.map((id, k) => ({
id,
title: `${k + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
summary: { position: 'top', label: '합계' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
}),
};버튼을 누르면 이 예제의 코드가 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.position(api, $any($event.target).value)"
>
<option value="top" selected>위</option>
<option value="bottom">아래</option>
<option value="off">숨기기</option>
</select>
</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 { 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 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: 'branch', title: '지점', width: 120 },
...months.map((id, k) => ({
id,
title: `${k + 1}월`,
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
summary: { position: 'top', label: '합계' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
}),
};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="Total row position" id="position">
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
<option value="off">Hidden</option>
</select>
</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('position').addEventListener('change', (event) => actions.position(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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('en-US');
export const options = {
columns: [
{ id: 'branch', title: 'Branch', width: 120 },
...months.map((id, k) => ({
id,
title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// With position: 'top' the summary row moves right below the header. The default is 'bottom'.
summary: { position: 'top', label: 'Total' },
};
export const actions = {
position: (api, value) => api.setOptions({
summary: value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
}),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Put the total row at the top</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Total row position" id="position">
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
<option value="off">Hidden</option>
</select>
</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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('en-US');
const options = {
columns: [
{ id: 'branch', title: 'Branch', width: 120 },
...months.map((id, k) => ({
id,
title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
kind: 'number',
width: 90,
align: 'end',
aggregate: 'sum',
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// With position: 'top' the summary row moves right below the header. The default is 'bottom'.
summary: { position: 'top', label: 'Total' },
};
const actions = {
position: (api, value) => api.setOptions({
summary: value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
}),
};
options.ariaLabel = "Put the total row at the top";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('position').addEventListener('change', (event) => actions.position(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="Total row position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="top">Top</option>
<option value="bottom">Bottom</option>
<option value="off">Hidden</option>
</select>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { 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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'branch', title: 'Branch', width: 120 },
...months.map((id, k) => ({
id,
title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// With position: 'top' the summary row moves right below the header. The default is 'bottom'.
summary: { position: 'top', label: 'Total' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
}),
};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="Total row position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
<option value="off">Hidden</option>
</select>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { 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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'branch', title: 'Branch', width: 120 },
...months.map((id, k) => ({
id,
title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// With position: 'top' the summary row moves right below the header. The default is 'bottom'.
summary: { position: 'top', label: 'Total' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
}),
};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="Total row position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="top" selected>Top</option>
<option value="bottom">Bottom</option>
<option value="off">Hidden</option>
</select>
</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 { 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 months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'] as const;
const money = (value: unknown) => Number(value).toLocaleString('en-US');
export const options: GridOptions<Row> = {
columns: [
{ id: 'branch', title: 'Branch', width: 120 },
...months.map((id, k) => ({
id,
title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
kind: 'number' as const,
width: 90,
align: 'end' as const,
aggregate: 'sum' as const,
formatValue: money,
aggregateFormat: money,
})),
],
rows,
rowKey: 'id',
// With position: 'top' the summary row moves right below the header. The default is 'bottom'.
summary: { position: 'top', label: 'Total' },
};
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setOptions({
summary:
value === 'off'
? false
: { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
}),
};