페이지마다 합계 줄과 강조 색이 따라와요Totals and highlights follow you across pages
페이지를 넘겨도 맨 아래 합계 줄은 전체 합계로 늘 붙어 있고, 서울 행이나 노트북 칸 같은 강조도 페이지마다 그대로 적용돼요. 이 페이지만의 합계는 기록 창에 따로 보여 줘요.A total row stays at the bottom of every page and shows the grand total, and row and cell highlights apply on each page. The current page's own sum appears in the log.
코드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="style">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 680px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('style').addEventListener('change', (event) => actions.style(api, event.target.value));const regions = ['서울', '부산', '대구', '제주'];
const products = ['노트북', '모니터', '무선 키보드', '웹캠', '도킹 스테이션'];
let styled = true;
// 페이지를 나눠도 합계 줄, 행 스타일, 칸 스타일이 그대로 따라와요.
// - 합계 줄은 모든 페이지의 합계를 한 줄로 아래에 붙여요(필터를 걸면 걸러진 행만의 합계예요).
// - rowClass / cellClass는 보이는 줄마다 불려서 조건에 맞는 곳에 클래스를 붙여요.
export const options = {
columns: [
{ id: 'region', title: '지역', width: 110 },
{
id: 'product',
title: '상품',
width: 150,
cellClass: (ctx) => (styled && ctx.value === '노트북' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 5) % 9),
amount: 59000 + ((i * 47000) % 900000),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === '서울' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: '전체 합계' },
pagination: { mode: 'client', pageSize: 10 },
};
// 클래스의 색은 테마 색으로 만들어서 밝은 화면과 어두운 화면 모두에서 읽혀요.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style;
export function setup(api, log) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = () => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log({
ko: `${api.getPage()}페이지 금액 합계 ${pageSum.toLocaleString('ko-KR')}원 · 전체 ${Number(api.getSummary().amount).toLocaleString('ko-KR')}원`,
en: `Page ${api.getPage()} amount total ${pageSum.toLocaleString('en-US')} KRW · all pages ${Number(api.getSummary().amount).toLocaleString('en-US')} KRW`,
});
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api, value) => {
styled = value !== 'off';
api.refresh();
},
};<!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="style">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 680px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const regions = ['서울', '부산', '대구', '제주'];
const products = ['노트북', '모니터', '무선 키보드', '웹캠', '도킹 스테이션'];
let styled = true;
// 페이지를 나눠도 합계 줄, 행 스타일, 칸 스타일이 그대로 따라와요.
// - 합계 줄은 모든 페이지의 합계를 한 줄로 아래에 붙여요(필터를 걸면 걸러진 행만의 합계예요).
// - rowClass / cellClass는 보이는 줄마다 불려서 조건에 맞는 곳에 클래스를 붙여요.
const options = {
columns: [
{ id: 'region', title: '지역', width: 110 },
{
id: 'product',
title: '상품',
width: 150,
cellClass: (ctx) => (styled && ctx.value === '노트북' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 5) % 9),
amount: 59000 + ((i * 47000) % 900000),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === '서울' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: '전체 합계' },
pagination: { mode: 'client', pageSize: 10 },
};
// 클래스의 색은 테마 색으로 만들어서 밝은 화면과 어두운 화면 모두에서 읽혀요.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style;
function setup(api, log) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = () => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log({
ko: `${api.getPage()}페이지 금액 합계 ${pageSum.toLocaleString('ko-KR')}원 · 전체 ${Number(api.getSummary().amount).toLocaleString('ko-KR')}원`,
en: `Page ${api.getPage()} amount total ${pageSum.toLocaleString('en-US')} KRW · all pages ${Number(api.getSummary().amount).toLocaleString('en-US')} KRW`,
});
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
const actions = {
style: (api, value) => {
styled = value !== 'off';
api.refresh();
},
};
options.ariaLabel = "페이지마다 합계 줄과 강조 색이 따라와요";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('style').addEventListener('change', (event) => actions.style(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="강조 스타일"
disabled={!api}
onChange={(event) => api && actions.style(api, event.target.value)}
>
<option value="on">켜기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style={{ height: 680 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['서울', '부산', '대구', '제주'];
const products = ['노트북', '모니터', '무선 키보드', '웹캠', '도킹 스테이션'];
let styled = true;
// 페이지를 나눠도 합계 줄, 행 스타일, 칸 스타일이 그대로 따라와요.
// - 합계 줄은 모든 페이지의 합계를 한 줄로 아래에 붙여요(필터를 걸면 걸러진 행만의 합계예요).
// - rowClass / cellClass는 보이는 줄마다 불려서 조건에 맞는 곳에 클래스를 붙여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: '지역', width: 110 },
{
id: 'product',
title: '상품',
width: 150,
cellClass: (ctx) => (styled && ctx.value === '노트북' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59000 + ((i * 47000) % 900000),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === '서울' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: '전체 합계' },
pagination: { mode: 'client', pageSize: 10 },
};
// 클래스의 색은 테마 색으로 만들어서 밝은 화면과 어두운 화면 모두에서 읽혀요.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log({
ko: `${api.getPage()}페이지 금액 합계 ${pageSum.toLocaleString('ko-KR')}원 · 전체 ${Number(api.getSummary().amount).toLocaleString('ko-KR')}원`,
en: `Page ${api.getPage()} amount total ${pageSum.toLocaleString('en-US')} KRW · all pages ${Number(api.getSummary().amount).toLocaleString('en-US')} KRW`,
});
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="강조 스타일"
:disabled="!api"
@change="api && actions.style(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style="height: 680px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['서울', '부산', '대구', '제주'];
const products = ['노트북', '모니터', '무선 키보드', '웹캠', '도킹 스테이션'];
let styled = true;
// 페이지를 나눠도 합계 줄, 행 스타일, 칸 스타일이 그대로 따라와요.
// - 합계 줄은 모든 페이지의 합계를 한 줄로 아래에 붙여요(필터를 걸면 걸러진 행만의 합계예요).
// - rowClass / cellClass는 보이는 줄마다 불려서 조건에 맞는 곳에 클래스를 붙여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: '지역', width: 110 },
{
id: 'product',
title: '상품',
width: 150,
cellClass: (ctx) => (styled && ctx.value === '노트북' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59000 + ((i * 47000) % 900000),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === '서울' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: '전체 합계' },
pagination: { mode: 'client', pageSize: 10 },
};
// 클래스의 색은 테마 색으로 만들어서 밝은 화면과 어두운 화면 모두에서 읽혀요.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log({
ko: `${api.getPage()}페이지 금액 합계 ${pageSum.toLocaleString('ko-KR')}원 · 전체 ${Number(api.getSummary().amount).toLocaleString('ko-KR')}원`,
en: `Page ${api.getPage()} amount total ${pageSum.toLocaleString('en-US')} KRW · all pages ${Number(api.getSummary().amount).toLocaleString('en-US')} KRW`,
});
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, 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.style(api, $any($event.target).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<mx-grid style="height: 680px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['서울', '부산', '대구', '제주'];
const products = ['노트북', '모니터', '무선 키보드', '웹캠', '도킹 스테이션'];
let styled = true;
// 페이지를 나눠도 합계 줄, 행 스타일, 칸 스타일이 그대로 따라와요.
// - 합계 줄은 모든 페이지의 합계를 한 줄로 아래에 붙여요(필터를 걸면 걸러진 행만의 합계예요).
// - rowClass / cellClass는 보이는 줄마다 불려서 조건에 맞는 곳에 클래스를 붙여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: '지역', width: 110 },
{
id: 'product',
title: '상품',
width: 150,
cellClass: (ctx) => (styled && ctx.value === '노트북' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59000 + ((i * 47000) % 900000),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === '서울' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: '전체 합계' },
pagination: { mode: 'client', pageSize: 10 },
};
// 클래스의 색은 테마 색으로 만들어서 밝은 화면과 어두운 화면 모두에서 읽혀요.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log({
ko: `${api.getPage()}페이지 금액 합계 ${pageSum.toLocaleString('ko-KR')}원 · 전체 ${Number(api.getSummary().amount).toLocaleString('ko-KR')}원`,
en: `Page ${api.getPage()} amount total ${pageSum.toLocaleString('en-US')} KRW · all pages ${Number(api.getSummary().amount).toLocaleString('en-US')} KRW`,
});
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};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="Highlights" id="style">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 680px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('style').addEventListener('change', (event) => actions.style(api, event.target.value));const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = ['Laptop', 'Monitor', 'Wireless keyboard', 'Webcam', 'Docking station'];
let styled = true;
// Splitting into pages keeps the total row, row styles and cell styles working.
// - The total row attaches one line below with the totals of all pages (with a filter, the total of the filtered rows only).
// - rowClass / cellClass are called for every visible line and add a class where the condition matches.
export const options = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{
id: 'product',
title: 'Product',
width: 170,
cellClass: (ctx) => (styled && ctx.value === 'Laptop' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 5) % 9),
amount: 59 + ((i * 47) % 900),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === 'New York' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: 'Grand total' },
pagination: { mode: 'client', pageSize: 10 },
};
// The class colors come from theme colors, so they stay readable on both light and dark screens.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style;
export function setup(api, log) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = () => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log(`Page ${api.getPage()} amount total $${pageSum.toLocaleString('en-US')} · all pages $${Number(api.getSummary().amount).toLocaleString('en-US')}`);
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api, value) => {
styled = value !== 'off';
api.refresh();
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Totals and highlights follow you across pages</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Highlights" id="style">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 680px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = ['Laptop', 'Monitor', 'Wireless keyboard', 'Webcam', 'Docking station'];
let styled = true;
// Splitting into pages keeps the total row, row styles and cell styles working.
// - The total row attaches one line below with the totals of all pages (with a filter, the total of the filtered rows only).
// - rowClass / cellClass are called for every visible line and add a class where the condition matches.
const options = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{
id: 'product',
title: 'Product',
width: 170,
cellClass: (ctx) => (styled && ctx.value === 'Laptop' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 5) % 9),
amount: 59 + ((i * 47) % 900),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === 'New York' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: 'Grand total' },
pagination: { mode: 'client', pageSize: 10 },
};
// The class colors come from theme colors, so they stay readable on both light and dark screens.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style;
function setup(api, log) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = () => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log(`Page ${api.getPage()} amount total $${pageSum.toLocaleString('en-US')} · all pages $${Number(api.getSummary().amount).toLocaleString('en-US')}`);
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
const actions = {
style: (api, value) => {
styled = value !== 'off';
api.refresh();
},
};
options.ariaLabel = "Totals and highlights follow you across pages";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('style').addEventListener('change', (event) => actions.style(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 { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Highlights"
disabled={!api}
onChange={(event) => api && actions.style(api, event.target.value)}
>
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
<Grid style={{ height: 680 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = ['Laptop', 'Monitor', 'Wireless keyboard', 'Webcam', 'Docking station'];
let styled = true;
// Splitting into pages keeps the total row, row styles and cell styles working.
// - The total row attaches one line below with the totals of all pages (with a filter, the total of the filtered rows only).
// - rowClass / cellClass are called for every visible line and add a class where the condition matches.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{
id: 'product',
title: 'Product',
width: 170,
cellClass: (ctx) => (styled && ctx.value === 'Laptop' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59 + ((i * 47) % 900),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === 'New York' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: 'Grand total' },
pagination: { mode: 'client', pageSize: 10 },
};
// The class colors come from theme colors, so they stay readable on both light and dark screens.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log(
`Page ${api.getPage()} amount total $${pageSum.toLocaleString('en-US')} · all pages $${Number(api.getSummary().amount).toLocaleString('en-US')}`,
);
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Highlights"
:disabled="!api"
@change="api && actions.style(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<Grid style="height: 680px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = ['Laptop', 'Monitor', 'Wireless keyboard', 'Webcam', 'Docking station'];
let styled = true;
// Splitting into pages keeps the total row, row styles and cell styles working.
// - The total row attaches one line below with the totals of all pages (with a filter, the total of the filtered rows only).
// - rowClass / cellClass are called for every visible line and add a class where the condition matches.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{
id: 'product',
title: 'Product',
width: 170,
cellClass: (ctx) => (styled && ctx.value === 'Laptop' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59 + ((i * 47) % 900),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === 'New York' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: 'Grand total' },
pagination: { mode: 'client', pageSize: 10 },
};
// The class colors come from theme colors, so they stay readable on both light and dark screens.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log(
`Page ${api.getPage()} amount total $${pageSum.toLocaleString('en-US')} · all pages $${Number(api.getSummary().amount).toLocaleString('en-US')}`,
);
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Highlights"
[disabled]="!api"
(change)="api && actions.style(api, $any($event.target).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<mx-grid style="height: 680px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
region: string;
product: string;
quantity: number;
amount: number;
}
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = ['Laptop', 'Monitor', 'Wireless keyboard', 'Webcam', 'Docking station'];
let styled = true;
// Splitting into pages keeps the total row, row styles and cell styles working.
// - The total row attaches one line below with the totals of all pages (with a filter, the total of the filtered rows only).
// - rowClass / cellClass are called for every visible line and add a class where the condition matches.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{
id: 'product',
title: 'Product',
width: 170,
cellClass: (ctx) => (styled && ctx.value === 'Laptop' ? 'pf-product' : undefined),
},
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
formatValue: (value) => Number(value).toLocaleString('en-US'),
cellClass: () => (styled ? 'pf-amount' : undefined),
},
],
rows: Array.from({ length: 60 }, (_, i) => ({
id: i + 1,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 5) % 9),
amount: 59 + ((i * 47) % 900),
})),
rowKey: 'id',
rowClass: (row) => (styled && row.region === 'New York' ? 'pf-seoul' : undefined),
summary: { position: 'bottom', label: 'Grand total' },
pagination: { mode: 'client', pageSize: 10 },
};
// The class colors come from theme colors, so they stay readable on both light and dark screens.
const CSS = `
.pf-seoul { box-shadow: inset 3px 0 0 var(--mxg-accent); }
.pf-product { color: var(--mxg-tone-danger-fg); font-weight: 700; }
.pf-amount { color: var(--mxg-tone-info-fg); }
`;
let style: HTMLStyleElement | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
styled = true;
style = document.createElement('style');
style.textContent = CSS;
document.head.append(style);
const report = (): void => {
const pageSum = api.getVisibleRows().reduce((sum, row) => sum + row.amount, 0);
log(
`Page ${api.getPage()} amount total $${pageSum.toLocaleString('en-US')} · all pages $${Number(api.getSummary().amount).toLocaleString('en-US')}`,
);
};
report();
const off = api.on('pageChanged', report);
return () => {
off();
style?.remove();
style = undefined;
};
}
export const actions = {
style: (api: GridApi<Row>, value?: string) => {
styled = value !== 'off';
api.refresh();
},
};