페이저의 문구와 구성을 내 방식으로Shape the pager text and layout
summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요. autoPageSize는 그리드 높이에 맞춰 한 쪽의 행 수를 정하고, nextPage·lastPage 같은 메서드로 코드에서 쪽을 옮겨요.summary writes the summary text, pageButtons sets the number slots and parts chooses which parts show and in what order. autoPageSize fits the rows per page to the grid height, and nextPage, lastPage and friends move pages from code.
코드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="layout">
<option value="default" selected>기본</option>
<option value="compact">간단하게</option>
<option value="auto">높이에 맞춤</option>
</select>
<button type="button" id="firstPage">처음 쪽</button>
<button type="button" id="prevPage">이전 쪽</button>
<button type="button" id="nextPage">다음 쪽</button>
<button type="button" id="lastPage">마지막 쪽</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('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(api));// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const rows = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `${L('상품', 'Item')} ${i + 1}`,
qty: (i * 7) % 50,
}));
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout) => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: L('이름', 'Name'), width: 160 },
{ id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination: layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => L(`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`, `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`),
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options = optionsFor('default');
export const actions = {
layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
firstPage: (api) => api.firstPage(),
prevPage: (api) => api.prevPage(),
nextPage: (api) => api.nextPage(),
lastPage: (api) => api.lastPage(),
};<!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="layout">
<option value="default" selected>기본</option>
<option value="compact">간단하게</option>
<option value="auto">높이에 맞춤</option>
</select>
<button type="button" id="firstPage">처음 쪽</button>
<button type="button" id="prevPage">이전 쪽</button>
<button type="button" id="nextPage">다음 쪽</button>
<button type="button" id="lastPage">마지막 쪽</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const rows = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `${L('상품', 'Item')} ${i + 1}`,
qty: (i * 7) % 50,
}));
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout) => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: L('이름', 'Name'), width: 160 },
{ id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination: layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => L(`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`, `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`),
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
const options = optionsFor('default');
const actions = {
layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
firstPage: (api) => api.firstPage(),
prevPage: (api) => api.prevPage(),
nextPage: (api) => api.nextPage(),
lastPage: (api) => api.lastPage(),
};
options.ariaLabel = "페이저의 문구와 구성을 내 방식으로";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(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.layout(api, event.target.value)}
>
<option value="default">기본</option>
<option value="compact">간단하게</option>
<option value="auto">높이에 맞춤</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.firstPage(api)}
>처음 쪽</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.prevPage(api)}
>이전 쪽</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.nextPage(api)}
>다음 쪽</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lastPage(api)}
>마지막 쪽</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export interface Row {
id: number;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `${L('상품', 'Item')} ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: L('이름', 'Name'), width: 160 },
{ id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) =>
L(
`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`,
`Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
),
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};버튼을 누르면 이 예제의 코드가 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.layout(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>기본</option>
<option value="compact">간단하게</option>
<option value="auto">높이에 맞춤</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.firstPage(api)"
>처음 쪽</button>
<button
type="button"
:disabled="!api"
@click="api && actions.prevPage(api)"
>이전 쪽</button>
<button
type="button"
:disabled="!api"
@click="api && actions.nextPage(api)"
>다음 쪽</button>
<button
type="button"
:disabled="!api"
@click="api && actions.lastPage(api)"
>마지막 쪽</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export interface Row {
id: number;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `${L('상품', 'Item')} ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: L('이름', 'Name'), width: 160 },
{ id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) =>
L(
`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`,
`Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
),
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};버튼을 누르면 이 예제의 코드가 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.layout(api, $any($event.target).value)"
>
<option value="default" selected>기본</option>
<option value="compact">간단하게</option>
<option value="auto">높이에 맞춤</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.firstPage(api)"
>처음 쪽</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.prevPage(api)"
>이전 쪽</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.nextPage(api)"
>다음 쪽</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lastPage(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';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export interface Row {
id: number;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `${L('상품', 'Item')} ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: L('이름', 'Name'), width: 160 },
{ id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) =>
L(
`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`,
`Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
),
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};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 layout" id="layout">
<option value="default" selected>Default</option>
<option value="compact">Compact</option>
<option value="auto">Fit to height</option>
</select>
<button type="button" id="firstPage">First page</button>
<button type="button" id="prevPage">Previous page</button>
<button type="button" id="nextPage">Next page</button>
<button type="button" id="lastPage">Last page</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('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(api));const rows = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 50,
}));
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout) => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination: layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options = optionsFor('default');
export const actions = {
layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
firstPage: (api) => api.firstPage(),
prevPage: (api) => api.prevPage(),
nextPage: (api) => api.nextPage(),
lastPage: (api) => api.lastPage(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Shape the pager text and layout</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Pager layout" id="layout">
<option value="default" selected>Default</option>
<option value="compact">Compact</option>
<option value="auto">Fit to height</option>
</select>
<button type="button" id="firstPage">First page</button>
<button type="button" id="prevPage">Previous page</button>
<button type="button" id="nextPage">Next page</button>
<button type="button" id="lastPage">Last page</button>
</div>
<div id="grid" style="height: 340px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 50,
}));
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout) => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination: layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
const options = optionsFor('default');
const actions = {
layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
firstPage: (api) => api.firstPage(),
prevPage: (api) => api.prevPage(),
nextPage: (api) => api.nextPage(),
lastPage: (api) => api.lastPage(),
};
options.ariaLabel = "Shape the pager text and layout";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(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="Pager layout"
disabled={!api}
onChange={(event) => api && actions.layout(api, event.target.value)}
>
<option value="default">Default</option>
<option value="compact">Compact</option>
<option value="auto">Fit to height</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.firstPage(api)}
>First page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.prevPage(api)}
>Previous page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.nextPage(api)}
>Next page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lastPage(api)}
>Last page</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};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="Pager layout"
:disabled="!api"
@change="api && actions.layout(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>Default</option>
<option value="compact">Compact</option>
<option value="auto">Fit to height</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.firstPage(api)"
>First page</button>
<button
type="button"
:disabled="!api"
@click="api && actions.prevPage(api)"
>Previous page</button>
<button
type="button"
:disabled="!api"
@click="api && actions.nextPage(api)"
>Next page</button>
<button
type="button"
:disabled="!api"
@click="api && actions.lastPage(api)"
>Last page</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};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="Pager layout"
[disabled]="!api"
(change)="api && actions.layout(api, $any($event.target).value)"
>
<option value="default" selected>Default</option>
<option value="compact">Compact</option>
<option value="auto">Fit to height</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.firstPage(api)"
>First page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.prevPage(api)"
>Previous page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.nextPage(api)"
>Next page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lastPage(api)"
>Last page</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;
name: string;
qty: number;
}
const rows: Row[] = Array.from({ length: 237 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 50,
}));
type Layout = 'default' | 'compact' | 'auto';
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout: Layout): GridOptions<Row> => ({
columns: [
{ id: 'id', title: 'ID', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
rowHeight: 32,
pagination:
layout === 'default'
? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
: layout === 'compact'
? {
mode: 'client',
pageSize: 10,
pageButtons: 5,
parts: ['nav', 'summary'],
summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
}
: { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options: GridOptions<Row> = optionsFor('default');
export const actions = {
layout: (api: GridApi<Row>, value?: string) =>
api.setOptions(optionsFor((value ?? 'default') as Layout)),
firstPage: (api: GridApi<Row>) => api.firstPage(),
prevPage: (api: GridApi<Row>) => api.prevPage(),
nextPage: (api: GridApi<Row>) => api.nextPage(),
lastPage: (api: GridApi<Row>) => api.lastPage(),
};