그룹 보기 방식: 컬럼 숨기기·줄 숨기기·병합Group display: hide columns, hide rows, merged
grouping.hideColumns는 묶인 컬럼을 묶여 있는 동안 숨기고, hideRows는 그룹 줄 없이 행을 그룹 순서로 보이고, merged는 그룹 컬럼 칸을 값별로 세로 병합해요.grouping.hideColumns hides grouped columns while grouped, hideRows shows rows in group order without group lines, and merged merges the group column cells by value.
코드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">
<button type="button" id="plain">기본</button>
<button type="button" id="hideColumns">컬럼 숨기기</button>
<button type="button" id="hideRows">줄 숨기기</button>
<button type="button" id="merged">병합</button>
<button type="button" id="ungroup">묶음 풀기</button>
</div>
<div id="grid" style="height: 420px"></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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(api));const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `사원 ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
}))));
export const options = {
columns: [
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 100 },
{ id: 'name', title: '이름', width: 120 },
{ id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
function mode(api, grouping, ko, en) {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
say({ ko, en });
}
export const actions = {
plain: (api) => mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
hideColumns: (api) => mode(api, { hideColumns: true }, '묶인 컬럼(팀·도시)이 숨겨져요', 'Grouped columns (team, city) are hidden'),
hideRows: (api) => mode(api, { hideRows: true }, '그룹 줄 없이 행이 그룹 순서로 이어져요', 'No group lines; rows follow group order'),
merged: (api) => mode(api, { merged: true }, '그룹 컬럼 칸이 값별로 세로 병합돼요', 'Group column cells are merged by value'),
ungroup: (api) => {
api.setGroupBy([]);
say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
},
};<!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">
<button type="button" id="plain">기본</button>
<button type="button" id="hideColumns">컬럼 숨기기</button>
<button type="button" id="hideRows">줄 숨기기</button>
<button type="button" id="merged">병합</button>
<button type="button" id="ungroup">묶음 풀기</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `사원 ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
}))));
const options = {
columns: [
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 100 },
{ id: 'name', title: '이름', width: 120 },
{ id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
function mode(api, grouping, ko, en) {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
say({ ko, en });
}
const actions = {
plain: (api) => mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
hideColumns: (api) => mode(api, { hideColumns: true }, '묶인 컬럼(팀·도시)이 숨겨져요', 'Grouped columns (team, city) are hidden'),
hideRows: (api) => mode(api, { hideRows: true }, '그룹 줄 없이 행이 그룹 순서로 이어져요', 'No group lines; rows follow group order'),
merged: (api) => mode(api, { merged: true }, '그룹 컬럼 칸이 값별로 세로 병합돼요', 'Group column cells are merged by value'),
ungroup: (api) => {
api.setGroupBy([]);
say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
},
};
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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.plain(api)}
>기본</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideColumns(api)}
>컬럼 숨기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideRows(api)}
>줄 숨기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.merged(api)}
>병합</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ungroup(api)}
>묶음 풀기</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `사원 ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 100 },
{ id: 'name', title: '이름', width: 120 },
{ id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, ko: string, en: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say({ ko, en });
}
export const actions = {
plain: (api: GridApi<Row>) =>
mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(
api,
{ hideColumns: true },
'묶인 컬럼(팀·도시)이 숨겨져요',
'Grouped columns (team, city) are hidden',
),
hideRows: (api: GridApi<Row>) =>
mode(
api,
{ hideRows: true },
'그룹 줄 없이 행이 그룹 순서로 이어져요',
'No group lines; rows follow group order',
),
merged: (api: GridApi<Row>) =>
mode(
api,
{ merged: true },
'그룹 컬럼 칸이 값별로 세로 병합돼요',
'Group column cells are merged by value',
),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
},
};버튼을 누르면 이 예제의 코드가 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">
<button type="button" :disabled="!api" @click="api && actions.plain(api)">기본</button>
<button
type="button"
:disabled="!api"
@click="api && actions.hideColumns(api)"
>컬럼 숨기기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.hideRows(api)"
>줄 숨기기</button>
<button type="button" :disabled="!api" @click="api && actions.merged(api)">병합</button>
<button type="button" :disabled="!api" @click="api && actions.ungroup(api)">묶음 풀기</button>
</div>
<Grid style="height: 420px" :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;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `사원 ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 100 },
{ id: 'name', title: '이름', width: 120 },
{ id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, ko: string, en: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say({ ko, en });
}
export const actions = {
plain: (api: GridApi<Row>) =>
mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(
api,
{ hideColumns: true },
'묶인 컬럼(팀·도시)이 숨겨져요',
'Grouped columns (team, city) are hidden',
),
hideRows: (api: GridApi<Row>) =>
mode(
api,
{ hideRows: true },
'그룹 줄 없이 행이 그룹 순서로 이어져요',
'No group lines; rows follow group order',
),
merged: (api: GridApi<Row>) =>
mode(
api,
{ merged: true },
'그룹 컬럼 칸이 값별로 세로 병합돼요',
'Group column cells are merged by value',
),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
},
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.plain(api)"
>기본</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideColumns(api)"
>컬럼 숨기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideRows(api)"
>줄 숨기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.merged(api)"
>병합</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ungroup(api)"
>묶음 풀기</button>
</div>
<mx-grid style="height: 420px" [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;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `사원 ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 100 },
{ id: 'name', title: '이름', width: 120 },
{ id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, ko: string, en: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say({ ko, en });
}
export const actions = {
plain: (api: GridApi<Row>) =>
mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(
api,
{ hideColumns: true },
'묶인 컬럼(팀·도시)이 숨겨져요',
'Grouped columns (team, city) are hidden',
),
hideRows: (api: GridApi<Row>) =>
mode(
api,
{ hideRows: true },
'그룹 줄 없이 행이 그룹 순서로 이어져요',
'No group lines; rows follow group order',
),
merged: (api: GridApi<Row>) =>
mode(
api,
{ merged: true },
'그룹 컬럼 칸이 값별로 세로 병합돼요',
'Group column cells are merged by value',
),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="plain">Default</button>
<button type="button" id="hideColumns">Hide columns</button>
<button type="button" id="hideRows">Hide rows</button>
<button type="button" id="merged">Merged</button>
<button type="button" id="ungroup">Ungroup</button>
</div>
<div id="grid" style="height: 420px"></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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(api));const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `Employee ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
}))));
export const options = {
columns: [
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'name', title: 'Name', width: 120 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
function mode(api, grouping, message) {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
say(message);
}
export const actions = {
plain: (api) => mode(api, {}, 'Default: group lines are shown'),
hideColumns: (api) => mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
hideRows: (api) => mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
merged: (api) => mode(api, { merged: true }, 'Group column cells are merged by value'),
ungroup: (api) => {
api.setGroupBy([]);
say('Ungrouping brings hidden columns back');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Group display: hide columns, hide rows, merged</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="plain">Default</button>
<button type="button" id="hideColumns">Hide columns</button>
<button type="button" id="hideRows">Hide rows</button>
<button type="button" id="merged">Merged</button>
<button type="button" id="ungroup">Ungroup</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `Employee ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
}))));
const options = {
columns: [
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'name', title: 'Name', width: 120 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
function mode(api, grouping, message) {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
say(message);
}
const actions = {
plain: (api) => mode(api, {}, 'Default: group lines are shown'),
hideColumns: (api) => mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
hideRows: (api) => mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
merged: (api) => mode(api, { merged: true }, 'Group column cells are merged by value'),
ungroup: (api) => {
api.setGroupBy([]);
say('Ungrouping brings hidden columns back');
},
};
options.ariaLabel = "Group display: hide columns, hide rows, merged";
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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.plain(api)}
>Default</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideColumns(api)}
>Hide columns</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideRows(api)}
>Hide rows</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.merged(api)}
>Merged</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ungroup(api)}
>Ungroup</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `Employee ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'name', title: 'Name', width: 120 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, message: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say(message);
}
export const actions = {
plain: (api: GridApi<Row>) => mode(api, {}, 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
hideRows: (api: GridApi<Row>) =>
mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
merged: (api: GridApi<Row>) =>
mode(api, { merged: true }, 'Group column cells are merged by value'),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say('Ungrouping brings hidden columns back');
},
};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">
<button type="button" :disabled="!api" @click="api && actions.plain(api)">Default</button>
<button
type="button"
:disabled="!api"
@click="api && actions.hideColumns(api)"
>Hide columns</button>
<button
type="button"
:disabled="!api"
@click="api && actions.hideRows(api)"
>Hide rows</button>
<button type="button" :disabled="!api" @click="api && actions.merged(api)">Merged</button>
<button type="button" :disabled="!api" @click="api && actions.ungroup(api)">Ungroup</button>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `Employee ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'name', title: 'Name', width: 120 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, message: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say(message);
}
export const actions = {
plain: (api: GridApi<Row>) => mode(api, {}, 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
hideRows: (api: GridApi<Row>) =>
mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
merged: (api: GridApi<Row>) =>
mode(api, { merged: true }, 'Group column cells are merged by value'),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say('Ungrouping brings hidden columns back');
},
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.plain(api)"
>Default</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideColumns(api)"
>Hide columns</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideRows(api)"
>Hide rows</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.merged(api)"
>Merged</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ungroup(api)"
>Ungroup</button>
</div>
<mx-grid style="height: 420px" [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;
team: string;
city: string;
name: string;
amount: number;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows: Row[] = TEAMS.flatMap((team, t) =>
CITIES.flatMap((city, c) =>
[0, 1].map((k) => ({
id: t * 4 + c * 2 + k + 1,
team,
city,
name: `Employee ${t * 4 + c * 2 + k + 1}`,
amount: 100 + t * 20 + c * 10 + k * 5,
})),
),
);
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 100 },
{ id: 'name', title: 'Name', width: 120 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
function mode(api: GridApi<Row>, grouping: object, message: string): void {
api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } } as never);
say(message);
}
export const actions = {
plain: (api: GridApi<Row>) => mode(api, {}, 'Default: group lines are shown'),
hideColumns: (api: GridApi<Row>) =>
mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
hideRows: (api: GridApi<Row>) =>
mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
merged: (api: GridApi<Row>) =>
mode(api, { merged: true }, 'Group column cells are merged by value'),
ungroup: (api: GridApi<Row>) => {
api.setGroupBy([]);
say('Ungrouping brings hidden columns back');
},
};