같은 저장소, 서로 다른 필터One store, different filters
두 그리드가 같은 행을 보지만 필터는 따로예요. 값이 바뀌면 각 그리드의 필터가 다시 판정해요.Two grids see the same rows but keep their own filters. When a value changes, each grid's filter judges the row again.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: 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="moveTeam">개발로 옮기기</button>
<button type="button" id="raise">수량 올리기</button>
<button type="button" id="lower">수량 내리기</button>
</div>
<div id="grid" style="height: 200px"></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('moveTeam').addEventListener('click', () => actions.moveTeam(api));
document.getElementById('raise').addEventListener('click', () => actions.raise(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(api));const store = MaxGrid.createRowsStore([
{ id: 1, name: '김하늘', team: '개발', qty: 4 },
{ id: 2, name: '이도윤', team: '운영', qty: 9 },
{ id: 3, name: '박서연', team: '디자인', qty: 2 },
{ id: 4, name: '최지우', team: '개발', qty: 12 },
{ id: 5, name: '정민준', team: '운영', qty: 6 },
], { rowKey: 'id' });
// 같은 저장소를 보는 두 그리드가 서로 다른 필터를 가져요. 왼쪽 위는 개발 팀만, 아래는 수량이 5 이상인 행만 보여요.
// 한쪽에서 행을 고치면 다른 쪽의 필터가 그 행을 다시 판정해서 나타나거나 사라져요.
const columns = () => [
{ id: 'name', title: '이름', editable: true, width: 120 },
{ id: 'team', title: '팀', editable: true, width: 90 },
{ id: 'qty', title: '수량', kind: 'number', editable: true, width: 80 },
];
export const options = {
density: 'normal', // 틀이 높이를 키우지 않게 고정(두 그리드 높이를 직접 정한다)
columns: columns(),
rowsStore: store,
ariaLabel: '개발 팀',
};
let second = null;
let host = null;
export function setup(api, log) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: '개발' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'ko',
columns: columns(),
rowsStore: store,
ariaLabel: '수량 5 이상',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log({
ko: '위는 팀이 개발인 행, 아래는 수량 5 이상인 행만 보여요. 버튼으로 값을 바꿔 두 필터가 다시 판정하는 걸 보세요.',
en: 'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
});
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api) => {
const row = api.getRows().find((r) => r.team !== '개발');
if (row)
api.setCellValue(row.id, 'team', '개발');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low)
store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high)
store.updateRow(high.id, { qty: 1 });
},
};<!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="moveTeam">개발로 옮기기</button>
<button type="button" id="raise">수량 올리기</button>
<button type="button" id="lower">수량 내리기</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const store = MaxGrid.createRowsStore([
{ id: 1, name: '김하늘', team: '개발', qty: 4 },
{ id: 2, name: '이도윤', team: '운영', qty: 9 },
{ id: 3, name: '박서연', team: '디자인', qty: 2 },
{ id: 4, name: '최지우', team: '개발', qty: 12 },
{ id: 5, name: '정민준', team: '운영', qty: 6 },
], { rowKey: 'id' });
// 같은 저장소를 보는 두 그리드가 서로 다른 필터를 가져요. 왼쪽 위는 개발 팀만, 아래는 수량이 5 이상인 행만 보여요.
// 한쪽에서 행을 고치면 다른 쪽의 필터가 그 행을 다시 판정해서 나타나거나 사라져요.
const columns = () => [
{ id: 'name', title: '이름', editable: true, width: 120 },
{ id: 'team', title: '팀', editable: true, width: 90 },
{ id: 'qty', title: '수량', kind: 'number', editable: true, width: 80 },
];
const options = {
density: 'normal', // 틀이 높이를 키우지 않게 고정(두 그리드 높이를 직접 정한다)
columns: columns(),
rowsStore: store,
ariaLabel: '개발 팀',
};
let second = null;
let host = null;
function setup(api, log) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: '개발' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'ko',
columns: columns(),
rowsStore: store,
ariaLabel: '수량 5 이상',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log({
ko: '위는 팀이 개발인 행, 아래는 수량 5 이상인 행만 보여요. 버튼으로 값을 바꿔 두 필터가 다시 판정하는 걸 보세요.',
en: 'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
});
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
const actions = {
moveTeam: (api) => {
const row = api.getRows().find((r) => r.team !== '개발');
if (row)
api.setCellValue(row.id, 'team', '개발');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low)
store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high)
store.updateRow(high.id, { qty: 1 });
},
};
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('moveTeam').addEventListener('click', () => actions.moveTeam(api));
document.getElementById('raise').addEventListener('click', () => actions.raise(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(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.moveTeam(api)}
>개발로 옮기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.raise(api)}
>수량 올리기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lower(api)}
>수량 내리기</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions, RowsStore } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: '김하늘', team: '개발', qty: 4 },
{ id: 2, name: '이도윤', team: '운영', qty: 9 },
{ id: 3, name: '박서연', team: '디자인', qty: 2 },
{ id: 4, name: '최지우', team: '개발', qty: 12 },
{ id: 5, name: '정민준', team: '운영', qty: 6 },
],
{ rowKey: 'id' },
);
// 같은 저장소를 보는 두 그리드가 서로 다른 필터를 가져요. 왼쪽 위는 개발 팀만, 아래는 수량이 5 이상인 행만 보여요.
// 한쪽에서 행을 고치면 다른 쪽의 필터가 그 행을 다시 판정해서 나타나거나 사라져요.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: '이름', editable: true, width: 120 },
{ id: 'team', title: '팀', editable: true, width: 90 },
{ id: 'qty', title: '수량', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // 틀이 높이를 키우지 않게 고정(두 그리드 높이를 직접 정한다)
columns: columns(),
rowsStore: store,
ariaLabel: '개발 팀',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: '개발' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'ko',
columns: columns(),
rowsStore: store,
ariaLabel: '수량 5 이상',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log({
ko: '위는 팀이 개발인 행, 아래는 수량 5 이상인 행만 보여요. 버튼으로 값을 바꿔 두 필터가 다시 판정하는 걸 보세요.',
en: 'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
});
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== '개발');
if (row) api.setCellValue(row.id, 'team', '개발');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 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.moveTeam(api)"
>개발로 옮기기</button>
<button type="button" :disabled="!api" @click="api && actions.raise(api)">수량 올리기</button>
<button type="button" :disabled="!api" @click="api && actions.lower(api)">수량 내리기</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions, RowsStore } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: '김하늘', team: '개발', qty: 4 },
{ id: 2, name: '이도윤', team: '운영', qty: 9 },
{ id: 3, name: '박서연', team: '디자인', qty: 2 },
{ id: 4, name: '최지우', team: '개발', qty: 12 },
{ id: 5, name: '정민준', team: '운영', qty: 6 },
],
{ rowKey: 'id' },
);
// 같은 저장소를 보는 두 그리드가 서로 다른 필터를 가져요. 왼쪽 위는 개발 팀만, 아래는 수량이 5 이상인 행만 보여요.
// 한쪽에서 행을 고치면 다른 쪽의 필터가 그 행을 다시 판정해서 나타나거나 사라져요.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: '이름', editable: true, width: 120 },
{ id: 'team', title: '팀', editable: true, width: 90 },
{ id: 'qty', title: '수량', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // 틀이 높이를 키우지 않게 고정(두 그리드 높이를 직접 정한다)
columns: columns(),
rowsStore: store,
ariaLabel: '개발 팀',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: '개발' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'ko',
columns: columns(),
rowsStore: store,
ariaLabel: '수량 5 이상',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log({
ko: '위는 팀이 개발인 행, 아래는 수량 5 이상인 행만 보여요. 버튼으로 값을 바꿔 두 필터가 다시 판정하는 걸 보세요.',
en: 'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
});
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== '개발');
if (row) api.setCellValue(row.id, 'team', '개발');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 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.moveTeam(api)"
>개발로 옮기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.raise(api)"
>수량 올리기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lower(api)"
>수량 내리기</button>
</div>
<mx-grid style="height: 200px" [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, RowsStore } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: '김하늘', team: '개발', qty: 4 },
{ id: 2, name: '이도윤', team: '운영', qty: 9 },
{ id: 3, name: '박서연', team: '디자인', qty: 2 },
{ id: 4, name: '최지우', team: '개발', qty: 12 },
{ id: 5, name: '정민준', team: '운영', qty: 6 },
],
{ rowKey: 'id' },
);
// 같은 저장소를 보는 두 그리드가 서로 다른 필터를 가져요. 왼쪽 위는 개발 팀만, 아래는 수량이 5 이상인 행만 보여요.
// 한쪽에서 행을 고치면 다른 쪽의 필터가 그 행을 다시 판정해서 나타나거나 사라져요.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: '이름', editable: true, width: 120 },
{ id: 'team', title: '팀', editable: true, width: 90 },
{ id: 'qty', title: '수량', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // 틀이 높이를 키우지 않게 고정(두 그리드 높이를 직접 정한다)
columns: columns(),
rowsStore: store,
ariaLabel: '개발 팀',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: '개발' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'ko',
columns: columns(),
rowsStore: store,
ariaLabel: '수량 5 이상',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log({
ko: '위는 팀이 개발인 행, 아래는 수량 5 이상인 행만 보여요. 버튼으로 값을 바꿔 두 필터가 다시 판정하는 걸 보세요.',
en: 'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
});
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== '개발');
if (row) api.setCellValue(row.id, 'team', '개발');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 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="moveTeam">Move to Dev</button>
<button type="button" id="raise">Raise qty</button>
<button type="button" id="lower">Lower qty</button>
</div>
<div id="grid" style="height: 200px"></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('moveTeam').addEventListener('click', () => actions.moveTeam(api));
document.getElementById('raise').addEventListener('click', () => actions.raise(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(api));const store = MaxGrid.createRowsStore([
{ id: 1, name: 'Liam Carter', team: 'Dev', qty: 4 },
{ id: 2, name: 'Emma Stone', team: 'Ops', qty: 9 },
{ id: 3, name: 'Noah Reed', team: 'Design', qty: 2 },
{ id: 4, name: 'Ava Brooks', team: 'Dev', qty: 12 },
{ id: 5, name: 'Mia Lopez', team: 'Ops', qty: 6 },
], { rowKey: 'id' });
// Two grids on one store keep different filters. The top one shows only the Dev team, the bottom one only rows with quantity 5 or more.
// When a row changes in one grid, the other grid's filter judges it again and the row appears or disappears.
const columns = () => [
{ id: 'name', title: 'Name', editable: true, width: 120 },
{ id: 'team', title: 'Team', editable: true, width: 90 },
{ id: 'qty', title: 'Qty', kind: 'number', editable: true, width: 80 },
];
export const options = {
density: 'normal', // keeps the frame from scaling heights (both grid heights are set here)
columns: columns(),
rowsStore: store,
ariaLabel: 'Dev team',
};
let second = null;
let host = null;
export function setup(api, log) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: 'Dev' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'en',
columns: columns(),
rowsStore: store,
ariaLabel: 'Quantity 5 or more',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log('The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.');
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api) => {
const row = api.getRows().find((r) => r.team !== 'Dev');
if (row)
api.setCellValue(row.id, 'team', 'Dev');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low)
store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high)
store.updateRow(high.id, { qty: 1 });
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One store, different filters</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="moveTeam">Move to Dev</button>
<button type="button" id="raise">Raise qty</button>
<button type="button" id="lower">Lower qty</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const store = MaxGrid.createRowsStore([
{ id: 1, name: 'Liam Carter', team: 'Dev', qty: 4 },
{ id: 2, name: 'Emma Stone', team: 'Ops', qty: 9 },
{ id: 3, name: 'Noah Reed', team: 'Design', qty: 2 },
{ id: 4, name: 'Ava Brooks', team: 'Dev', qty: 12 },
{ id: 5, name: 'Mia Lopez', team: 'Ops', qty: 6 },
], { rowKey: 'id' });
// Two grids on one store keep different filters. The top one shows only the Dev team, the bottom one only rows with quantity 5 or more.
// When a row changes in one grid, the other grid's filter judges it again and the row appears or disappears.
const columns = () => [
{ id: 'name', title: 'Name', editable: true, width: 120 },
{ id: 'team', title: 'Team', editable: true, width: 90 },
{ id: 'qty', title: 'Qty', kind: 'number', editable: true, width: 80 },
];
const options = {
density: 'normal', // keeps the frame from scaling heights (both grid heights are set here)
columns: columns(),
rowsStore: store,
ariaLabel: 'Dev team',
};
let second = null;
let host = null;
function setup(api, log) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: 'Dev' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null)
first.after(host);
else
document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'en',
columns: columns(),
rowsStore: store,
ariaLabel: 'Quantity 5 or more',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log('The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.');
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
const actions = {
moveTeam: (api) => {
const row = api.getRows().find((r) => r.team !== 'Dev');
if (row)
api.setCellValue(row.id, 'team', 'Dev');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low)
store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high)
store.updateRow(high.id, { qty: 1 });
},
};
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('moveTeam').addEventListener('click', () => actions.moveTeam(api));
document.getElementById('raise').addEventListener('click', () => actions.raise(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(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.moveTeam(api)}
>Move to Dev</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.raise(api)}
>Raise qty</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lower(api)}
>Lower qty</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions, RowsStore } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: 'Liam Carter', team: 'Dev', qty: 4 },
{ id: 2, name: 'Emma Stone', team: 'Ops', qty: 9 },
{ id: 3, name: 'Noah Reed', team: 'Design', qty: 2 },
{ id: 4, name: 'Ava Brooks', team: 'Dev', qty: 12 },
{ id: 5, name: 'Mia Lopez', team: 'Ops', qty: 6 },
],
{ rowKey: 'id' },
);
// Two grids on one store keep different filters. The top one shows only the Dev team, the bottom one only rows with quantity 5 or more.
// When a row changes in one grid, the other grid's filter judges it again and the row appears or disappears.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: 'Name', editable: true, width: 120 },
{ id: 'team', title: 'Team', editable: true, width: 90 },
{ id: 'qty', title: 'Qty', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // keeps the frame from scaling heights (both grid heights are set here)
columns: columns(),
rowsStore: store,
ariaLabel: 'Dev team',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: 'Dev' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'en',
columns: columns(),
rowsStore: store,
ariaLabel: 'Quantity 5 or more',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log(
'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
);
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== 'Dev');
if (row) api.setCellValue(row.id, 'team', 'Dev');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 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.moveTeam(api)"
>Move to Dev</button>
<button type="button" :disabled="!api" @click="api && actions.raise(api)">Raise qty</button>
<button type="button" :disabled="!api" @click="api && actions.lower(api)">Lower qty</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions, RowsStore } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: 'Liam Carter', team: 'Dev', qty: 4 },
{ id: 2, name: 'Emma Stone', team: 'Ops', qty: 9 },
{ id: 3, name: 'Noah Reed', team: 'Design', qty: 2 },
{ id: 4, name: 'Ava Brooks', team: 'Dev', qty: 12 },
{ id: 5, name: 'Mia Lopez', team: 'Ops', qty: 6 },
],
{ rowKey: 'id' },
);
// Two grids on one store keep different filters. The top one shows only the Dev team, the bottom one only rows with quantity 5 or more.
// When a row changes in one grid, the other grid's filter judges it again and the row appears or disappears.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: 'Name', editable: true, width: 120 },
{ id: 'team', title: 'Team', editable: true, width: 90 },
{ id: 'qty', title: 'Qty', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // keeps the frame from scaling heights (both grid heights are set here)
columns: columns(),
rowsStore: store,
ariaLabel: 'Dev team',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: 'Dev' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'en',
columns: columns(),
rowsStore: store,
ariaLabel: 'Quantity 5 or more',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log(
'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
);
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== 'Dev');
if (row) api.setCellValue(row.id, 'team', 'Dev');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 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.moveTeam(api)"
>Move to Dev</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.raise(api)"
>Raise qty</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lower(api)"
>Lower qty</button>
</div>
<mx-grid style="height: 200px" [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, RowsStore } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
qty: number;
}
declare const MaxGrid: {
createGrid(container: HTMLElement, options: GridOptions<Row>): GridApi<Row>;
createRowsStore(rows: Row[], options: { rowKey: 'id' }): RowsStore<Row>;
};
const store = MaxGrid.createRowsStore(
[
{ id: 1, name: 'Liam Carter', team: 'Dev', qty: 4 },
{ id: 2, name: 'Emma Stone', team: 'Ops', qty: 9 },
{ id: 3, name: 'Noah Reed', team: 'Design', qty: 2 },
{ id: 4, name: 'Ava Brooks', team: 'Dev', qty: 12 },
{ id: 5, name: 'Mia Lopez', team: 'Ops', qty: 6 },
],
{ rowKey: 'id' },
);
// Two grids on one store keep different filters. The top one shows only the Dev team, the bottom one only rows with quantity 5 or more.
// When a row changes in one grid, the other grid's filter judges it again and the row appears or disappears.
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'name', title: 'Name', editable: true, width: 120 },
{ id: 'team', title: 'Team', editable: true, width: 90 },
{ id: 'qty', title: 'Qty', kind: 'number', editable: true, width: 80 },
];
export const options: GridOptions<Row> = {
density: 'normal', // keeps the frame from scaling heights (both grid heights are set here)
columns: columns(),
rowsStore: store,
ariaLabel: 'Dev team',
};
let second: GridApi<Row> | null = null;
let host: HTMLElement | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
api.setFilterModel({
match: 'all',
items: [{ columnId: 'team', operator: 'equals', value: 'Dev' }],
});
const first = document.getElementById('grid');
host = document.createElement('div');
host.style.cssText = 'height:260px;margin-top:10px';
if (first !== null) first.after(host);
else document.body.append(host);
second = MaxGrid.createGrid(host, {
locale: 'en',
columns: columns(),
rowsStore: store,
ariaLabel: 'Quantity 5 or more',
});
second.setFilterModel({ match: 'all', items: [{ columnId: 'qty', operator: 'gte', value: 5 }] });
log(
'The top grid shows the Dev team, the bottom grid shows quantity 5 or more. Use the buttons to change values and watch both filters re-evaluate.',
);
return () => {
second?.destroy();
host?.remove();
second = host = null;
};
}
export const actions = {
moveTeam: (api: GridApi<Row>) => {
const row = api.getRows().find((r) => r.team !== 'Dev');
if (row) api.setCellValue(row.id, 'team', 'Dev');
},
raise: () => {
const low = store.getRows().find((r) => r.qty < 5);
if (low) store.updateRow(low.id, { qty: 20 });
},
lower: () => {
const high = store.getRows().find((r) => r.qty >= 5);
if (high) store.updateRow(high.id, { qty: 1 });
},
};