필터 없이 행 숨기기Hide rows without a filter
hideRows(keys)는 고른 행을 보기에서 빼고 showRows()로 되돌려요. 필터와 따로 움직여서 필터를 걸고 풀어도 숨김은 그대로예요. 숨긴 행은 getRows()에 남고 변경으로 세지 않아요.hideRows(keys) takes chosen rows out of the view and showRows() brings them back. It moves independently of the filter, so setting or clearing a filter does not change what is hidden. Hidden rows stay in getRows() and are not counted as changes.
코드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="hideSelected">고른 줄 숨기기</button>
<button type="button" id="showAll">모두 보이기</button>
<button type="button" id="filter">70점 초과만</button>
<button type="button" id="clearFilter">필터 풀기</button>
</div>
<div id="grid" style="height: 420px"></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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(api));const en = document.documentElement.dataset.lang === 'en';
const names = en
? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
: [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'한지우',
'오세훈',
'윤아름',
'강태양',
'서하늘',
];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
export const options = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
{ id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
{ id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
// 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
const off = api.on('rowsHiddenChanged', (e) => say({
ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
}));
return off;
}
export const actions = {
// 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
hideSelected: (api) => {
const keys = api.getSelectedKeys();
if (keys.length === 0)
return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
api.hideRows([...keys]);
},
showAll: (api) => api.showRows(),
filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api) => api.setFilterModel(null),
};<!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="hideSelected">고른 줄 숨기기</button>
<button type="button" id="showAll">모두 보이기</button>
<button type="button" id="filter">70점 초과만</button>
<button type="button" id="clearFilter">필터 풀기</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const en = document.documentElement.dataset.lang === 'en';
const names = en
? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
: [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'한지우',
'오세훈',
'윤아름',
'강태양',
'서하늘',
];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
const options = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
{ id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
{ id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
function setup(api, log) {
say = log;
// 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
const off = api.on('rowsHiddenChanged', (e) => say({
ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
}));
return off;
}
const actions = {
// 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
hideSelected: (api) => {
const keys = api.getSelectedKeys();
if (keys.length === 0)
return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
api.hideRows([...keys]);
},
showAll: (api) => api.showRows(),
filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api) => api.setFilterModel(null),
};
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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(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.hideSelected(api)}
>고른 줄 숨기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.showAll(api)}
>모두 보이기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filter(api)}
>70점 초과만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clearFilter(api)}
>필터 풀기</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
score: number;
}
const en = document.documentElement.dataset.lang === 'en';
const names = en
? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
: [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'한지우',
'오세훈',
'윤아름',
'강태양',
'서하늘',
];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
{ id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
{ id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
const off = api.on('rowsHiddenChanged', (e) =>
say({
ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
}),
);
return off;
}
export const actions = {
// 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 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.hideSelected(api)"
>고른 줄 숨기기</button>
<button type="button" :disabled="!api" @click="api && actions.showAll(api)">모두 보이기</button>
<button type="button" :disabled="!api" @click="api && actions.filter(api)">70점 초과만</button>
<button
type="button"
:disabled="!api"
@click="api && actions.clearFilter(api)"
>필터 풀기</button>
</div>
<Grid style="height: 420px" :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;
name: string;
team: string;
score: number;
}
const en = document.documentElement.dataset.lang === 'en';
const names = en
? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
: [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'한지우',
'오세훈',
'윤아름',
'강태양',
'서하늘',
];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
{ id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
{ id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
const off = api.on('rowsHiddenChanged', (e) =>
say({
ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
}),
);
return off;
}
export const actions = {
// 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 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.hideSelected(api)"
>고른 줄 숨기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.showAll(api)"
>모두 보이기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filter(api)"
>70점 초과만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clearFilter(api)"
>필터 풀기</button>
</div>
<mx-grid style="height: 420px" [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;
name: string;
team: string;
score: number;
}
const en = document.documentElement.dataset.lang === 'en';
const names = en
? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
: [
'김서연',
'이준호',
'박민지',
'최도윤',
'정하은',
'한지우',
'오세훈',
'윤아름',
'강태양',
'서하늘',
];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
{ id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
{ id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
const off = api.on('rowsHiddenChanged', (e) =>
say({
ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
}),
);
return off;
}
export const actions = {
// 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};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="hideSelected">Hide selected</button>
<button type="button" id="showAll">Show all</button>
<button type="button" id="filter">Score above 70</button>
<button type="button" id="clearFilter">Clear filter</button>
</div>
<div id="grid" style="height: 420px"></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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(api));const names = [
'Alex',
'Blair',
'Casey',
'Drew',
'Emery',
'Finn',
'Gray',
'Harper',
'Indy',
'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 120, sortable: true },
{ id: 'team', title: 'Team', width: 100, sortable: true },
{ id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
// Each time rows are hidden or shown, the keys that actually changed arrive at once.
const off = api.on('rowsHiddenChanged', (e) => say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`));
return off;
}
export const actions = {
// Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
hideSelected: (api) => {
const keys = api.getSelectedKeys();
if (keys.length === 0)
return say('Select rows first');
api.hideRows([...keys]);
},
showAll: (api) => api.showRows(),
filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api) => api.setFilterModel(null),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hide rows without a filter</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="hideSelected">Hide selected</button>
<button type="button" id="showAll">Show all</button>
<button type="button" id="filter">Score above 70</button>
<button type="button" id="clearFilter">Clear filter</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Alex',
'Blair',
'Casey',
'Drew',
'Emery',
'Finn',
'Gray',
'Harper',
'Indy',
'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
const options = {
columns: [
{ id: 'name', title: 'Name', width: 120, sortable: true },
{ id: 'team', title: 'Team', width: 100, sortable: true },
{ id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3],
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
function setup(api, log) {
say = log;
// Each time rows are hidden or shown, the keys that actually changed arrive at once.
const off = api.on('rowsHiddenChanged', (e) => say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`));
return off;
}
const actions = {
// Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
hideSelected: (api) => {
const keys = api.getSelectedKeys();
if (keys.length === 0)
return say('Select rows first');
api.hideRows([...keys]);
},
showAll: (api) => api.showRows(),
filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api) => api.setFilterModel(null),
};
options.ariaLabel = "Hide rows without a filter";
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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(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.hideSelected(api)}
>Hide selected</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.showAll(api)}
>Show all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filter(api)}
>Score above 70</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clearFilter(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
score: number;
}
const names = [
'Alex',
'Blair',
'Casey',
'Drew',
'Emery',
'Finn',
'Gray',
'Harper',
'Indy',
'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120, sortable: true },
{ id: 'team', title: 'Team', width: 100, sortable: true },
{ id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// Each time rows are hidden or shown, the keys that actually changed arrive at once.
const off = api.on('rowsHiddenChanged', (e) =>
say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`),
);
return off;
}
export const actions = {
// Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say('Select rows first');
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};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.hideSelected(api)"
>Hide selected</button>
<button type="button" :disabled="!api" @click="api && actions.showAll(api)">Show all</button>
<button type="button" :disabled="!api" @click="api && actions.filter(api)">Score above 70</button>
<button
type="button"
:disabled="!api"
@click="api && actions.clearFilter(api)"
>Clear filter</button>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
score: number;
}
const names = [
'Alex',
'Blair',
'Casey',
'Drew',
'Emery',
'Finn',
'Gray',
'Harper',
'Indy',
'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120, sortable: true },
{ id: 'team', title: 'Team', width: 100, sortable: true },
{ id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// Each time rows are hidden or shown, the keys that actually changed arrive at once.
const off = api.on('rowsHiddenChanged', (e) =>
say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`),
);
return off;
}
export const actions = {
// Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say('Select rows first');
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};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.hideSelected(api)"
>Hide selected</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.showAll(api)"
>Show all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filter(api)"
>Score above 70</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clearFilter(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 420px" [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;
name: string;
team: string;
score: number;
}
const names = [
'Alex',
'Blair',
'Casey',
'Drew',
'Emery',
'Finn',
'Gray',
'Harper',
'Indy',
'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120, sortable: true },
{ id: 'team', title: 'Team', width: 100, sortable: true },
{ id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
team: teams[i % 3] as string,
score: 50 + ((i * 9) % 50),
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
// Each time rows are hidden or shown, the keys that actually changed arrive at once.
const off = api.on('rowsHiddenChanged', (e) =>
say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`),
);
return off;
}
export const actions = {
// Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
hideSelected: (api: GridApi<Row>) => {
const keys = api.getSelectedKeys();
if (keys.length === 0) return say('Select rows first');
api.hideRows([...keys]);
},
showAll: (api: GridApi<Row>) => api.showRows(),
filter: (api: GridApi<Row>) =>
api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
clearFilter: (api: GridApi<Row>) => api.setFilterModel(null),
};