스크롤해도 붙어 있는 그룹 머리글Group headers that stay pinned while scrolling
groupRows.sticky: true면 지금 보는 그룹의 머리글 행이 컬럼 헤더 아래에 붙어 있어요. 그룹이 중첩되면 바깥 그룹부터 쌓이고(최대 3단계), 붙은 행을 누르면 그 그룹이 접혀요.With groupRows.sticky: true the header row of the group you are inside stays under the column header. Nested groups stack outermost first (up to 3 levels) and a click on a pinned row collapses that 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">
<select aria-label="붙이기" id="sticky">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<select aria-label="그룹 단계" id="levels">
<option value="two" selected>팀 > 도시</option>
<option value="one">팀만</option>
</select>
<button type="button" id="jump">중간으로 이동</button>
</div>
<div id="grid" style="height: 320px"></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('sticky').addEventListener('change', (event) => actions.sticky(api, event.target.value));
document.getElementById('levels').addEventListener('change', (event) => actions.levels(api, event.target.value));
document.getElementById('jump').addEventListener('click', () => actions.jump(api));const teams = ['개발', '디자인', '기획', '영업'];
const cities = ['서울', '부산'];
const names = [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'강지후',
'윤서아',
'임태민',
'한소희',
'오세훈',
];
const rows = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)],
city: cities[Math.floor(i / 12) % 2],
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true면 스크롤해도 지금 보는 그룹의 머리글 행이 헤더 아래에 붙어 있어요(중첩은 마지막 3단계까지).
export const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 110 },
{
id: 'salary',
title: '연봉 ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api, log) {
log({
ko: '아래로 스크롤하면 지금 보는 팀과 도시의 머리글 행이 헤더 아래에 붙어 있어요. 붙은 행을 누르면 그 그룹이 접혀요.',
en: 'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
});
return () => undefined;
}
export const actions = {
sticky: (api, value) => api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api, value) => api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api) => api.scrollToIndex(60),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>스크롤해도 붙어 있는 그룹 머리글</title>
</head>
<body>
<div class="toolbar">
<select aria-label="붙이기" id="sticky">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<select aria-label="그룹 단계" id="levels">
<option value="two" selected>팀 > 도시</option>
<option value="one">팀만</option>
</select>
<button type="button" id="jump">중간으로 이동</button>
</div>
<div id="grid" style="height: 320px"></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 names = [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'강지후',
'윤서아',
'임태민',
'한소희',
'오세훈',
];
const rows = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)],
city: cities[Math.floor(i / 12) % 2],
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true면 스크롤해도 지금 보는 그룹의 머리글 행이 헤더 아래에 붙어 있어요(중첩은 마지막 3단계까지).
const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 110 },
{
id: 'salary',
title: '연봉 ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
function setup(_api, log) {
log({
ko: '아래로 스크롤하면 지금 보는 팀과 도시의 머리글 행이 헤더 아래에 붙어 있어요. 붙은 행을 누르면 그 그룹이 접혀요.',
en: 'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
});
return () => undefined;
}
const actions = {
sticky: (api, value) => api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api, value) => api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api) => api.scrollToIndex(60),
};
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('sticky').addEventListener('change', (event) => actions.sticky(api, event.target.value));
document.getElementById('levels').addEventListener('change', (event) => actions.levels(api, event.target.value));
document.getElementById('jump').addEventListener('click', () => actions.jump(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.sticky(api, event.target.value)}
>
<option value="on">켜기</option>
<option value="off">끄기</option>
</select>
<select defaultValue="on"
aria-label="그룹 단계"
disabled={!api}
onChange={(event) => api && actions.levels(api, event.target.value)}
>
<option value="two">팀 > 도시</option>
<option value="one">팀만</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.jump(api)}
>중간으로 이동</button>
</div>
<Grid style={{ height: 320 }} 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;
team: string;
city: string;
salary: number;
}
const teams = ['개발', '디자인', '기획', '영업'];
const cities = ['서울', '부산'];
const names = [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'강지후',
'윤서아',
'임태민',
'한소희',
'오세훈',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true면 스크롤해도 지금 보는 그룹의 머리글 행이 헤더 아래에 붙어 있어요(중첩은 마지막 3단계까지).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 110 },
{
id: 'salary',
title: '연봉 ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '아래로 스크롤하면 지금 보는 팀과 도시의 머리글 행이 헤더 아래에 붙어 있어요. 붙은 행을 누르면 그 그룹이 접혀요.',
en: 'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
});
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};버튼을 누르면 이 예제의 코드가 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.sticky(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<select
aria-label="그룹 단계"
:disabled="!api"
@change="api && actions.levels(api, ($event.target as HTMLSelectElement).value)"
>
<option value="two" selected>팀 > 도시</option>
<option value="one">팀만</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.jump(api)">중간으로 이동</button>
</div>
<Grid style="height: 320px" :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;
team: string;
city: string;
salary: number;
}
const teams = ['개발', '디자인', '기획', '영업'];
const cities = ['서울', '부산'];
const names = [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'강지후',
'윤서아',
'임태민',
'한소희',
'오세훈',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true면 스크롤해도 지금 보는 그룹의 머리글 행이 헤더 아래에 붙어 있어요(중첩은 마지막 3단계까지).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 110 },
{
id: 'salary',
title: '연봉 ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '아래로 스크롤하면 지금 보는 팀과 도시의 머리글 행이 헤더 아래에 붙어 있어요. 붙은 행을 누르면 그 그룹이 접혀요.',
en: 'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
});
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};버튼을 누르면 이 예제의 코드가 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.sticky(api, $any($event.target).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
<select
aria-label="그룹 단계"
[disabled]="!api"
(change)="api && actions.levels(api, $any($event.target).value)"
>
<option value="two" selected>팀 > 도시</option>
<option value="one">팀만</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.jump(api)"
>중간으로 이동</button>
</div>
<mx-grid style="height: 320px" [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;
team: string;
city: string;
salary: number;
}
const teams = ['개발', '디자인', '기획', '영업'];
const cities = ['서울', '부산'];
const names = [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'강지후',
'윤서아',
'임태민',
'한소희',
'오세훈',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true면 스크롤해도 지금 보는 그룹의 머리글 행이 헤더 아래에 붙어 있어요(중첩은 마지막 3단계까지).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 110 },
{ id: 'city', title: '도시', width: 110 },
{
id: 'salary',
title: '연봉 ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '아래로 스크롤하면 지금 보는 팀과 도시의 머리글 행이 헤더 아래에 붙어 있어요. 붙은 행을 누르면 그 그룹이 접혀요.',
en: 'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
});
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};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="Pinning" id="sticky">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<select aria-label="Group levels" id="levels">
<option value="two" selected>Team > City</option>
<option value="one">Team only</option>
</select>
<button type="button" id="jump">Jump to the middle</button>
</div>
<div id="grid" style="height: 320px"></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('sticky').addEventListener('change', (event) => actions.sticky(api, event.target.value));
document.getElementById('levels').addEventListener('change', (event) => actions.levels(api, event.target.value));
document.getElementById('jump').addEventListener('click', () => actions.jump(api));const teams = ['Dev', 'Design', 'Planning', 'Sales'];
const cities = ['New York', 'Boston'];
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
'Mia Grant',
'Ethan Cole',
];
const rows = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)],
city: cities[Math.floor(i / 12) % 2],
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true keeps the header row of the group you are inside under the column header while scrolling (up to the last 3 nested levels).
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 110 },
{
id: 'salary',
title: 'Salary ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api, log) {
log('Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.');
return () => undefined;
}
export const actions = {
sticky: (api, value) => api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api, value) => api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api) => api.scrollToIndex(60),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Group headers that stay pinned while scrolling</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Pinning" id="sticky">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<select aria-label="Group levels" id="levels">
<option value="two" selected>Team > City</option>
<option value="one">Team only</option>
</select>
<button type="button" id="jump">Jump to the middle</button>
</div>
<div id="grid" style="height: 320px"></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', 'Planning', 'Sales'];
const cities = ['New York', 'Boston'];
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
'Mia Grant',
'Ethan Cole',
];
const rows = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)],
city: cities[Math.floor(i / 12) % 2],
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true keeps the header row of the group you are inside under the column header while scrolling (up to the last 3 nested levels).
const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 110 },
{
id: 'salary',
title: 'Salary ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
function setup(_api, log) {
log('Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.');
return () => undefined;
}
const actions = {
sticky: (api, value) => api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api, value) => api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api) => api.scrollToIndex(60),
};
options.ariaLabel = "Group headers that stay pinned while scrolling";
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('sticky').addEventListener('change', (event) => actions.sticky(api, event.target.value));
document.getElementById('levels').addEventListener('change', (event) => actions.levels(api, event.target.value));
document.getElementById('jump').addEventListener('click', () => actions.jump(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="Pinning"
disabled={!api}
onChange={(event) => api && actions.sticky(api, event.target.value)}
>
<option value="on">On</option>
<option value="off">Off</option>
</select>
<select defaultValue="on"
aria-label="Group levels"
disabled={!api}
onChange={(event) => api && actions.levels(api, event.target.value)}
>
<option value="two">Team > City</option>
<option value="one">Team only</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.jump(api)}
>Jump to the middle</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const teams = ['Dev', 'Design', 'Planning', 'Sales'];
const cities = ['New York', 'Boston'];
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
'Mia Grant',
'Ethan Cole',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true keeps the header row of the group you are inside under the column header while scrolling (up to the last 3 nested levels).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 110 },
{
id: 'salary',
title: 'Salary ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
);
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};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="Pinning"
:disabled="!api"
@change="api && actions.sticky(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<select
aria-label="Group levels"
:disabled="!api"
@change="api && actions.levels(api, ($event.target as HTMLSelectElement).value)"
>
<option value="two" selected>Team > City</option>
<option value="one">Team only</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.jump(api)">Jump to the middle</button>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
city: string;
salary: number;
}
const teams = ['Dev', 'Design', 'Planning', 'Sales'];
const cities = ['New York', 'Boston'];
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
'Mia Grant',
'Ethan Cole',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true keeps the header row of the group you are inside under the column header while scrolling (up to the last 3 nested levels).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 110 },
{
id: 'salary',
title: 'Salary ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
);
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};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="Pinning"
[disabled]="!api"
(change)="api && actions.sticky(api, $any($event.target).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
<select
aria-label="Group levels"
[disabled]="!api"
(change)="api && actions.levels(api, $any($event.target).value)"
>
<option value="two" selected>Team > City</option>
<option value="one">Team only</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.jump(api)"
>Jump to the middle</button>
</div>
<mx-grid style="height: 320px" [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;
name: string;
team: string;
city: string;
salary: number;
}
const teams = ['Dev', 'Design', 'Planning', 'Sales'];
const cities = ['New York', 'Boston'];
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
'Mia Grant',
'Ethan Cole',
];
const rows: Row[] = Array.from({ length: 96 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 24)] as string,
city: cities[Math.floor(i / 12) % 2] as string,
salary: 42 + ((i * 7) % 31),
}));
// groupRows.sticky: true keeps the header row of the group you are inside under the column header while scrolling (up to the last 3 nested levels).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'city', title: 'City', width: 110 },
{
id: 'salary',
title: 'Salary ($1,000)',
kind: 'number',
width: 140,
align: 'end',
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team', 'city'], expandDepth: 'all' },
groupRows: { sticky: true },
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Scroll down: the header rows of the team and city you are in stay under the column header. Click a pinned row to collapse its group.',
);
return () => undefined;
}
export const actions = {
sticky: (api: GridApi<Row>, value?: string) =>
api.setOptions({ groupRows: { sticky: value !== 'off' } }),
levels: (api: GridApi<Row>, value?: string) =>
api.setOptions({
grouping: { by: value === 'one' ? ['team'] : ['team', 'city'], expandDepth: 'all' },
}),
jump: (api: GridApi<Row>) => api.scrollToIndex(60),
};