위쪽 줄 붙여 두기Pin rows to the top
합계·평균 같은 요약 줄을 맨 위에 붙여 두면, 아래로 스크롤해도 헤더 바로 밑에 그대로 보여요. 정렬할 때 이 줄을 같이 정렬할지도 고를 수 있어요.Pin summary rows such as total and average under the header so they stay visible while scrolling. Choose whether sorting moves them too.
코드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="count">
<option value="3">3줄</option>
<option value="2">2줄</option>
<option value="1">1줄</option>
<option value="0">고정 안 함</option>
</select>
<select aria-label="정렬할 때 고정 줄" id="sortMode">
<option value="stay">그대로 두기</option>
<option value="with">같이 정렬</option>
</select>
<button type="button" id="sort">판매량 큰 순 정렬</button>
<button type="button" id="clearSort">정렬 해제</button>
</div>
<div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('count').addEventListener('change', (event) => actions.count(api, event.target.value));
document.getElementById('sortMode').addEventListener('change', (event) => actions.sortMode(api, event.target.value));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clearSort').addEventListener('click', () => actions.clearSort(api));// 아래 40개 품목의 합계·평균·최대를 계산해서 맨 위 세 줄로 놓아요.
// pinnedRows: 3 이면 그 세 줄은 스크롤해도 헤더 아래에 붙어 있어요.
const regions = ['서울점', '부산점', '대구점'];
const items = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `상품 ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows = [
{ id: 1, group: '요약', item: '전체 합계', amount: sum },
{ id: 2, group: '요약', item: '평균', amount: Math.round(sum / items.length) },
{ id: 3, group: '요약', item: '최대', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// 고정 줄 수와 "정렬에 같이 따를지"를 기억해 두었다가 함께 넘겨요.
let count = 3;
let sortToo = false;
export const options = {
columns: [
{ id: 'group', title: '구분', width: 110 },
{ id: 'item', title: '항목', width: 160 },
{ id: 'amount', title: '판매량', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api, value) => {
count = Number(value ?? 0);
apply(api);
},
// 기본은 "그대로". 정렬해도 고정 줄은 위에 원래 순서로 남고, 나머지 줄만 정렬돼요.
sortMode: (api, value) => {
sortToo = value === 'with';
apply(api);
},
sort: (api) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api) => api.setSortModel([]),
};<!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="count">
<option value="3">3줄</option>
<option value="2">2줄</option>
<option value="1">1줄</option>
<option value="0">고정 안 함</option>
</select>
<select aria-label="정렬할 때 고정 줄" id="sortMode">
<option value="stay">그대로 두기</option>
<option value="with">같이 정렬</option>
</select>
<button type="button" id="sort">판매량 큰 순 정렬</button>
<button type="button" id="clearSort">정렬 해제</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 아래 40개 품목의 합계·평균·최대를 계산해서 맨 위 세 줄로 놓아요.
// pinnedRows: 3 이면 그 세 줄은 스크롤해도 헤더 아래에 붙어 있어요.
const regions = ['서울점', '부산점', '대구점'];
const items = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `상품 ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows = [
{ id: 1, group: '요약', item: '전체 합계', amount: sum },
{ id: 2, group: '요약', item: '평균', amount: Math.round(sum / items.length) },
{ id: 3, group: '요약', item: '최대', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// 고정 줄 수와 "정렬에 같이 따를지"를 기억해 두었다가 함께 넘겨요.
let count = 3;
let sortToo = false;
const options = {
columns: [
{ id: 'group', title: '구분', width: 110 },
{ id: 'item', title: '항목', width: 160 },
{ id: 'amount', title: '판매량', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
const actions = {
count: (api, value) => {
count = Number(value ?? 0);
apply(api);
},
// 기본은 "그대로". 정렬해도 고정 줄은 위에 원래 순서로 남고, 나머지 줄만 정렬돼요.
sortMode: (api, value) => {
sortToo = value === 'with';
apply(api);
},
sort: (api) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api) => api.setSortModel([]),
};
options.ariaLabel = "위쪽 줄 붙여 두기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('count').addEventListener('change', (event) => actions.count(api, event.target.value));
document.getElementById('sortMode').addEventListener('change', (event) => actions.sortMode(api, event.target.value));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clearSort').addEventListener('click', () => actions.clearSort(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="고정 줄 수"
disabled={!api}
onChange={(event) => api && actions.count(api, event.target.value)}
>
<option value="3">3줄</option>
<option value="2">2줄</option>
<option value="1">1줄</option>
<option value="0">고정 안 함</option>
</select>
<select
aria-label="정렬할 때 고정 줄"
disabled={!api}
onChange={(event) => api && actions.sortMode(api, event.target.value)}
>
<option value="stay">그대로 두기</option>
<option value="with">같이 정렬</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sort(api)}
>판매량 큰 순 정렬</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clearSort(api)}
>정렬 해제</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// 아래 40개 품목의 합계·평균·최대를 계산해서 맨 위 세 줄로 놓아요.
// pinnedRows: 3 이면 그 세 줄은 스크롤해도 헤더 아래에 붙어 있어요.
const regions = ['서울점', '부산점', '대구점'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `상품 ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: '요약', item: '전체 합계', amount: sum },
{ id: 2, group: '요약', item: '평균', amount: Math.round(sum / items.length) },
{ id: 3, group: '요약', item: '최대', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// 고정 줄 수와 "정렬에 같이 따를지"를 기억해 두었다가 함께 넘겨요.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: '구분', width: 110 },
{ id: 'item', title: '항목', width: 160 },
{ id: 'amount', title: '판매량', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// 기본은 "그대로". 정렬해도 고정 줄은 위에 원래 순서로 남고, 나머지 줄만 정렬돼요.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="고정 줄 수"
:disabled="!api"
@change="api && actions.count(api, ($event.target as HTMLSelectElement).value)"
>
<option value="3">3줄</option>
<option value="2">2줄</option>
<option value="1">1줄</option>
<option value="0">고정 안 함</option>
</select>
<select
aria-label="정렬할 때 고정 줄"
:disabled="!api"
@change="api && actions.sortMode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="stay">그대로 두기</option>
<option value="with">같이 정렬</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.sort(api)">판매량 큰 순 정렬</button>
<button
type="button"
:disabled="!api"
@click="api && actions.clearSort(api)"
>정렬 해제</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// 아래 40개 품목의 합계·평균·최대를 계산해서 맨 위 세 줄로 놓아요.
// pinnedRows: 3 이면 그 세 줄은 스크롤해도 헤더 아래에 붙어 있어요.
const regions = ['서울점', '부산점', '대구점'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `상품 ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: '요약', item: '전체 합계', amount: sum },
{ id: 2, group: '요약', item: '평균', amount: Math.round(sum / items.length) },
{ id: 3, group: '요약', item: '최대', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// 고정 줄 수와 "정렬에 같이 따를지"를 기억해 두었다가 함께 넘겨요.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: '구분', width: 110 },
{ id: 'item', title: '항목', width: 160 },
{ id: 'amount', title: '판매량', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// 기본은 "그대로". 정렬해도 고정 줄은 위에 원래 순서로 남고, 나머지 줄만 정렬돼요.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, 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.count(api, $any($event.target).value)"
>
<option value="3">3줄</option>
<option value="2">2줄</option>
<option value="1">1줄</option>
<option value="0">고정 안 함</option>
</select>
<select
aria-label="정렬할 때 고정 줄"
[disabled]="!api"
(change)="api && actions.sortMode(api, $any($event.target).value)"
>
<option value="stay">그대로 두기</option>
<option value="with">같이 정렬</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sort(api)"
>판매량 큰 순 정렬</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clearSort(api)"
>정렬 해제</button>
</div>
<mx-grid style="height: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// 아래 40개 품목의 합계·평균·최대를 계산해서 맨 위 세 줄로 놓아요.
// pinnedRows: 3 이면 그 세 줄은 스크롤해도 헤더 아래에 붙어 있어요.
const regions = ['서울점', '부산점', '대구점'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `상품 ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: '요약', item: '전체 합계', amount: sum },
{ id: 2, group: '요약', item: '평균', amount: Math.round(sum / items.length) },
{ id: 3, group: '요약', item: '최대', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// 고정 줄 수와 "정렬에 같이 따를지"를 기억해 두었다가 함께 넘겨요.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: '구분', width: 110 },
{ id: 'item', title: '항목', width: 160 },
{ id: 'amount', title: '판매량', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// 기본은 "그대로". 정렬해도 고정 줄은 위에 원래 순서로 남고, 나머지 줄만 정렬돼요.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};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="Pinned rows" id="count">
<option value="3">3 rows</option>
<option value="2">2 rows</option>
<option value="1">1 row</option>
<option value="0">None</option>
</select>
<select aria-label="Pinned rows when sorting" id="sortMode">
<option value="stay">Stay put</option>
<option value="with">Sort too</option>
</select>
<button type="button" id="sort">Sort by quantity</button>
<button type="button" id="clearSort">Clear sort</button>
</div>
<div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('count').addEventListener('change', (event) => actions.count(api, event.target.value));
document.getElementById('sortMode').addEventListener('change', (event) => actions.sortMode(api, event.target.value));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clearSort').addEventListener('click', () => actions.clearSort(api));// Compute the total, average and maximum of the 40 items below and place them as the top three rows.
// With pinnedRows: 3, those three rows stay attached under the header while scrolling.
const regions = ['Seoul Store', 'Busan Store', 'Daegu Store'];
const items = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `Product ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows = [
{ id: 1, group: 'Summary', item: 'Grand total', amount: sum },
{ id: 2, group: 'Summary', item: 'Average', amount: Math.round(sum / items.length) },
{ id: 3, group: 'Summary', item: 'Maximum', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// Remember the number of pinned rows and whether they "follow the sort", and pass them together.
let count = 3;
let sortToo = false;
export const options = {
columns: [
{ id: 'group', title: 'Group', width: 110 },
{ id: 'item', title: 'Item', width: 160 },
{ id: 'amount', title: 'Units sold', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api, value) => {
count = Number(value ?? 0);
apply(api);
},
// The default is "stay put". Even when sorting, the pinned rows stay on top in their original order and only the other rows are sorted.
sortMode: (api, value) => {
sortToo = value === 'with';
apply(api);
},
sort: (api) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api) => api.setSortModel([]),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pin rows to the top</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Pinned rows" id="count">
<option value="3">3 rows</option>
<option value="2">2 rows</option>
<option value="1">1 row</option>
<option value="0">None</option>
</select>
<select aria-label="Pinned rows when sorting" id="sortMode">
<option value="stay">Stay put</option>
<option value="with">Sort too</option>
</select>
<button type="button" id="sort">Sort by quantity</button>
<button type="button" id="clearSort">Clear sort</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// Compute the total, average and maximum of the 40 items below and place them as the top three rows.
// With pinnedRows: 3, those three rows stay attached under the header while scrolling.
const regions = ['Seoul Store', 'Busan Store', 'Daegu Store'];
const items = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `Product ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows = [
{ id: 1, group: 'Summary', item: 'Grand total', amount: sum },
{ id: 2, group: 'Summary', item: 'Average', amount: Math.round(sum / items.length) },
{ id: 3, group: 'Summary', item: 'Maximum', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// Remember the number of pinned rows and whether they "follow the sort", and pass them together.
let count = 3;
let sortToo = false;
const options = {
columns: [
{ id: 'group', title: 'Group', width: 110 },
{ id: 'item', title: 'Item', width: 160 },
{ id: 'amount', title: 'Units sold', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
const actions = {
count: (api, value) => {
count = Number(value ?? 0);
apply(api);
},
// The default is "stay put". Even when sorting, the pinned rows stay on top in their original order and only the other rows are sorted.
sortMode: (api, value) => {
sortToo = value === 'with';
apply(api);
},
sort: (api) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api) => api.setSortModel([]),
};
options.ariaLabel = "Pin rows to the top";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('count').addEventListener('change', (event) => actions.count(api, event.target.value));
document.getElementById('sortMode').addEventListener('change', (event) => actions.sortMode(api, event.target.value));
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('clearSort').addEventListener('click', () => actions.clearSort(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Pinned rows"
disabled={!api}
onChange={(event) => api && actions.count(api, event.target.value)}
>
<option value="3">3 rows</option>
<option value="2">2 rows</option>
<option value="1">1 row</option>
<option value="0">None</option>
</select>
<select
aria-label="Pinned rows when sorting"
disabled={!api}
onChange={(event) => api && actions.sortMode(api, event.target.value)}
>
<option value="stay">Stay put</option>
<option value="with">Sort too</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sort(api)}
>Sort by quantity</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clearSort(api)}
>Clear sort</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// Compute the total, average and maximum of the 40 items below and place them as the top three rows.
// With pinnedRows: 3, those three rows stay attached under the header while scrolling.
const regions = ['Seoul Store', 'Busan Store', 'Daegu Store'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `Product ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: 'Summary', item: 'Grand total', amount: sum },
{ id: 2, group: 'Summary', item: 'Average', amount: Math.round(sum / items.length) },
{ id: 3, group: 'Summary', item: 'Maximum', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// Remember the number of pinned rows and whether they "follow the sort", and pass them together.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: 'Group', width: 110 },
{ id: 'item', title: 'Item', width: 160 },
{ id: 'amount', title: 'Units sold', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// The default is "stay put". Even when sorting, the pinned rows stay on top in their original order and only the other rows are sorted.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Pinned rows"
:disabled="!api"
@change="api && actions.count(api, ($event.target as HTMLSelectElement).value)"
>
<option value="3">3 rows</option>
<option value="2">2 rows</option>
<option value="1">1 row</option>
<option value="0">None</option>
</select>
<select
aria-label="Pinned rows when sorting"
:disabled="!api"
@change="api && actions.sortMode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="stay">Stay put</option>
<option value="with">Sort too</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.sort(api)">Sort by quantity</button>
<button
type="button"
:disabled="!api"
@click="api && actions.clearSort(api)"
>Clear sort</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// Compute the total, average and maximum of the 40 items below and place them as the top three rows.
// With pinnedRows: 3, those three rows stay attached under the header while scrolling.
const regions = ['Seoul Store', 'Busan Store', 'Daegu Store'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `Product ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: 'Summary', item: 'Grand total', amount: sum },
{ id: 2, group: 'Summary', item: 'Average', amount: Math.round(sum / items.length) },
{ id: 3, group: 'Summary', item: 'Maximum', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// Remember the number of pinned rows and whether they "follow the sort", and pass them together.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: 'Group', width: 110 },
{ id: 'item', title: 'Item', width: 160 },
{ id: 'amount', title: 'Units sold', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// The default is "stay put". Even when sorting, the pinned rows stay on top in their original order and only the other rows are sorted.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Pinned rows"
[disabled]="!api"
(change)="api && actions.count(api, $any($event.target).value)"
>
<option value="3">3 rows</option>
<option value="2">2 rows</option>
<option value="1">1 row</option>
<option value="0">None</option>
</select>
<select
aria-label="Pinned rows when sorting"
[disabled]="!api"
(change)="api && actions.sortMode(api, $any($event.target).value)"
>
<option value="stay">Stay put</option>
<option value="with">Sort too</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sort(api)"
>Sort by quantity</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clearSort(api)"
>Clear sort</button>
</div>
<mx-grid style="height: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
group: string;
item: string;
amount: number;
}
// Compute the total, average and maximum of the 40 items below and place them as the top three rows.
// With pinnedRows: 3, those three rows stay attached under the header while scrolling.
const regions = ['Seoul Store', 'Busan Store', 'Daegu Store'];
const items: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 4,
group: regions[i % regions.length],
item: `Product ${String(i + 1).padStart(2, '0')}`,
amount: 100 + ((i * 53) % 400),
}));
const sum = items.reduce((total, row) => total + row.amount, 0);
const rows: Row[] = [
{ id: 1, group: 'Summary', item: 'Grand total', amount: sum },
{ id: 2, group: 'Summary', item: 'Average', amount: Math.round(sum / items.length) },
{ id: 3, group: 'Summary', item: 'Maximum', amount: Math.max(...items.map((row) => row.amount)) },
...items,
];
// Remember the number of pinned rows and whether they "follow the sort", and pass them together.
let count = 3;
let sortToo = false;
export const options: GridOptions<Row> = {
columns: [
{ id: 'group', title: 'Group', width: 110 },
{ id: 'item', title: 'Item', width: 160 },
{ id: 'amount', title: 'Units sold', kind: 'number', width: 120, align: 'end' },
],
rows,
rowKey: 'id',
pinnedRows: { count, sort: sortToo },
};
const apply = (api: GridApi<Row>) => api.setOptions({ pinnedRows: { count, sort: sortToo } });
export const actions = {
count: (api: GridApi<Row>, value?: string) => {
count = Number(value ?? 0);
apply(api);
},
// The default is "stay put". Even when sorting, the pinned rows stay on top in their original order and only the other rows are sorted.
sortMode: (api: GridApi<Row>, value?: string) => {
sortToo = value === 'with';
apply(api);
},
sort: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
clearSort: (api: GridApi<Row>) => api.setSortModel([]),
};