도구 모음과 헤더 그룹·고정 컬럼 함께 쓰기Use the toolbar with header groups and a pinned column
컬럼 도구 모음은 접히는 헤더 그룹, 고정 컬럼과 함께 써요. 앞에 고정한 번호는 칩으로 옮겨도 고정 영역을 벗어나지 않고, 접은 그룹 안의 컬럼은 그룹을 펴기 전까지 접힌 채로 있어요.The column toolbar works with collapsible header groups and a pinned column. The pinned No. column never leaves its zone when you move chips, and a column inside a collapsed group stays folded until you expand the group.
코드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="collapseAll">그룹 모두 접기</button>
<button type="button" id="expandAll">그룹 모두 펴기</button>
<button type="button" id="hideQ2">2분기 숨기기</button>
<button type="button" id="state">저장본 순서</button>
</div>
<div id="grid" style="height: 360px"></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('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('hideQ2').addEventListener('click', () => actions.hideQ2(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));const names = ['서울', '부산', '대구', '인천', '광주', '대전', '울산', '세종'];
// 컬럼 도구 모음과 접히는 헤더 그룹, 고정 컬럼을 함께 써요. 번호는 앞에 고정이라 칩으로 옮겨도 고정 영역을 벗어나지 않고,
// 접힌 그룹의 컬럼은 칩을 눌러도 접힘이 먼저예요(그룹을 펴면 칩 상태대로 보여요).
export const options = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: '지점', width: 110 },
{ id: 'q1', title: '1분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: '2분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: '3분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: '4분기', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: '상반기', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: '하반기', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
log({
ko: '칩으로 분기를 숨기거나 옮기고, 그룹 제목의 ▾로 접어 보세요.',
en: 'Hide or move quarters with the chips, and fold groups with the arrow in the group title.',
});
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) => log({
ko: `${groupId} 그룹을 ${collapsed ? '접었어요' : '펼쳤어요'}`,
en: `Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`,
}));
return () => off();
}
export const actions = {
collapseAll: (api) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api) => api.setColumnVisible('q2', false),
state: (api) => say({
ko: `저장본 순서: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? '(숨김)' : ''}`)
.join(' · ')}`,
en: `Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
}),
};<!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="collapseAll">그룹 모두 접기</button>
<button type="button" id="expandAll">그룹 모두 펴기</button>
<button type="button" id="hideQ2">2분기 숨기기</button>
<button type="button" id="state">저장본 순서</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['서울', '부산', '대구', '인천', '광주', '대전', '울산', '세종'];
// 컬럼 도구 모음과 접히는 헤더 그룹, 고정 컬럼을 함께 써요. 번호는 앞에 고정이라 칩으로 옮겨도 고정 영역을 벗어나지 않고,
// 접힌 그룹의 컬럼은 칩을 눌러도 접힘이 먼저예요(그룹을 펴면 칩 상태대로 보여요).
const options = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: '지점', width: 110 },
{ id: 'q1', title: '1분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: '2분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: '3분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: '4분기', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: '상반기', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: '하반기', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say = () => { };
function setup(api, log) {
say = log;
log({
ko: '칩으로 분기를 숨기거나 옮기고, 그룹 제목의 ▾로 접어 보세요.',
en: 'Hide or move quarters with the chips, and fold groups with the arrow in the group title.',
});
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) => log({
ko: `${groupId} 그룹을 ${collapsed ? '접었어요' : '펼쳤어요'}`,
en: `Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`,
}));
return () => off();
}
const actions = {
collapseAll: (api) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api) => api.setColumnVisible('q2', false),
state: (api) => say({
ko: `저장본 순서: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? '(숨김)' : ''}`)
.join(' · ')}`,
en: `Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
}),
};
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('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('hideQ2').addEventListener('click', () => actions.hideQ2(api));
document.getElementById('state').addEventListener('click', () => actions.state(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.collapseAll(api)}
>그룹 모두 접기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>그룹 모두 펴기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideQ2(api)}
>2분기 숨기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.state(api)}
>저장본 순서</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['서울', '부산', '대구', '인천', '광주', '대전', '울산', '세종'];
// 컬럼 도구 모음과 접히는 헤더 그룹, 고정 컬럼을 함께 써요. 번호는 앞에 고정이라 칩으로 옮겨도 고정 영역을 벗어나지 않고,
// 접힌 그룹의 컬럼은 칩을 눌러도 접힘이 먼저예요(그룹을 펴면 칩 상태대로 보여요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: '지점', width: 110 },
{ id: 'q1', title: '1분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: '2분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: '3분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: '4분기', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: '상반기', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: '하반기', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '칩으로 분기를 숨기거나 옮기고, 그룹 제목의 ▾로 접어 보세요.',
en: 'Hide or move quarters with the chips, and fold groups with the arrow in the group title.',
});
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log({
ko: `${groupId} 그룹을 ${collapsed ? '접었어요' : '펼쳤어요'}`,
en: `Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`,
}),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say({
ko: `저장본 순서: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? '(숨김)' : ''}`)
.join(' · ')}`,
en: `Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
}),
};버튼을 누르면 이 예제의 코드가 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.collapseAll(api)"
>그룹 모두 접기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>그룹 모두 펴기</button>
<button type="button" :disabled="!api" @click="api && actions.hideQ2(api)">2분기 숨기기</button>
<button type="button" :disabled="!api" @click="api && actions.state(api)">저장본 순서</button>
</div>
<Grid style="height: 360px" :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;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['서울', '부산', '대구', '인천', '광주', '대전', '울산', '세종'];
// 컬럼 도구 모음과 접히는 헤더 그룹, 고정 컬럼을 함께 써요. 번호는 앞에 고정이라 칩으로 옮겨도 고정 영역을 벗어나지 않고,
// 접힌 그룹의 컬럼은 칩을 눌러도 접힘이 먼저예요(그룹을 펴면 칩 상태대로 보여요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: '지점', width: 110 },
{ id: 'q1', title: '1분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: '2분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: '3분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: '4분기', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: '상반기', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: '하반기', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '칩으로 분기를 숨기거나 옮기고, 그룹 제목의 ▾로 접어 보세요.',
en: 'Hide or move quarters with the chips, and fold groups with the arrow in the group title.',
});
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log({
ko: `${groupId} 그룹을 ${collapsed ? '접었어요' : '펼쳤어요'}`,
en: `Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`,
}),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say({
ko: `저장본 순서: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? '(숨김)' : ''}`)
.join(' · ')}`,
en: `Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
}),
};버튼을 누르면 이 예제의 코드가 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.collapseAll(api)"
>그룹 모두 접기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>그룹 모두 펴기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideQ2(api)"
>2분기 숨기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.state(api)"
>저장본 순서</button>
</div>
<mx-grid style="height: 360px" [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;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['서울', '부산', '대구', '인천', '광주', '대전', '울산', '세종'];
// 컬럼 도구 모음과 접히는 헤더 그룹, 고정 컬럼을 함께 써요. 번호는 앞에 고정이라 칩으로 옮겨도 고정 영역을 벗어나지 않고,
// 접힌 그룹의 컬럼은 칩을 눌러도 접힘이 먼저예요(그룹을 펴면 칩 상태대로 보여요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: '지점', width: 110 },
{ id: 'q1', title: '1분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: '2분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: '3분기', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: '4분기', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: '상반기', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: '하반기', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '칩으로 분기를 숨기거나 옮기고, 그룹 제목의 ▾로 접어 보세요.',
en: 'Hide or move quarters with the chips, and fold groups with the arrow in the group title.',
});
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log({
ko: `${groupId} 그룹을 ${collapsed ? '접었어요' : '펼쳤어요'}`,
en: `Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`,
}),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say({
ko: `저장본 순서: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? '(숨김)' : ''}`)
.join(' · ')}`,
en: `Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
}),
};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="collapseAll">Collapse all groups</button>
<button type="button" id="expandAll">Expand all groups</button>
<button type="button" id="hideQ2">Hide Q2</button>
<button type="button" id="state">Show saved order</button>
</div>
<div id="grid" style="height: 360px"></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('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('hideQ2').addEventListener('click', () => actions.hideQ2(api));
document.getElementById('state').addEventListener('click', () => actions.state(api));const names = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland', 'Dallas', 'Miami', 'Phoenix'];
// The column toolbar works together with collapsible header groups and a pinned column. No. is pinned at the start,
// so a chip can never move it out of the pinned zone, and a column inside a collapsed group stays folded
// until you expand the group (then it follows its chip).
export const options = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: 'Branch', width: 120 },
{ id: 'q1', title: 'Q1', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: 'Q2', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: 'Q3', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: 'Q4', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: 'First half', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: 'Second half', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
log('Hide or move quarters with the chips, and fold groups with the arrow in the group title.');
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) => log(`Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`));
return () => off();
}
export const actions = {
collapseAll: (api) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api) => api.setColumnVisible('q2', false),
state: (api) => say(`Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Use the toolbar with header groups and a pinned column</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="collapseAll">Collapse all groups</button>
<button type="button" id="expandAll">Expand all groups</button>
<button type="button" id="hideQ2">Hide Q2</button>
<button type="button" id="state">Show saved order</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland', 'Dallas', 'Miami', 'Phoenix'];
// The column toolbar works together with collapsible header groups and a pinned column. No. is pinned at the start,
// so a chip can never move it out of the pinned zone, and a column inside a collapsed group stays folded
// until you expand the group (then it follows its chip).
const options = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: 'Branch', width: 120 },
{ id: 'q1', title: 'Q1', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: 'Q2', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: 'Q3', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: 'Q4', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: 'First half', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: 'Second half', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say = () => { };
function setup(api, log) {
say = log;
log('Hide or move quarters with the chips, and fold groups with the arrow in the group title.');
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) => log(`Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`));
return () => off();
}
const actions = {
collapseAll: (api) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api) => api.setColumnVisible('q2', false),
state: (api) => say(`Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`),
};
options.ariaLabel = "Use the toolbar with header groups and a pinned column";
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('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('hideQ2').addEventListener('click', () => actions.hideQ2(api));
document.getElementById('state').addEventListener('click', () => actions.state(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.collapseAll(api)}
>Collapse all groups</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>Expand all groups</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hideQ2(api)}
>Hide Q2</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.state(api)}
>Show saved order</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland', 'Dallas', 'Miami', 'Phoenix'];
// The column toolbar works together with collapsible header groups and a pinned column. No. is pinned at the start,
// so a chip can never move it out of the pinned zone, and a column inside a collapsed group stays folded
// until you expand the group (then it follows its chip).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: 'Branch', width: 120 },
{ id: 'q1', title: 'Q1', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: 'Q2', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: 'Q3', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: 'Q4', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: 'First half', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: 'Second half', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Hide or move quarters with the chips, and fold groups with the arrow in the group title.');
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log(`Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say(
`Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
),
};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.collapseAll(api)"
>Collapse all groups</button>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>Expand all groups</button>
<button type="button" :disabled="!api" @click="api && actions.hideQ2(api)">Hide Q2</button>
<button type="button" :disabled="!api" @click="api && actions.state(api)">Show saved order</button>
</div>
<Grid style="height: 360px" :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;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland', 'Dallas', 'Miami', 'Phoenix'];
// The column toolbar works together with collapsible header groups and a pinned column. No. is pinned at the start,
// so a chip can never move it out of the pinned zone, and a column inside a collapsed group stays folded
// until you expand the group (then it follows its chip).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: 'Branch', width: 120 },
{ id: 'q1', title: 'Q1', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: 'Q2', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: 'Q3', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: 'Q4', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: 'First half', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: 'Second half', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Hide or move quarters with the chips, and fold groups with the arrow in the group title.');
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log(`Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say(
`Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
),
};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.collapseAll(api)"
>Collapse all groups</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>Expand all groups</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hideQ2(api)"
>Hide Q2</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.state(api)"
>Show saved order</button>
</div>
<mx-grid style="height: 360px" [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;
name: string;
q1: number;
q2: number;
q3: number;
q4: number;
}
const names = ['Austin', 'Boston', 'Denver', 'Seattle', 'Portland', 'Dallas', 'Miami', 'Phoenix'];
// The column toolbar works together with collapsible header groups and a pinned column. No. is pinned at the start,
// so a chip can never move it out of the pinned zone, and a column inside a collapsed group stays folded
// until you expand the group (then it follows its chip).
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', width: 70, align: 'end', pinned: 'start' },
{ id: 'name', title: 'Branch', width: 120 },
{ id: 'q1', title: 'Q1', kind: 'number', width: 100, align: 'end' },
{ id: 'q2', title: 'Q2', kind: 'number', width: 100, align: 'end' },
{ id: 'q3', title: 'Q3', kind: 'number', width: 100, align: 'end' },
{ id: 'q4', title: 'Q4', kind: 'number', width: 100, align: 'end' },
],
headerGroups: [
{ id: 'h1', title: 'First half', collapsible: true, children: ['q1', 'q2'] },
{ id: 'h2', title: 'Second half', collapsible: true, children: ['q3', 'q4'] },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
q1: 100 + ((i * 37) % 90),
q2: 120 + ((i * 53) % 80),
q3: 90 + ((i * 29) % 100),
q4: 140 + ((i * 41) % 70),
})),
rowKey: 'id',
showRowNumbers: false,
columnToolbar: { position: 'top', showLabels: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Hide or move quarters with the chips, and fold groups with the arrow in the group title.');
const off = api.on('headerGroupToggled', ({ groupId, collapsed }) =>
log(`Group ${groupId} ${collapsed ? 'collapsed' : 'expanded'}`),
);
return () => off();
}
export const actions = {
collapseAll: (api: GridApi<Row>) => {
api.collapseHeaderGroup('h1');
api.collapseHeaderGroup('h2');
},
expandAll: (api: GridApi<Row>) => {
api.expandHeaderGroup('h1');
api.expandHeaderGroup('h2');
},
hideQ2: (api: GridApi<Row>) => api.setColumnVisible('q2', false),
state: (api: GridApi<Row>) =>
say(
`Saved order: ${api
.getColumnState()
.map((s) => `${s.id}${s.hidden ? ' (hidden)' : ''}`)
.join(' · ')}`,
),
};