페이지 막대 모양 고르기Choose the pager style
pager 옵션으로 페이지 막대를 기본(처음·번호·끝), 간단(이전·다음과 n / m), 버튼(번호 버튼만) 중에서 골라요.The pager option switches the page bar between full (first, numbers, last), simple (previous, next and "n of m") and button (numbered buttons only).
코드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="pager">
<option value="full" selected>기본</option>
<option value="simple">간단</option>
<option value="button">버튼</option>
</select>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const paging = (pager) => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
position: 'top',
// pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
pager,
// 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
messages: { pageOf: '{page} / {total} 페이지' },
});
export const options = {
columns: [
{ id: 'employee', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }));
return () => off();
}
export const actions = {
// 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};<!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="pager">
<option value="full" selected>기본</option>
<option value="simple">간단</option>
<option value="button">버튼</option>
</select>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const paging = (pager) => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
position: 'top',
// pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
pager,
// 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
messages: { pageOf: '{page} / {total} 페이지' },
});
const options = {
columns: [
{ id: 'employee', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
})),
rowKey: 'id',
pagination: paging('full'),
};
function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }));
return () => off();
}
const actions = {
// 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};
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('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));
</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.pager(api, event.target.value)}
>
<option value="full">기본</option>
<option value="simple">간단</option>
<option value="button">버튼</option>
</select>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
employee: string;
team: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
position: 'top',
// pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
pager,
// 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
messages: { pageOf: '{page} / {total} 페이지' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) =>
log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }),
);
return () => off();
}
export const actions = {
// 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};버튼을 누르면 이 예제의 코드가 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.pager(api, ($event.target as HTMLSelectElement).value)"
>
<option value="full" selected>기본</option>
<option value="simple">간단</option>
<option value="button">버튼</option>
</select>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
employee: string;
team: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
position: 'top',
// pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
pager,
// 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
messages: { pageOf: '{page} / {total} 페이지' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) =>
log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }),
);
return () => off();
}
export const actions = {
// 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};버튼을 누르면 이 예제의 코드가 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.pager(api, $any($event.target).value)"
>
<option value="full" selected>기본</option>
<option value="simple">간단</option>
<option value="button">버튼</option>
</select>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
employee: string;
team: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
position: 'top',
// pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
pager,
// 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
messages: { pageOf: '{page} / {total} 페이지' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) =>
log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }),
);
return () => off();
}
export const actions = {
// 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};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="Pager style" id="pager">
<option value="full" selected>Full (default)</option>
<option value="simple">Simple</option>
<option value="button">Buttons</option>
</select>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const paging = (pager) => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// Put the bar above the table so the select that picks the style and the changed bar are on screen together.
position: 'top',
// pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
pager,
// Make the "n / m" text of the simple style say "Page" like the other places.
messages: { pageOf: 'Page {page} / {total}' },
});
export const options = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
return () => off();
}
export const actions = {
// Only the style changes; the current page and the rows per page stay the same.
pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Choose the pager style</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Pager style" id="pager">
<option value="full" selected>Full (default)</option>
<option value="simple">Simple</option>
<option value="button">Buttons</option>
</select>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const paging = (pager) => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// Put the bar above the table so the select that picks the style and the changed bar are on screen together.
position: 'top',
// pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
pager,
// Make the "n / m" text of the simple style say "Page" like the other places.
messages: { pageOf: 'Page {page} / {total}' },
});
const options = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
})),
rowKey: 'id',
pagination: paging('full'),
};
function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
return () => off();
}
const actions = {
// Only the style changes; the current page and the rows per page stay the same.
pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};
options.ariaLabel = "Choose the pager style";
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('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));
</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="Pager style"
disabled={!api}
onChange={(event) => api && actions.pager(api, event.target.value)}
>
<option value="full">Full (default)</option>
<option value="simple">Simple</option>
<option value="button">Buttons</option>
</select>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
employee: string;
team: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// Put the bar above the table so the select that picks the style and the changed bar are on screen together.
position: 'top',
// pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
pager,
// Make the "n / m" text of the simple style say "Page" like the other places.
messages: { pageOf: 'Page {page} / {total}' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
return () => off();
}
export const actions = {
// Only the style changes; the current page and the rows per page stay the same.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};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="Pager style"
:disabled="!api"
@change="api && actions.pager(api, ($event.target as HTMLSelectElement).value)"
>
<option value="full" selected>Full (default)</option>
<option value="simple">Simple</option>
<option value="button">Buttons</option>
</select>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
employee: string;
team: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// Put the bar above the table so the select that picks the style and the changed bar are on screen together.
position: 'top',
// pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
pager,
// Make the "n / m" text of the simple style say "Page" like the other places.
messages: { pageOf: 'Page {page} / {total}' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
return () => off();
}
export const actions = {
// Only the style changes; the current page and the rows per page stay the same.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};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="Pager style"
[disabled]="!api"
(change)="api && actions.pager(api, $any($event.target).value)"
>
<option value="full" selected>Full (default)</option>
<option value="simple">Simple</option>
<option value="button">Buttons</option>
</select>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
employee: string;
team: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
type Pager = 'full' | 'simple' | 'button';
const paging = (pager: Pager): NonNullable<GridOptions<Row>['pagination']> => ({
mode: 'client',
pageSize: 5,
pageSizes: [5, 10],
// Put the bar above the table so the select that picks the style and the changed bar are on screen together.
position: 'top',
// pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
pager,
// Make the "n / m" text of the simple style say "Page" like the other places.
messages: { pageOf: 'Page {page} / {total}' },
});
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
})),
rowKey: 'id',
pagination: paging('full'),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
return () => off();
}
export const actions = {
// Only the style changes; the current page and the rows per page stay the same.
pager: (api: GridApi<Row>, value?: string) =>
api.setOptions({ pagination: paging((value ?? 'full') as Pager) }),
};