페이지당 행 수를 사용자가 고르게 하기Let users pick how many rows per page
5, 10, 15건 중에서 한 페이지에 몇 건을 볼지 고를 수 있는 칸을 페이지 막대에 달아요. 개수를 바꾸면 전체 페이지 수가 바로 다시 계산돼요.Add a rows-per-page chooser (5, 10, 15) to the pager. Changing it recalculates the page count immediately.
코드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="size">
<option value="5">5건</option>
<option value="10" selected>10건 (기본)</option>
<option value="15">15건</option>
</select>
</div>
<div id="grid" style="height: 600px"></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('size').addEventListener('change', (event) => actions.size(api, event.target.value));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// pageSizes에 후보를 적으면 페이지 막대에 "페이지당 행 수" 선택 칸이 생겨요.
export const options = {
columns: [
{ id: 'employee', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 120 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
salary: 3800 + ((i * 537) % 4200),
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api, log) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log({
ko: `페이지당 ${lastSize}건 → ${pageSize}건 (전체 ${pageCount}페이지)`,
en: `Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`,
});
}
lastSize = pageSize;
// 쪽 막대에서 크기를 바꿔도 위의 '코드로 바꾸기' 선택 목록이 같은 값을 보여 주게 맞춰요.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement)
select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// 코드로도 바꿀 수 있어요.
size: (api, value) => api.setPageSize(Number(value ?? 10)),
};<!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="size">
<option value="5">5건</option>
<option value="10" selected>10건 (기본)</option>
<option value="15">15건</option>
</select>
</div>
<div id="grid" style="height: 600px"></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 = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// pageSizes에 후보를 적으면 페이지 막대에 "페이지당 행 수" 선택 칸이 생겨요.
const options = {
columns: [
{ id: 'employee', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 120 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
salary: 3800 + ((i * 537) % 4200),
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
function setup(api, log) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log({
ko: `페이지당 ${lastSize}건 → ${pageSize}건 (전체 ${pageCount}페이지)`,
en: `Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`,
});
}
lastSize = pageSize;
// 쪽 막대에서 크기를 바꿔도 위의 '코드로 바꾸기' 선택 목록이 같은 값을 보여 주게 맞춰요.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement)
select.value = String(pageSize);
});
return () => off();
}
const actions = {
// 코드로도 바꿀 수 있어요.
size: (api, value) => api.setPageSize(Number(value ?? 10)),
};
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('size').addEventListener('change', (event) => actions.size(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.size(api, event.target.value)}
>
<option value="5">5건</option>
<option value="10">10건 (기본)</option>
<option value="15">15건</option>
</select>
</div>
<Grid style={{ height: 600 }} 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;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// pageSizes에 후보를 적으면 페이지 막대에 "페이지당 행 수" 선택 칸이 생겨요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 120 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 537) % 4200),
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log({
ko: `페이지당 ${lastSize}건 → ${pageSize}건 (전체 ${pageCount}페이지)`,
en: `Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`,
});
}
lastSize = pageSize;
// 쪽 막대에서 크기를 바꿔도 위의 '코드로 바꾸기' 선택 목록이 같은 값을 보여 주게 맞춰요.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// 코드로도 바꿀 수 있어요.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};버튼을 누르면 이 예제의 코드가 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.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="5">5건</option>
<option value="10" selected>10건 (기본)</option>
<option value="15">15건</option>
</select>
</div>
<Grid style="height: 600px" :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;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// pageSizes에 후보를 적으면 페이지 막대에 "페이지당 행 수" 선택 칸이 생겨요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 120 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 537) % 4200),
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log({
ko: `페이지당 ${lastSize}건 → ${pageSize}건 (전체 ${pageCount}페이지)`,
en: `Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`,
});
}
lastSize = pageSize;
// 쪽 막대에서 크기를 바꿔도 위의 '코드로 바꾸기' 선택 목록이 같은 값을 보여 주게 맞춰요.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// 코드로도 바꿀 수 있어요.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};버튼을 누르면 이 예제의 코드가 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.size(api, $any($event.target).value)"
>
<option value="5">5건</option>
<option value="10" selected>10건 (기본)</option>
<option value="15">15건</option>
</select>
</div>
<mx-grid style="height: 600px" [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;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// pageSizes에 후보를 적으면 페이지 막대에 "페이지당 행 수" 선택 칸이 생겨요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: '이름', width: 120 },
{ id: 'team', title: '팀', width: 120 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 537) % 4200),
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log({
ko: `페이지당 ${lastSize}건 → ${pageSize}건 (전체 ${pageCount}페이지)`,
en: `Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`,
});
}
lastSize = pageSize;
// 쪽 막대에서 크기를 바꿔도 위의 '코드로 바꾸기' 선택 목록이 같은 값을 보여 주게 맞춰요.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// 코드로도 바꿀 수 있어요.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};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="Set from code" id="size">
<option value="5">5 rows</option>
<option value="10" selected>10 rows (default)</option>
<option value="15">15 rows</option>
</select>
</div>
<div id="grid" style="height: 600px"></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('size').addEventListener('change', (event) => actions.size(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'];
// List candidates in pageSizes and the pager gets a "rows per page" select.
export const options = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
salary: 38000 + ((i * 537) % 4200) * 10,
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api, log) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log(`Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`);
}
lastSize = pageSize;
// Even when the size is changed in the pager, keep the "change from code" select above showing the same value.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement)
select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// You can also change it from code.
size: (api, value) => api.setPageSize(Number(value ?? 10)),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Let users pick how many rows per page</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Set from code" id="size">
<option value="5">5 rows</option>
<option value="10" selected>10 rows (default)</option>
<option value="15">15 rows</option>
</select>
</div>
<div id="grid" style="height: 600px"></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'];
// List candidates in pageSizes and the pager gets a "rows per page" select.
const options = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4],
salary: 38000 + ((i * 537) % 4200) * 10,
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
function setup(api, log) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log(`Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`);
}
lastSize = pageSize;
// Even when the size is changed in the pager, keep the "change from code" select above showing the same value.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement)
select.value = String(pageSize);
});
return () => off();
}
const actions = {
// You can also change it from code.
size: (api, value) => api.setPageSize(Number(value ?? 10)),
};
options.ariaLabel = "Let users pick how many rows per page";
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('size').addEventListener('change', (event) => actions.size(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="Set from code"
disabled={!api}
onChange={(event) => api && actions.size(api, event.target.value)}
>
<option value="5">5 rows</option>
<option value="10">10 rows (default)</option>
<option value="15">15 rows</option>
</select>
</div>
<Grid style={{ height: 600 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
employee: string;
team: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// List candidates in pageSizes and the pager gets a "rows per page" select.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 537) % 4200) * 10,
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log(`Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`);
}
lastSize = pageSize;
// Even when the size is changed in the pager, keep the "change from code" select above showing the same value.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// You can also change it from code.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};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="Set from code"
:disabled="!api"
@change="api && actions.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="5">5 rows</option>
<option value="10" selected>10 rows (default)</option>
<option value="15">15 rows</option>
</select>
</div>
<Grid style="height: 600px" :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;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// List candidates in pageSizes and the pager gets a "rows per page" select.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 537) % 4200) * 10,
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log(`Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`);
}
lastSize = pageSize;
// Even when the size is changed in the pager, keep the "change from code" select above showing the same value.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// You can also change it from code.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};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="Set from code"
[disabled]="!api"
(change)="api && actions.size(api, $any($event.target).value)"
>
<option value="5">5 rows</option>
<option value="10" selected>10 rows (default)</option>
<option value="15">15 rows</option>
</select>
</div>
<mx-grid style="height: 600px" [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;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brown',
'Mia Johnson',
'Jack Miller',
'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// List candidates in pageSizes and the pager gets a "rows per page" select.
export const options: GridOptions<Row> = {
columns: [
{ id: 'employee', title: 'Name', width: 170 },
{ id: 'team', title: 'Team', width: 120 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 200 }, (_, i) => ({
id: i + 1,
employee: `${names[i % 8]} ${i + 1}`,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 537) % 4200) * 10,
})),
rowKey: 'id',
pagination: { mode: 'client', pageSize: 10, pageSizes: [5, 10, 15] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
let lastSize = api.getPageSize();
const off = api.on('pageChanged', ({ pageSize, pageCount, reason }) => {
if (reason === 'size' || pageSize !== lastSize) {
log(`Rows per page ${lastSize} → ${pageSize} (${pageCount} pages in all)`);
}
lastSize = pageSize;
// Even when the size is changed in the pager, keep the "change from code" select above showing the same value.
const select = document.getElementById('size');
if (select instanceof HTMLSelectElement) select.value = String(pageSize);
});
return () => off();
}
export const actions = {
// You can also change it from code.
size: (api: GridApi<Row>, value?: string) => api.setPageSize(Number(value ?? 10)),
};