검색하고 걸러도 페이지가 알아서 맞춰져요Search and filter, and the pages adjust themselves
상품 이름을 검색하거나 지역으로 걸러 보세요. 조건에 맞는 행만으로 페이지가 다시 나뉘고, 조건을 바꾸면 늘 1페이지로 돌아가요. 정렬도 걸러진 결과 전체를 기준으로 해요.Search product names or filter by region. Pages are rebuilt from the matching rows only, and any change sends you back to page 1. Sorting covers the whole filtered result.
코드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="page3">3페이지로</button>
<input type="text" aria-label="상품 검색" placeholder="예: 무선" id="query" />
<select aria-label="지역" id="region">
<option value="all" selected>전체</option>
<option value="r1">서울</option>
<option value="r2">부산</option>
<option value="r3">대구</option>
<option value="r4">제주</option>
</select>
</div>
<div id="grid" style="height: 520px"></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('page3').addEventListener('click', () => actions.page3(api));
document.getElementById('query').addEventListener('input', (event) => actions.query(api, event.target.value));
document.getElementById('region').addEventListener('change', (event) => actions.region(api, event.target.value));const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '무선 키보드', '스마트 워치', '노트북 거치대', '보조배터리'];
export const options = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
amount: 29000 + ((i * 7919) % 480000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// 검색 글자와 지역 선택을 모아 필터 하나(둘 다 만족)로 만들어요. 페이징은 걸러진 결과 전체를 기준으로 나눠요.
const state = { query: '', region: 'all' };
function apply(api) {
const items = [];
if (state.query)
items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api, log) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels = {
filter: ['필터가 바뀌어', 'Filter changed'],
sort: ['정렬이 바뀌어', 'Sort changed'],
user: ['이동', 'Moved'],
api: ['이동', 'Moved'],
size: ['개수 변경', 'Page size changed'],
};
const why = labels[reason] ?? ['이동', 'Moved'];
log({
ko: `${why[0]} ${page} / ${pageCount} 페이지 · 조건에 맞는 ${totalRows}건`,
en: `${why[1]}: page ${page} / ${pageCount} · ${totalRows} matching rows`,
});
});
return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const REGION_BY_KEY = { r1: '서울', r2: '부산', r3: '대구', r4: '제주' };
export const actions = {
query: (api, value) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api, value) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api) => api.setPage(3),
};<!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">
<button type="button" id="page3">3페이지로</button>
<input type="text" aria-label="상품 검색" placeholder="예: 무선" id="query" />
<select aria-label="지역" id="region">
<option value="all" selected>전체</option>
<option value="r1">서울</option>
<option value="r2">부산</option>
<option value="r3">대구</option>
<option value="r4">제주</option>
</select>
</div>
<div id="grid" style="height: 520px"></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 = ['무선 이어폰', '무선 키보드', '스마트 워치', '노트북 거치대', '보조배터리'];
const options = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
amount: 29000 + ((i * 7919) % 480000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// 검색 글자와 지역 선택을 모아 필터 하나(둘 다 만족)로 만들어요. 페이징은 걸러진 결과 전체를 기준으로 나눠요.
const state = { query: '', region: 'all' };
function apply(api) {
const items = [];
if (state.query)
items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
function setup(api, log) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels = {
filter: ['필터가 바뀌어', 'Filter changed'],
sort: ['정렬이 바뀌어', 'Sort changed'],
user: ['이동', 'Moved'],
api: ['이동', 'Moved'],
size: ['개수 변경', 'Page size changed'],
};
const why = labels[reason] ?? ['이동', 'Moved'];
log({
ko: `${why[0]} ${page} / ${pageCount} 페이지 · 조건에 맞는 ${totalRows}건`,
en: `${why[1]}: page ${page} / ${pageCount} · ${totalRows} matching rows`,
});
});
return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const REGION_BY_KEY = { r1: '서울', r2: '부산', r3: '대구', r4: '제주' };
const actions = {
query: (api, value) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api, value) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api) => api.setPage(3),
};
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('page3').addEventListener('click', () => actions.page3(api));
document.getElementById('query').addEventListener('input', (event) => actions.query(api, event.target.value));
document.getElementById('region').addEventListener('change', (event) => actions.region(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.page3(api)}
>3페이지로</button>
<input
type="text"
aria-label="상품 검색"
placeholder="예: 무선"
disabled={!api}
onChange={(event) => api && actions.query(api, event.target.value)}
/>
<select
aria-label="지역"
disabled={!api}
onChange={(event) => api && actions.region(api, event.target.value)}
>
<option value="all">전체</option>
<option value="r1">서울</option>
<option value="r2">부산</option>
<option value="r3">대구</option>
<option value="r4">제주</option>
</select>
</div>
<Grid style={{ height: 520 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '무선 키보드', '스마트 워치', '노트북 거치대', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29000 + ((i * 7919) % 480000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// 검색 글자와 지역 선택을 모아 필터 하나(둘 다 만족)로 만들어요. 페이징은 걸러진 결과 전체를 기준으로 나눠요.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, [string, string]> = {
filter: ['필터가 바뀌어', 'Filter changed'],
sort: ['정렬이 바뀌어', 'Sort changed'],
user: ['이동', 'Moved'],
api: ['이동', 'Moved'],
size: ['개수 변경', 'Page size changed'],
};
const why = labels[reason] ?? ['이동', 'Moved'];
log({
ko: `${why[0]} ${page} / ${pageCount} 페이지 · 조건에 맞는 ${totalRows}건`,
en: `${why[1]}: page ${page} / ${pageCount} · ${totalRows} matching rows`,
});
});
return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const REGION_BY_KEY: Record<string, string> = { r1: '서울', r2: '부산', r3: '대구', r4: '제주' };
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};버튼을 누르면 이 예제의 코드가 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.page3(api)">3페이지로</button>
<input
type="text"
aria-label="상품 검색"
placeholder="예: 무선"
:disabled="!api"
@input="api && actions.query(api, ($event.target as HTMLInputElement).value)"
/>
<select
aria-label="지역"
:disabled="!api"
@change="api && actions.region(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>전체</option>
<option value="r1">서울</option>
<option value="r2">부산</option>
<option value="r3">대구</option>
<option value="r4">제주</option>
</select>
</div>
<Grid style="height: 520px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '무선 키보드', '스마트 워치', '노트북 거치대', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29000 + ((i * 7919) % 480000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// 검색 글자와 지역 선택을 모아 필터 하나(둘 다 만족)로 만들어요. 페이징은 걸러진 결과 전체를 기준으로 나눠요.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, [string, string]> = {
filter: ['필터가 바뀌어', 'Filter changed'],
sort: ['정렬이 바뀌어', 'Sort changed'],
user: ['이동', 'Moved'],
api: ['이동', 'Moved'],
size: ['개수 변경', 'Page size changed'],
};
const why = labels[reason] ?? ['이동', 'Moved'];
log({
ko: `${why[0]} ${page} / ${pageCount} 페이지 · 조건에 맞는 ${totalRows}건`,
en: `${why[1]}: page ${page} / ${pageCount} · ${totalRows} matching rows`,
});
});
return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const REGION_BY_KEY: Record<string, string> = { r1: '서울', r2: '부산', r3: '대구', r4: '제주' };
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};버튼을 누르면 이 예제의 코드가 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.page3(api)"
>3페이지로</button>
<input
type="text"
aria-label="상품 검색"
placeholder="예: 무선"
[disabled]="!api"
(input)="api && actions.query(api, $any($event.target).value)"
/>
<select
aria-label="지역"
[disabled]="!api"
(change)="api && actions.region(api, $any($event.target).value)"
>
<option value="all" selected>전체</option>
<option value="r1">서울</option>
<option value="r2">부산</option>
<option value="r3">대구</option>
<option value="r4">제주</option>
</select>
</div>
<mx-grid style="height: 520px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '무선 키보드', '스마트 워치', '노트북 거치대', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 130 },
{ id: 'region', title: '지역', width: 90 },
{ id: 'product', title: '상품', width: 160 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29000 + ((i * 7919) % 480000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// 검색 글자와 지역 선택을 모아 필터 하나(둘 다 만족)로 만들어요. 페이징은 걸러진 결과 전체를 기준으로 나눠요.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, [string, string]> = {
filter: ['필터가 바뀌어', 'Filter changed'],
sort: ['정렬이 바뀌어', 'Sort changed'],
user: ['이동', 'Moved'],
api: ['이동', 'Moved'],
size: ['개수 변경', 'Page size changed'],
};
const why = labels[reason] ?? ['이동', 'Moved'];
log({
ko: `${why[0]} ${page} / ${pageCount} 페이지 · 조건에 맞는 ${totalRows}건`,
en: `${why[1]}: page ${page} / ${pageCount} · ${totalRows} matching rows`,
});
});
return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const REGION_BY_KEY: Record<string, string> = { r1: '서울', r2: '부산', r3: '대구', r4: '제주' };
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};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="page3">Go to page 3</button>
<input
type="text"
aria-label="Product search"
placeholder="e.g. Wireless"
id="query"
/>
<select aria-label="Region" id="region">
<option value="all" selected>All</option>
<option value="r1">New York</option>
<option value="r2">Boston</option>
<option value="r3">Austin</option>
<option value="r4">Seattle</option>
</select>
</div>
<div id="grid" style="height: 520px"></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('page3').addEventListener('click', () => actions.page3(api));
document.getElementById('query').addEventListener('input', (event) => actions.query(api, event.target.value));
document.getElementById('region').addEventListener('change', (event) => actions.region(api, event.target.value));const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless earbuds',
'Wireless keyboard',
'Smart watch',
'Laptop stand',
'Power bank',
];
export const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
amount: 29 + Math.round(((i * 7919) % 480000) / 1000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// Combine the search text and the region choice into one filter (both must match). Paging splits the whole filtered result.
const state = { query: '', region: 'all' };
function apply(api) {
const items = [];
if (state.query)
items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api, log) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels = {
filter: 'Filter changed',
sort: 'Sort changed',
user: 'Moved',
api: 'Moved',
size: 'Page size changed',
};
const why = labels[reason] ?? 'Moved';
log(`${why}: page ${page} / ${pageCount} · ${totalRows} matching rows`);
});
return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const REGION_BY_KEY = {
r1: 'New York',
r2: 'Boston',
r3: 'Austin',
r4: 'Seattle',
};
export const actions = {
query: (api, value) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api, value) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api) => api.setPage(3),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Search and filter, and the pages adjust themselves</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="page3">Go to page 3</button>
<input
type="text"
aria-label="Product search"
placeholder="e.g. Wireless"
id="query"
/>
<select aria-label="Region" id="region">
<option value="all" selected>All</option>
<option value="r1">New York</option>
<option value="r2">Boston</option>
<option value="r3">Austin</option>
<option value="r4">Seattle</option>
</select>
</div>
<div id="grid" style="height: 520px"></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',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless earbuds',
'Wireless keyboard',
'Smart watch',
'Laptop stand',
'Power bank',
];
const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 150 },
{ id: 'region', title: 'Region', width: 100 },
{ id: 'product', title: 'Product', width: 170 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6],
region: regions[(i * 3) % 4],
product: products[(i * 7) % 5],
amount: 29 + Math.round(((i * 7919) % 480000) / 1000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// Combine the search text and the region choice into one filter (both must match). Paging splits the whole filtered result.
const state = { query: '', region: 'all' };
function apply(api) {
const items = [];
if (state.query)
items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
function setup(api, log) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels = {
filter: 'Filter changed',
sort: 'Sort changed',
user: 'Moved',
api: 'Moved',
size: 'Page size changed',
};
const why = labels[reason] ?? 'Moved';
log(`${why}: page ${page} / ${pageCount} · ${totalRows} matching rows`);
});
return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const REGION_BY_KEY = {
r1: 'New York',
r2: 'Boston',
r3: 'Austin',
r4: 'Seattle',
};
const actions = {
query: (api, value) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api, value) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api) => api.setPage(3),
};
options.ariaLabel = "Search and filter, and the pages adjust themselves";
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('page3').addEventListener('click', () => actions.page3(api));
document.getElementById('query').addEventListener('input', (event) => actions.query(api, event.target.value));
document.getElementById('region').addEventListener('change', (event) => actions.region(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.page3(api)}
>Go to page 3</button>
<input
type="text"
aria-label="Product search"
placeholder="e.g. Wireless"
disabled={!api}
onChange={(event) => api && actions.query(api, event.target.value)}
/>
<select
aria-label="Region"
disabled={!api}
onChange={(event) => api && actions.region(api, event.target.value)}
>
<option value="all">All</option>
<option value="r1">New York</option>
<option value="r2">Boston</option>
<option value="r3">Austin</option>
<option value="r4">Seattle</option>
</select>
</div>
<Grid style={{ height: 520 }} ref={gridRef} options={options} />
</>
);
}import type { FilterItem, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless earbuds',
'Wireless keyboard',
'Smart watch',
'Laptop stand',
'Power bank',
];
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: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29 + Math.round(((i * 7919) % 480000) / 1000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// Combine the search text and the region choice into one filter (both must match). Paging splits the whole filtered result.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, string> = {
filter: 'Filter changed',
sort: 'Sort changed',
user: 'Moved',
api: 'Moved',
size: 'Page size changed',
};
const why = labels[reason] ?? 'Moved';
log(`${why}: page ${page} / ${pageCount} · ${totalRows} matching rows`);
});
return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const REGION_BY_KEY: Record<string, string> = {
r1: 'New York',
r2: 'Boston',
r3: 'Austin',
r4: 'Seattle',
};
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};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.page3(api)">Go to page 3</button>
<input
type="text"
aria-label="Product search"
placeholder="e.g. Wireless"
:disabled="!api"
@input="api && actions.query(api, ($event.target as HTMLInputElement).value)"
/>
<select
aria-label="Region"
:disabled="!api"
@change="api && actions.region(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>All</option>
<option value="r1">New York</option>
<option value="r2">Boston</option>
<option value="r3">Austin</option>
<option value="r4">Seattle</option>
</select>
</div>
<Grid style="height: 520px" :options="options" @ready="onReady" />
</template>import type { FilterItem, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless earbuds',
'Wireless keyboard',
'Smart watch',
'Laptop stand',
'Power bank',
];
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: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29 + Math.round(((i * 7919) % 480000) / 1000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// Combine the search text and the region choice into one filter (both must match). Paging splits the whole filtered result.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, string> = {
filter: 'Filter changed',
sort: 'Sort changed',
user: 'Moved',
api: 'Moved',
size: 'Page size changed',
};
const why = labels[reason] ?? 'Moved';
log(`${why}: page ${page} / ${pageCount} · ${totalRows} matching rows`);
});
return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const REGION_BY_KEY: Record<string, string> = {
r1: 'New York',
r2: 'Boston',
r3: 'Austin',
r4: 'Seattle',
};
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};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.page3(api)"
>Go to page 3</button>
<input
type="text"
aria-label="Product search"
placeholder="e.g. Wireless"
[disabled]="!api"
(input)="api && actions.query(api, $any($event.target).value)"
/>
<select
aria-label="Region"
[disabled]="!api"
(change)="api && actions.region(api, $any($event.target).value)"
>
<option value="all" selected>All</option>
<option value="r1">New York</option>
<option value="r2">Boston</option>
<option value="r3">Austin</option>
<option value="r4">Seattle</option>
</select>
</div>
<mx-grid style="height: 520px" [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 { FilterItem, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
customer: string;
region: string;
product: string;
amount: number;
}
const customers = [
'Harbor Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Commerce',
'Sunrise Farm',
'Moda Fashion',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
'Wireless earbuds',
'Wireless keyboard',
'Smart watch',
'Laptop stand',
'Power bank',
];
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: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: Array.from({ length: 120 }, (_, i) => ({
id: i + 1,
customer: customers[i % 6] as string,
region: regions[(i * 3) % 4] as string,
product: products[(i * 7) % 5] as string,
amount: 29 + Math.round(((i * 7919) % 480000) / 1000),
})),
rowKey: 'id',
showRowNumbers: true,
pagination: { mode: 'client', pageSize: 10 },
};
// Combine the search text and the region choice into one filter (both must match). Paging splits the whole filtered result.
const state = { query: '', region: 'all' };
function apply(api: GridApi<Row>): void {
const items: FilterItem[] = [];
if (state.query) items.push({ columnId: 'product', operator: 'contains', value: state.query });
if (state.region !== 'all')
items.push({ columnId: 'region', operator: 'equals', value: state.region });
api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
state.query = '';
state.region = 'all';
const off = api.on('pageChanged', ({ page, pageCount, totalRows, reason }) => {
const labels: Record<string, string> = {
filter: 'Filter changed',
sort: 'Sort changed',
user: 'Moved',
api: 'Moved',
size: 'Page size changed',
};
const why = labels[reason] ?? 'Moved';
log(`${why}: page ${page} / ${pageCount} · ${totalRows} matching rows`);
});
return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const REGION_BY_KEY: Record<string, string> = {
r1: 'New York',
r2: 'Boston',
r3: 'Austin',
r4: 'Seattle',
};
export const actions = {
query: (api: GridApi<Row>, value?: string) => {
state.query = (value ?? '').trim();
apply(api);
},
region: (api: GridApi<Row>, value?: string) => {
state.region = value && value !== 'all' ? (REGION_BY_KEY[value] ?? 'all') : 'all';
apply(api);
},
page3: (api: GridApi<Row>) => api.setPage(3),
};