10만 줄을 본부·팀으로 묶기Group 100,000 rows by division and team
직원 10만 명을 본부·팀으로 묶고 평균 월급을 보여 줘요. 묶는 기준을 바꾸거나 월급 필터를 걸어도 금방 다시 계산해요.Group 100,000 employees by division and team with average salary, then change the grouping or filter by salary.
코드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="by">
<option value="both" selected>본부 → 팀</option>
<option value="team">팀만</option>
</select>
<select aria-label="월급 필터" id="high">
<option value="all" selected>전체</option>
<option value="high">7,000만원 이상</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 330px"></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('by').addEventListener('change', (event) => actions.by(api, event.target.value));
document.getElementById('high').addEventListener('change', (event) => actions.high(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));const surnames = ['김', '이', '박', '최', '정', '강', '조', '윤', '장', '임'];
const given = ['서연', '준호', '민지', '도윤', '하은', '지후', '수빈', '예준', '지민', '시우'];
const departments = Array.from({ length: 40 }, (_, i) => `${i + 1}본부`);
const teams = ['핵심팀', '플랫폼팀', '성장팀', '지원팀', '데이터팀'];
// 부서 40곳 × 팀 5곳, 모두 10만 줄이에요. 그룹은 줄의 번호만 들고 있어서 열 때도 가벼워요.
const rows = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length],
team: teams[Math.floor(i / 40) % teams.length],
employee: `${surnames[i % 10]}${given[Math.floor(i / 10) % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 3000 + ((i * 7919) % 5000),
}));
export const options = {
columns: [
{ id: 'department', title: '본부', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'employee', title: '직원(사번)', width: 170 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 본부·팀으로 묶었어요. 그룹 줄의 월급은 평균이에요.`,
en: `${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
});
}
export const actions = {
by: (api, value) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say({
ko: `묶는 기준: ${value === 'team' ? '팀만' : '본부 → 팀'}`,
en: `Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`,
});
},
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
collapseAll: (api) => api.collapseAll(),
high: (api, value) => {
api.setFilterModel(value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 7000 }] }
: null);
say({
ko: value === 'high'
? `월급 7,000만원 이상만 남겼어요. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('ko-KR')}줄이 조건에 맞아요)`
: '필터를 풀었어요.',
en: value === 'high'
? `Kept only monthly pay of 70 million KRW or more. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
});
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>10만 줄을 본부·팀으로 묶기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="묶는 기준" id="by">
<option value="both" selected>본부 → 팀</option>
<option value="team">팀만</option>
</select>
<select aria-label="월급 필터" id="high">
<option value="all" selected>전체</option>
<option value="high">7,000만원 이상</option>
</select>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const surnames = ['김', '이', '박', '최', '정', '강', '조', '윤', '장', '임'];
const given = ['서연', '준호', '민지', '도윤', '하은', '지후', '수빈', '예준', '지민', '시우'];
const departments = Array.from({ length: 40 }, (_, i) => `${i + 1}본부`);
const teams = ['핵심팀', '플랫폼팀', '성장팀', '지원팀', '데이터팀'];
// 부서 40곳 × 팀 5곳, 모두 10만 줄이에요. 그룹은 줄의 번호만 들고 있어서 열 때도 가벼워요.
const rows = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length],
team: teams[Math.floor(i / 40) % teams.length],
employee: `${surnames[i % 10]}${given[Math.floor(i / 10) % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 3000 + ((i * 7919) % 5000),
}));
const options = {
columns: [
{ id: 'department', title: '본부', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'employee', title: '직원(사번)', width: 170 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say = () => { };
function setup(_api, log) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 본부·팀으로 묶었어요. 그룹 줄의 월급은 평균이에요.`,
en: `${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
});
}
const actions = {
by: (api, value) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say({
ko: `묶는 기준: ${value === 'team' ? '팀만' : '본부 → 팀'}`,
en: `Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`,
});
},
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
collapseAll: (api) => api.collapseAll(),
high: (api, value) => {
api.setFilterModel(value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 7000 }] }
: null);
say({
ko: value === 'high'
? `월급 7,000만원 이상만 남겼어요. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('ko-KR')}줄이 조건에 맞아요)`
: '필터를 풀었어요.',
en: value === 'high'
? `Kept only monthly pay of 70 million KRW or more. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
});
},
};
options.ariaLabel = "10만 줄을 본부·팀으로 묶기";
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('by').addEventListener('change', (event) => actions.by(api, event.target.value));
document.getElementById('high').addEventListener('change', (event) => actions.high(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 { 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.by(api, event.target.value)}
>
<option value="both">본부 → 팀</option>
<option value="team">팀만</option>
</select>
<select defaultValue="both"
aria-label="월급 필터"
disabled={!api}
onChange={(event) => api && actions.high(api, event.target.value)}
>
<option value="all">전체</option>
<option value="high">7,000만원 이상</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: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = ['김', '이', '박', '최', '정', '강', '조', '윤', '장', '임'];
const given = ['서연', '준호', '민지', '도윤', '하은', '지후', '수빈', '예준', '지민', '시우'];
const departments = Array.from({ length: 40 }, (_, i) => `${i + 1}본부`);
const teams = ['핵심팀', '플랫폼팀', '성장팀', '지원팀', '데이터팀'];
// 부서 40곳 × 팀 5곳, 모두 10만 줄이에요. 그룹은 줄의 번호만 들고 있어서 열 때도 가벼워요.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${surnames[i % 10]}${given[Math.floor(i / 10) % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 3000 + ((i * 7919) % 5000),
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: '본부', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'employee', title: '직원(사번)', width: 170 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 본부·팀으로 묶었어요. 그룹 줄의 월급은 평균이에요.`,
en: `${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
});
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say({
ko: `묶는 기준: ${value === 'team' ? '팀만' : '본부 → 팀'}`,
en: `Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`,
});
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 7000 }] }
: null,
);
say({
ko:
value === 'high'
? `월급 7,000만원 이상만 남겼어요. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('ko-KR')}줄이 조건에 맞아요)`
: '필터를 풀었어요.',
en:
value === 'high'
? `Kept only monthly pay of 70 million KRW or more. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
});
},
};버튼을 누르면 이 예제의 코드가 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.by(api, ($event.target as HTMLSelectElement).value)"
>
<option value="both" selected>본부 → 팀</option>
<option value="team">팀만</option>
</select>
<select
aria-label="월급 필터"
:disabled="!api"
@change="api && actions.high(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>전체</option>
<option value="high">7,000만원 이상</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: 330px" :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;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = ['김', '이', '박', '최', '정', '강', '조', '윤', '장', '임'];
const given = ['서연', '준호', '민지', '도윤', '하은', '지후', '수빈', '예준', '지민', '시우'];
const departments = Array.from({ length: 40 }, (_, i) => `${i + 1}본부`);
const teams = ['핵심팀', '플랫폼팀', '성장팀', '지원팀', '데이터팀'];
// 부서 40곳 × 팀 5곳, 모두 10만 줄이에요. 그룹은 줄의 번호만 들고 있어서 열 때도 가벼워요.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${surnames[i % 10]}${given[Math.floor(i / 10) % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 3000 + ((i * 7919) % 5000),
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: '본부', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'employee', title: '직원(사번)', width: 170 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 본부·팀으로 묶었어요. 그룹 줄의 월급은 평균이에요.`,
en: `${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
});
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say({
ko: `묶는 기준: ${value === 'team' ? '팀만' : '본부 → 팀'}`,
en: `Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`,
});
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 7000 }] }
: null,
);
say({
ko:
value === 'high'
? `월급 7,000만원 이상만 남겼어요. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('ko-KR')}줄이 조건에 맞아요)`
: '필터를 풀었어요.',
en:
value === 'high'
? `Kept only monthly pay of 70 million KRW or more. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
});
},
};버튼을 누르면 이 예제의 코드가 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.by(api, $any($event.target).value)"
>
<option value="both" selected>본부 → 팀</option>
<option value="team">팀만</option>
</select>
<select
aria-label="월급 필터"
[disabled]="!api"
(change)="api && actions.high(api, $any($event.target).value)"
>
<option value="all" selected>전체</option>
<option value="high">7,000만원 이상</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: 330px" [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;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = ['김', '이', '박', '최', '정', '강', '조', '윤', '장', '임'];
const given = ['서연', '준호', '민지', '도윤', '하은', '지후', '수빈', '예준', '지민', '시우'];
const departments = Array.from({ length: 40 }, (_, i) => `${i + 1}본부`);
const teams = ['핵심팀', '플랫폼팀', '성장팀', '지원팀', '데이터팀'];
// 부서 40곳 × 팀 5곳, 모두 10만 줄이에요. 그룹은 줄의 번호만 들고 있어서 열 때도 가벼워요.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${surnames[i % 10]}${given[Math.floor(i / 10) % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 3000 + ((i * 7919) % 5000),
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: '본부', width: 110 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'employee', title: '직원(사번)', width: 170 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 본부·팀으로 묶었어요. 그룹 줄의 월급은 평균이에요.`,
en: `${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
});
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say({
ko: `묶는 기준: ${value === 'team' ? '팀만' : '본부 → 팀'}`,
en: `Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`,
});
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 7000 }] }
: null,
);
say({
ko:
value === 'high'
? `월급 7,000만원 이상만 남겼어요. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('ko-KR')}줄이 조건에 맞아요)`
: '필터를 풀었어요.',
en:
value === 'high'
? `Kept only monthly pay of 70 million KRW or more. (${rows.filter((r) => r.salary >= 7000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
});
},
};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="Group by" id="by">
<option value="both" selected>Division → team</option>
<option value="team">Team only</option>
</select>
<select aria-label="Salary filter" id="high">
<option value="all" selected>All</option>
<option value="high">70,000 or more</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 330px"></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('by').addEventListener('change', (event) => actions.by(api, event.target.value));
document.getElementById('high').addEventListener('change', (event) => actions.high(api, event.target.value));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));const surnames = [
'Carter',
'Stone',
'Kim',
'Park',
'Brown',
'Johnson',
'Lee',
'Davis',
'Miller',
'Clark',
];
const given = ['Liam', 'Emma', 'Noah', 'Olivia', 'Mia', 'Ava', 'Ethan', 'Zoe', 'Jack', 'Lily'];
const departments = Array.from({ length: 40 }, (_, i) => `Division ${i + 1}`);
const teams = ['Core', 'Platform', 'Growth', 'Support', 'Data'];
// 40 departments x 5 teams, 100,000 rows in all. A group only holds row numbers, so opening one stays cheap.
const rows = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length],
team: teams[Math.floor(i / 40) % teams.length],
employee: `${given[Math.floor(i / 10) % 10]} ${surnames[i % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 30000 + ((i * 7919) % 5000) * 10,
}));
export const options = {
columns: [
{ id: 'department', title: 'Division', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'employee', title: 'Employee (ID)', width: 200 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 180,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say = () => { };
export function setup(_api, log) {
say = log;
log(`${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`);
}
export const actions = {
by: (api, value) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say(`Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`);
},
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say(`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`);
},
collapseAll: (api) => api.collapseAll(),
high: (api, value) => {
api.setFilterModel(value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 70000 }] }
: null);
say(value === 'high'
? `Kept only monthly pay of $70,000 or more. (${rows.filter((r) => r.salary >= 70000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Group 100,000 rows by division and team</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Group by" id="by">
<option value="both" selected>Division → team</option>
<option value="team">Team only</option>
</select>
<select aria-label="Salary filter" id="high">
<option value="all" selected>All</option>
<option value="high">70,000 or more</option>
</select>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const surnames = [
'Carter',
'Stone',
'Kim',
'Park',
'Brown',
'Johnson',
'Lee',
'Davis',
'Miller',
'Clark',
];
const given = ['Liam', 'Emma', 'Noah', 'Olivia', 'Mia', 'Ava', 'Ethan', 'Zoe', 'Jack', 'Lily'];
const departments = Array.from({ length: 40 }, (_, i) => `Division ${i + 1}`);
const teams = ['Core', 'Platform', 'Growth', 'Support', 'Data'];
// 40 departments x 5 teams, 100,000 rows in all. A group only holds row numbers, so opening one stays cheap.
const rows = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length],
team: teams[Math.floor(i / 40) % teams.length],
employee: `${given[Math.floor(i / 10) % 10]} ${surnames[i % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 30000 + ((i * 7919) % 5000) * 10,
}));
const options = {
columns: [
{ id: 'department', title: 'Division', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'employee', title: 'Employee (ID)', width: 200 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 180,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say = () => { };
function setup(_api, log) {
say = log;
log(`${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`);
}
const actions = {
by: (api, value) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say(`Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`);
},
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say(`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`);
},
collapseAll: (api) => api.collapseAll(),
high: (api, value) => {
api.setFilterModel(value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 70000 }] }
: null);
say(value === 'high'
? `Kept only monthly pay of $70,000 or more. (${rows.filter((r) => r.salary >= 70000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.');
},
};
options.ariaLabel = "Group 100,000 rows by division and team";
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('by').addEventListener('change', (event) => actions.by(api, event.target.value));
document.getElementById('high').addEventListener('change', (event) => actions.high(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 { 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="Group by"
disabled={!api}
onChange={(event) => api && actions.by(api, event.target.value)}
>
<option value="both">Division → team</option>
<option value="team">Team only</option>
</select>
<select defaultValue="both"
aria-label="Salary filter"
disabled={!api}
onChange={(event) => api && actions.high(api, event.target.value)}
>
<option value="all">All</option>
<option value="high">70,000 or more</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: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = [
'Carter',
'Stone',
'Kim',
'Park',
'Brown',
'Johnson',
'Lee',
'Davis',
'Miller',
'Clark',
];
const given = ['Liam', 'Emma', 'Noah', 'Olivia', 'Mia', 'Ava', 'Ethan', 'Zoe', 'Jack', 'Lily'];
const departments = Array.from({ length: 40 }, (_, i) => `Division ${i + 1}`);
const teams = ['Core', 'Platform', 'Growth', 'Support', 'Data'];
// 40 departments x 5 teams, 100,000 rows in all. A group only holds row numbers, so opening one stays cheap.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${given[Math.floor(i / 10) % 10]} ${surnames[i % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 30000 + ((i * 7919) % 5000) * 10,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: 'Division', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'employee', title: 'Employee (ID)', width: 200 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 180,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
`${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
);
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say(`Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`);
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 70000 }] }
: null,
);
say(
value === 'high'
? `Kept only monthly pay of $70,000 or more. (${rows.filter((r) => r.salary >= 70000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
);
},
};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="Group by"
:disabled="!api"
@change="api && actions.by(api, ($event.target as HTMLSelectElement).value)"
>
<option value="both" selected>Division → team</option>
<option value="team">Team only</option>
</select>
<select
aria-label="Salary filter"
:disabled="!api"
@change="api && actions.high(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>All</option>
<option value="high">70,000 or more</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: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = [
'Carter',
'Stone',
'Kim',
'Park',
'Brown',
'Johnson',
'Lee',
'Davis',
'Miller',
'Clark',
];
const given = ['Liam', 'Emma', 'Noah', 'Olivia', 'Mia', 'Ava', 'Ethan', 'Zoe', 'Jack', 'Lily'];
const departments = Array.from({ length: 40 }, (_, i) => `Division ${i + 1}`);
const teams = ['Core', 'Platform', 'Growth', 'Support', 'Data'];
// 40 departments x 5 teams, 100,000 rows in all. A group only holds row numbers, so opening one stays cheap.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${given[Math.floor(i / 10) % 10]} ${surnames[i % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 30000 + ((i * 7919) % 5000) * 10,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: 'Division', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'employee', title: 'Employee (ID)', width: 200 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 180,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
`${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
);
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say(`Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`);
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 70000 }] }
: null,
);
say(
value === 'high'
? `Kept only monthly pay of $70,000 or more. (${rows.filter((r) => r.salary >= 70000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
);
},
};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="Group by"
[disabled]="!api"
(change)="api && actions.by(api, $any($event.target).value)"
>
<option value="both" selected>Division → team</option>
<option value="team">Team only</option>
</select>
<select
aria-label="Salary filter"
[disabled]="!api"
(change)="api && actions.high(api, $any($event.target).value)"
>
<option value="all" selected>All</option>
<option value="high">70,000 or more</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: 330px" [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;
department: string;
team: string;
employee: string;
salary: number;
}
const surnames = [
'Carter',
'Stone',
'Kim',
'Park',
'Brown',
'Johnson',
'Lee',
'Davis',
'Miller',
'Clark',
];
const given = ['Liam', 'Emma', 'Noah', 'Olivia', 'Mia', 'Ava', 'Ethan', 'Zoe', 'Jack', 'Lily'];
const departments = Array.from({ length: 40 }, (_, i) => `Division ${i + 1}`);
const teams = ['Core', 'Platform', 'Growth', 'Support', 'Data'];
// 40 departments x 5 teams, 100,000 rows in all. A group only holds row numbers, so opening one stays cheap.
const rows: Row[] = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
department: departments[i % departments.length] as string,
team: teams[Math.floor(i / 40) % teams.length] as string,
employee: `${given[Math.floor(i / 10) % 10]} ${surnames[i % 10]} (${String(i + 1).padStart(6, '0')})`,
salary: 30000 + ((i * 7919) % 5000) * 10,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'department', title: 'Division', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'employee', title: 'Employee (ID)', width: 200 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 180,
align: 'end',
aggregate: { fn: 'avg', precision: 0 },
},
],
rows,
rowKey: 'id',
grouping: { by: ['department', 'team'], expandDepth: 0 },
summary: true,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
`${rows.length.toLocaleString('en-US')} rows grouped by division and team. Group rows show the average monthly pay.`,
);
}
export const actions = {
by: (api: GridApi<Row>, value?: string) => {
api.setGroupBy(value === 'team' ? ['team'] : ['department', 'team']);
say(`Grouped by: ${value === 'team' ? 'team only' : 'division → team'}`);
},
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
collapseAll: (api: GridApi<Row>) => api.collapseAll(),
high: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(
value === 'high'
? { match: 'all', items: [{ columnId: 'salary', operator: 'gte', value: 70000 }] }
: null,
);
say(
value === 'high'
? `Kept only monthly pay of $70,000 or more. (${rows.filter((r) => r.salary >= 70000).length.toLocaleString('en-US')} rows match)`
: 'Filter cleared.',
);
},
};