한 페이지 개수와 안내 문구 바꾸기Change rows per page and the pager text
한 페이지에 15건씩 보이게 하고, 페이지 막대의 위치(위·아래)와 "총 300건 중 1–15" 같은 안내 문구를 내 말투로 바꿔요. 설정 몇 줄이면 돼요.Show 15 rows per page, move the pager to the top or bottom, and replace the "1–15 of 300" text with your own wording. A few settings are enough.
코드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="position">
<option value="bottom" selected>아래 (기본)</option>
<option value="top">위</option>
</select>
<select aria-label="안내 문구" id="messages">
<option value="default" selected>기본 문구</option>
<option value="custom">내 문구</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);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(api, event.target.value));// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
default: {},
custom: {
summary: L('게시글 {total}개 중 {from}번~{to}번 보는 중', 'Showing posts {from}-{to} of {total}'),
},
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
export const options = {
columns: [
{ id: 'title', title: '제목', width: 260 },
{ id: 'author', title: '작성자', width: 110 },
{
id: 'views',
title: '조회수',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `공지사항 ${300 - i}번째 안내드립니다`,
author: authors[i % 5],
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => { };
}
export const actions = {
position: (api, value) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api, value) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};<!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="position">
<option value="bottom" selected>아래 (기본)</option>
<option value="top">위</option>
</select>
<select aria-label="안내 문구" id="messages">
<option value="default" selected>기본 문구</option>
<option value="custom">내 문구</option>
</select>
</div>
<div id="grid" style="height: 600px"></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 authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
default: {},
custom: {
summary: L('게시글 {total}개 중 {from}번~{to}번 보는 중', 'Showing posts {from}-{to} of {total}'),
},
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
const options = {
columns: [
{ id: 'title', title: '제목', width: 260 },
{ id: 'author', title: '작성자', width: 110 },
{
id: 'views',
title: '조회수',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `공지사항 ${300 - i}번째 안내드립니다`,
author: authors[i % 5],
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
function setup() {
position = 'bottom';
messages = 'default';
return () => { };
}
const actions = {
position: (api, value) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api, value) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};
options.ariaLabel = "한 페이지 개수와 안내 문구 바꾸기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(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) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="막대 위치"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="bottom">아래 (기본)</option>
<option value="top">위</option>
</select>
<select defaultValue="bottom"
aria-label="안내 문구"
disabled={!api}
onChange={(event) => api && actions.messages(api, event.target.value)}
>
<option value="default">기본 문구</option>
<option value="custom">내 문구</option>
</select>
</div>
<Grid style={{ height: 600 }} 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;
title: string;
author: string;
views: number;
}
const authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
default: {},
custom: {
summary: L(
'게시글 {total}개 중 {from}번~{to}번 보는 중',
'Showing posts {from}-{to} of {total}',
),
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '제목', width: 260 },
{ id: 'author', title: '작성자', width: 110 },
{
id: 'views',
title: '조회수',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `공지사항 ${300 - i}번째 안내드립니다`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};버튼을 누르면 이 예제의 코드가 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);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="막대 위치"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="bottom" selected>아래 (기본)</option>
<option value="top">위</option>
</select>
<select
aria-label="안내 문구"
:disabled="!api"
@change="api && actions.messages(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>기본 문구</option>
<option value="custom">내 문구</option>
</select>
</div>
<Grid style="height: 600px" :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;
title: string;
author: string;
views: number;
}
const authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
default: {},
custom: {
summary: L(
'게시글 {total}개 중 {from}번~{to}번 보는 중',
'Showing posts {from}-{to} of {total}',
),
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '제목', width: 260 },
{ id: 'author', title: '작성자', width: 110 },
{
id: 'views',
title: '조회수',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `공지사항 ${300 - i}번째 안내드립니다`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};버튼을 누르면 이 예제의 코드가 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.position(api, $any($event.target).value)"
>
<option value="bottom" selected>아래 (기본)</option>
<option value="top">위</option>
</select>
<select
aria-label="안내 문구"
[disabled]="!api"
(change)="api && actions.messages(api, $any($event.target).value)"
>
<option value="default" selected>기본 문구</option>
<option value="custom">내 문구</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);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}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;
title: string;
author: string;
views: number;
}
const authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
default: {},
custom: {
summary: L(
'게시글 {total}개 중 {from}번~{to}번 보는 중',
'Showing posts {from}-{to} of {total}',
),
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '제목', width: 260 },
{ id: 'author', title: '작성자', width: 110 },
{
id: 'views',
title: '조회수',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `공지사항 ${300 - i}번째 안내드립니다`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};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 position" id="position">
<option value="bottom" selected>Bottom (default)</option>
<option value="top">Top</option>
</select>
<select aria-label="Pager text" id="messages">
<option value="default" selected>Default</option>
<option value="custom">Custom</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);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(api, event.target.value));const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
default: {},
custom: {
summary: 'Showing posts {from}-{to} of {total}',
},
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
export const options = {
columns: [
{ id: 'title', title: 'Title', width: 260 },
{ id: 'author', title: 'Author', width: 120 },
{
id: 'views',
title: 'Views',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `Announcement no. ${300 - i}`,
author: authors[i % 5],
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => { };
}
export const actions = {
position: (api, value) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api, value) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change rows per page and the pager text</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Pager position" id="position">
<option value="bottom" selected>Bottom (default)</option>
<option value="top">Top</option>
</select>
<select aria-label="Pager text" id="messages">
<option value="default" selected>Default</option>
<option value="custom">Custom</option>
</select>
</div>
<div id="grid" style="height: 600px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
default: {},
custom: {
summary: 'Showing posts {from}-{to} of {total}',
},
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
const options = {
columns: [
{ id: 'title', title: 'Title', width: 260 },
{ id: 'author', title: 'Author', width: 120 },
{
id: 'views',
title: 'Views',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `Announcement no. ${300 - i}`,
author: authors[i % 5],
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
function setup() {
position = 'bottom';
messages = 'default';
return () => { };
}
const actions = {
position: (api, value) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api, value) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};
options.ariaLabel = "Change rows per page and the pager text";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(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) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Pager position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="bottom">Bottom (default)</option>
<option value="top">Top</option>
</select>
<select defaultValue="bottom"
aria-label="Pager text"
disabled={!api}
onChange={(event) => api && actions.messages(api, event.target.value)}
>
<option value="default">Default</option>
<option value="custom">Custom</option>
</select>
</div>
<Grid style={{ height: 600 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
title: string;
author: string;
views: number;
}
const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
default: {},
custom: {
summary: 'Showing posts {from}-{to} of {total}',
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 260 },
{ id: 'author', title: 'Author', width: 120 },
{
id: 'views',
title: 'Views',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `Announcement no. ${300 - i}`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};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);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Pager position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="bottom" selected>Bottom (default)</option>
<option value="top">Top</option>
</select>
<select
aria-label="Pager text"
:disabled="!api"
@change="api && actions.messages(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>Default</option>
<option value="custom">Custom</option>
</select>
</div>
<Grid style="height: 600px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
title: string;
author: string;
views: number;
}
const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
default: {},
custom: {
summary: 'Showing posts {from}-{to} of {total}',
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 260 },
{ id: 'author', title: 'Author', width: 120 },
{
id: 'views',
title: 'Views',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `Announcement no. ${300 - i}`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};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 position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="bottom" selected>Bottom (default)</option>
<option value="top">Top</option>
</select>
<select
aria-label="Pager text"
[disabled]="!api"
(change)="api && actions.messages(api, $any($event.target).value)"
>
<option value="default" selected>Default</option>
<option value="custom">Custom</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);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
title: string;
author: string;
views: number;
}
const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
default: {},
custom: {
summary: 'Showing posts {from}-{to} of {total}',
},
};
const build = (position: 'top' | 'bottom', messages: 'default' | 'custom') =>
({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] }) as const;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 260 },
{ id: 'author', title: 'Author', width: 120 },
{
id: 'views',
title: 'Views',
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 300 }, (_, i) => ({
id: i + 1,
title: `Announcement no. ${300 - i}`,
author: authors[i % 5] as string,
views: 120 + ((i * 7919) % 9000),
})),
rowKey: 'id',
pagination: build('bottom', 'default'),
};
let position: 'top' | 'bottom' = 'bottom';
let messages: 'default' | 'custom' = 'default';
const apply = (api: GridApi<Row>): void =>
api.setOptions({ pagination: build(position, messages) });
export function setup() {
position = 'bottom';
messages = 'default';
return () => {};
}
export const actions = {
position: (api: GridApi<Row>, value?: string) => {
position = value === 'top' ? 'top' : 'bottom';
apply(api);
},
messages: (api: GridApi<Row>, value?: string) => {
messages = value === 'custom' ? 'custom' : 'default';
apply(api);
},
};