헤더 아래 입력 칸에 치면 바로 걸러져요Type in the cells under the header to filter live
헤더 바로 아래에 컬럼마다 입력 칸이 생겨서, 글자를 치는 즉시 목록이 줄어들어요. 이름은 글자, 팀은 값 목록, 연봉은 범위(5000..6000), 입사일은 날짜 식, 재택은 예/아니오 선택이에요.A row of inputs under the header filters as you type: text for names, a value list for teams, ranges such as 50000..60000 for salary, date expressions for hire dates and yes/no for remote.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="필터 칸" id="row">
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
<button type="button" id="fill">코드로 걸기: 개발팀·연봉 5000 이상</button>
</div>
<div id="grid" style="height: 540px"></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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
export const options = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: '이름',
width: 120,
filter: { placeholder: L('이름 일부', 'part of the name') },
},
{ id: 'team', title: '팀', kind: 'select', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 150,
filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
team: teams[(i * 3) % 4],
salary: 3800 + ((i * 530) % 4200),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log({
ko: !filterModel || filterModel.items.length === 0
? '필터 없음'
: `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
en: !filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
export const actions = {
// 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
row: (api, value) => {
if (value === 'off')
api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// 코드로 걸면 칸에도 그대로 채워져요.
fill: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['개발팀'] },
{ columnId: 'salary', operator: 'gte', value: 5000 },
],
}),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>헤더 아래 입력 칸에 치면 바로 걸러져요</title>
</head>
<body>
<div class="toolbar">
<select aria-label="필터 칸" id="row">
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
<button type="button" id="fill">코드로 걸기: 개발팀·연봉 5000 이상</button>
</div>
<div id="grid" style="height: 540px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
const options = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: '이름',
width: 120,
filter: { placeholder: L('이름 일부', 'part of the name') },
},
{ id: 'team', title: '팀', kind: 'select', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 150,
filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
team: teams[(i * 3) % 4],
salary: 3800 + ((i * 530) % 4200),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log({
ko: !filterModel || filterModel.items.length === 0
? '필터 없음'
: `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
en: !filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
}));
return () => off();
}
const actions = {
// 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
row: (api, value) => {
if (value === 'off')
api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// 코드로 걸면 칸에도 그대로 채워져요.
fill: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['개발팀'] },
{ columnId: 'salary', operator: 'gte', value: 5000 },
],
}),
};
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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(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">
<select
aria-label="필터 칸"
disabled={!api}
onChange={(event) => api && actions.row(api, event.target.value)}
>
<option value="on">보이기</option>
<option value="off">숨기기</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>코드로 걸기: 개발팀·연봉 5000 이상</button>
</div>
<Grid style={{ height: 540 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: '이름',
width: 120,
filter: { placeholder: L('이름 일부', 'part of the name') },
},
{ id: 'team', title: '팀', kind: 'select', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 150,
filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 530) % 4200),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
!filterModel || filterModel.items.length === 0
? '필터 없음'
: `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// 코드로 걸면 칸에도 그대로 채워져요.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['개발팀'] },
{ columnId: 'salary', operator: 'gte', value: 5000 },
],
}),
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="필터 칸"
:disabled="!api"
@change="api && actions.row(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">코드로 걸기: 개발팀·연봉 5000 이상</button>
</div>
<Grid style="height: 540px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: '이름',
width: 120,
filter: { placeholder: L('이름 일부', 'part of the name') },
},
{ id: 'team', title: '팀', kind: 'select', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 150,
filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 530) % 4200),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
!filterModel || filterModel.items.length === 0
? '필터 없음'
: `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// 코드로 걸면 칸에도 그대로 채워져요.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['개발팀'] },
{ columnId: 'salary', operator: 'gte', value: 5000 },
],
}),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="필터 칸"
[disabled]="!api"
(change)="api && actions.row(api, $any($event.target).value)"
>
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>코드로 걸기: 개발팀·연봉 5000 이상</button>
</div>
<mx-grid style="height: 540px" [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';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
salary: number;
hired: Date;
remote: boolean;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: '이름',
width: 120,
filter: { placeholder: L('이름 일부', 'part of the name') },
},
{ id: 'team', title: '팀', kind: 'select', width: 130 },
{
id: 'salary',
title: '연봉(만원)',
kind: 'number',
width: 130,
align: 'end',
filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
},
{
id: 'hired',
title: '입사일',
kind: 'date',
width: 150,
filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
},
{ id: 'remote', title: '재택', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 3800 + ((i * 530) % 4200),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log({
ko:
!filterModel || filterModel.items.length === 0
? '필터 없음'
: `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
en:
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
}),
);
return () => off();
}
export const actions = {
// 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// 코드로 걸면 칸에도 그대로 채워져요.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['개발팀'] },
{ columnId: 'salary', operator: 'gte', value: 5000 },
],
}),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Filter row" id="row">
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
<button type="button" id="fill">Set in code: Dev, salary >= 50000</button>
</div>
<div id="grid" style="height: 540px"></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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
export const options = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: 'Name',
width: 140,
filter: { placeholder: 'part of the name' },
},
{ id: 'team', title: 'Team', kind: 'select', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 140,
align: 'end',
filter: { placeholder: 'e.g. 50000..60000' },
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 150,
filter: { placeholder: 'e.g. >=2022-01-01' },
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
team: teams[(i * 3) % 4],
salary: 38000 + ((i * 5300) % 42000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log(!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`));
return () => off();
}
export const actions = {
// Turning the filter cells on or off is one option. Turning them off also clears active filters.
row: (api, value) => {
if (value === 'off')
api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// Applying from code fills the cells as well.
fill: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['Dev'] },
{ columnId: 'salary', operator: 'gte', value: 50000 },
],
}),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Type in the cells under the header to filter live</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Filter row" id="row">
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
<button type="button" id="fill">Set in code: Dev, salary >= 50000</button>
</div>
<div id="grid" style="height: 540px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
const options = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: 'Name',
width: 140,
filter: { placeholder: 'part of the name' },
},
{ id: 'team', title: 'Team', kind: 'select', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 140,
align: 'end',
filter: { placeholder: 'e.g. 50000..60000' },
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 150,
filter: { placeholder: 'e.g. >=2022-01-01' },
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8],
team: teams[(i * 3) % 4],
salary: 38000 + ((i * 5300) % 42000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
function setup(api, log) {
const off = api.on('filterChanged', ({ filterModel }) => log(!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`));
return () => off();
}
const actions = {
// Turning the filter cells on or off is one option. Turning them off also clears active filters.
row: (api, value) => {
if (value === 'off')
api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// Applying from code fills the cells as well.
fill: (api) => api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['Dev'] },
{ columnId: 'salary', operator: 'gte', value: 50000 },
],
}),
};
options.ariaLabel = "Type in the cells under the header to filter live";
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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(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">
<select
aria-label="Filter row"
disabled={!api}
onChange={(event) => api && actions.row(api, event.target.value)}
>
<option value="on">Show</option>
<option value="off">Hide</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>Set in code: Dev, salary >= 50000</button>
</div>
<Grid style={{ height: 540 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: 'Name',
width: 140,
filter: { placeholder: 'part of the name' },
},
{ id: 'team', title: 'Team', kind: 'select', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 140,
align: 'end',
filter: { placeholder: 'e.g. 50000..60000' },
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 150,
filter: { placeholder: 'e.g. >=2022-01-01' },
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 5300) % 42000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
export const actions = {
// Turning the filter cells on or off is one option. Turning them off also clears active filters.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// Applying from code fills the cells as well.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['Dev'] },
{ columnId: 'salary', operator: 'gte', value: 50000 },
],
}),
};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">
<select
aria-label="Filter row"
:disabled="!api"
@change="api && actions.row(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">Set in code: Dev, salary >= 50000</button>
</div>
<Grid style="height: 540px" :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;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: 'Name',
width: 140,
filter: { placeholder: 'part of the name' },
},
{ id: 'team', title: 'Team', kind: 'select', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 140,
align: 'end',
filter: { placeholder: 'e.g. 50000..60000' },
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 150,
filter: { placeholder: 'e.g. >=2022-01-01' },
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 5300) % 42000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
export const actions = {
// Turning the filter cells on or off is one option. Turning them off also clears active filters.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// Applying from code fills the cells as well.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['Dev'] },
{ columnId: 'salary', operator: 'gte', value: 50000 },
],
}),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Filter row"
[disabled]="!api"
(change)="api && actions.row(api, $any($event.target).value)"
>
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>Set in code: Dev, salary >= 50000</button>
</div>
<mx-grid style="height: 540px" [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;
salary: number;
hired: Date;
remote: boolean;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Sophia Lee',
'Mason Reed',
'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
export const options: GridOptions<Row> = {
filterRow: true,
showRowNumbers: true,
columns: [
{
id: 'name',
title: 'Name',
width: 140,
filter: { placeholder: 'part of the name' },
},
{ id: 'team', title: 'Team', kind: 'select', width: 130 },
{
id: 'salary',
title: 'Salary ($)',
kind: 'number',
width: 140,
align: 'end',
filter: { placeholder: 'e.g. 50000..60000' },
},
{
id: 'hired',
title: 'Hired',
kind: 'date',
width: 150,
filter: { placeholder: 'e.g. >=2022-01-01' },
},
{ id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
],
rows: Array.from({ length: 14 }, (_, i) => ({
id: i + 1,
name: names[i % 8] as string,
team: teams[(i * 3) % 4] as string,
salary: 38000 + ((i * 5300) % 42000),
hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
remote: i % 3 === 0,
})),
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
const off = api.on('filterChanged', ({ filterModel }) =>
log(
!filterModel || filterModel.items.length === 0
? 'No filter'
: `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
),
);
return () => off();
}
export const actions = {
// Turning the filter cells on or off is one option. Turning them off also clears active filters.
row: (api: GridApi<Row>, value?: string) => {
if (value === 'off') api.setFilterModel(null);
api.setOptions({ filterRow: value !== 'off' });
},
// Applying from code fills the cells as well.
fill: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'team', operator: 'in', value: ['Dev'] },
{ columnId: 'salary', operator: 'gte', value: 50000 },
],
}),
};