500건을 20건씩 나눠 보기Split 500 rows into pages of 20
주문 500건을 한 번에 넣고 페이지 나누기만 켜면 20건씩 나눠 보여요. 아래 페이지 막대에서 이동하거나 페이지 번호를 직접 입력할 수 있고, 행 번호는 페이지를 넘어서도 이어져요.Load 500 orders at once, switch paging on and they show 20 at a time. Move with the pager or type a page number; row numbers continue across pages.
코드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">
<button type="button" id="first">첫 페이지</button>
<button type="button" id="page5">5페이지로</button>
<button type="button" id="last">마지막 페이지</button>
<button type="button" id="row200">200번째 행 찾아가기</button>
</div>
<div id="grid" style="height: 760px"></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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
export const options = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7],
region: regions[(i * 3) % 7],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 13) % 30),
amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log({
ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
});
});
return () => off();
}
export const actions = {
page5: (api) => api.setPage(5),
last: (api) => api.setPage(api.getPageCount()),
// 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
row200: (api) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api) => api.setPage(1),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>500건을 20건씩 나눠 보기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="first">첫 페이지</button>
<button type="button" id="page5">5페이지로</button>
<button type="button" id="last">마지막 페이지</button>
<button type="button" id="row200">200번째 행 찾아가기</button>
</div>
<div id="grid" style="height: 760px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
const options = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7],
region: regions[(i * 3) % 7],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 13) % 30),
amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log({
ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
});
});
return () => off();
}
const actions = {
page5: (api) => api.setPage(5),
last: (api) => api.setPage(api.getPageCount()),
// 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
row200: (api) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api) => api.setPage(1),
};
options.ariaLabel = "500건을 20건씩 나눠 보기";
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.first(api)}
>첫 페이지</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.page5(api)}
>5페이지로</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.last(api)}
>마지막 페이지</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.row200(api)}
>200번째 행 찾아가기</button>
</div>
<Grid style={{ height: 760 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log({
ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
});
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};버튼을 누르면 이 예제의 코드가 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">
<button type="button" :disabled="!api" @click="api && actions.first(api)">첫 페이지</button>
<button type="button" :disabled="!api" @click="api && actions.page5(api)">5페이지로</button>
<button type="button" :disabled="!api" @click="api && actions.last(api)">마지막 페이지</button>
<button type="button" :disabled="!api" @click="api && actions.row200(api)">200번째 행 찾아가기</button>
</div>
<Grid style="height: 760px" :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;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log({
ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
});
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.first(api)"
>첫 페이지</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.page5(api)"
>5페이지로</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.last(api)"
>마지막 페이지</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.row200(api)"
>200번째 행 찾아가기</button>
</div>
<mx-grid style="height: 760px" [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;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{ id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log({
ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
});
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="first">First page</button>
<button type="button" id="page5">Go to page 5</button>
<button type="button" id="last">Last page</button>
<button type="button" id="row200">Show row 200</button>
</div>
<div id="grid" style="height: 760px"></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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
'Wireless earbuds',
'Smart watch',
'Laptop stand',
'Power bank',
'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
export const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7],
region: regions[(i * 3) % 7],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 13) % 30),
amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true adds a box where you can type a page number to go to it.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
});
return () => off();
}
export const actions = {
page5: (api) => api.setPage(5),
last: (api) => api.setPage(api.getPageCount()),
// Go find row 200: move to the page that holds it and focus its Amount cell.
row200: (api) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api) => api.setPage(1),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Split 500 rows into pages of 20</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="first">First page</button>
<button type="button" id="page5">Go to page 5</button>
<button type="button" id="last">Last page</button>
<button type="button" id="row200">Show row 200</button>
</div>
<div id="grid" style="height: 760px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
'Wireless earbuds',
'Smart watch',
'Laptop stand',
'Power bank',
'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7],
region: regions[(i * 3) % 7],
product: products[(i * 7) % 5],
quantity: 1 + ((i * 13) % 30),
amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true adds a box where you can type a page number to go to it.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
function setup(api, log) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
});
return () => off();
}
const actions = {
page5: (api) => api.setPage(5),
last: (api) => api.setPage(api.getPageCount()),
// Go find row 200: move to the page that holds it and focus its Amount cell.
row200: (api) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api) => api.setPage(1),
};
options.ariaLabel = "Split 500 rows into pages of 20";
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.first(api)}
>First page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.page5(api)}
>Go to page 5</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.last(api)}
>Last page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.row200(api)}
>Show row 200</button>
</div>
<Grid style={{ height: 760 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
'Wireless earbuds',
'Smart watch',
'Laptop stand',
'Power bank',
'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true adds a box where you can type a page number to go to it.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// Go find row 200: move to the page that holds it and focus its Amount cell.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};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">
<button type="button" :disabled="!api" @click="api && actions.first(api)">First page</button>
<button type="button" :disabled="!api" @click="api && actions.page5(api)">Go to page 5</button>
<button type="button" :disabled="!api" @click="api && actions.last(api)">Last page</button>
<button type="button" :disabled="!api" @click="api && actions.row200(api)">Show row 200</button>
</div>
<Grid style="height: 760px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
'Wireless earbuds',
'Smart watch',
'Laptop stand',
'Power bank',
'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true adds a box where you can type a page number to go to it.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// Go find row 200: move to the page that holds it and focus its Amount cell.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.first(api)"
>First page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.page5(api)"
>Go to page 5</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.last(api)"
>Last page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.row200(api)"
>Show row 200</button>
</div>
<mx-grid style="height: 760px" [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;
customer: string;
region: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
'Wireless earbuds',
'Smart watch',
'Laptop stand',
'Power bank',
'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
customer: customers[i % 7] as string,
region: regions[(i * 3) % 7] as string,
product: products[(i * 7) % 5] as string,
quantity: 1 + ((i * 13) % 30),
amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
})),
rowKey: 'id',
showRowNumbers: true,
// jump: true adds a box where you can type a page number to go to it.
pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('pageChanged', ({ page, pageCount }) => {
const info = api.getPageInfo();
log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
});
return () => off();
}
export const actions = {
page5: (api: GridApi<Row>) => api.setPage(5),
last: (api: GridApi<Row>) => api.setPage(api.getPageCount()),
// Go find row 200: move to the page that holds it and focus its Amount cell.
row200: (api: GridApi<Row>) => {
api.setPage(Math.ceil(200 / api.getPageSize()));
api.focusCell(200, 'amount');
},
first: (api: GridApi<Row>) => api.setPage(1),
};