코드 대신 보이는 이름으로 고르기Pick filter values by what the user sees
데이터에는 D01, 1 같은 코드가 들어 있어도 화면에는 영업팀, 재직처럼 읽기 좋은 이름이 보여요. 필터 값 목록도 보이는 이름으로 나오게 하면 사용자가 코드를 몰라도 고를 수 있어요.Data may hold codes such as D01 or 1 while the grid shows Sales or Active. Show the displayed names in the filter list so users never need to know the codes.
코드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="list">
<option value="shown" selected>보이는 이름 (기본)</option>
<option value="raw">원래 코드</option>
</select>
<button type="button" id="salesOnly">영업팀(D01)만</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 540px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('list').addEventListener('change', (event) => actions.list(api, event.target.value));
document.getElementById('salesOnly').addEventListener('click', () => actions.salesOnly(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// 데이터에는 코드(D01, 1…)가 들어 있고, 화면에는 formatValue로 읽기 좋은 이름을 보여 주는 표예요.
const DEPT = {
D01: '영업팀',
D02: '개발팀',
D03: '인사팀',
D04: '디자인팀',
};
const STATUS = { 1: '재직', 2: '휴직', 3: '퇴직 예정' };
const codes = Object.keys(DEPT);
const columns = (shown) => [
{ id: 'name', title: '이름', width: 110 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// 목록에 코드(D01)를 보일지, 화면에 보이는 이름(영업팀)을 보일지 정해요.
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: '상태',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'][i % 6],
dept: codes[(i * 3) % 4],
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// 부서·상태 칸의 값 목록에 무엇을 보일지 바꿔요. 걸려 있던 필터는 지워요.
list: (api, value) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// 표시 이름으로 고른 것과 같은 결과를 코드로: 영업팀(D01)만
salesOnly: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (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">
<select aria-label="필터 목록" id="list">
<option value="shown" selected>보이는 이름 (기본)</option>
<option value="raw">원래 코드</option>
</select>
<button type="button" id="salesOnly">영업팀(D01)만</button>
<button type="button" id="clear">필터 지우기</button>
</div>
<div id="grid" style="height: 540px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 데이터에는 코드(D01, 1…)가 들어 있고, 화면에는 formatValue로 읽기 좋은 이름을 보여 주는 표예요.
const DEPT = {
D01: '영업팀',
D02: '개발팀',
D03: '인사팀',
D04: '디자인팀',
};
const STATUS = { 1: '재직', 2: '휴직', 3: '퇴직 예정' };
const codes = Object.keys(DEPT);
const columns = (shown) => [
{ id: 'name', title: '이름', width: 110 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// 목록에 코드(D01)를 보일지, 화면에 보이는 이름(영업팀)을 보일지 정해요.
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: '상태',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
const options = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'][i % 6],
dept: codes[(i * 3) % 4],
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
const actions = {
// 부서·상태 칸의 값 목록에 무엇을 보일지 바꿔요. 걸려 있던 필터는 지워요.
list: (api, value) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// 표시 이름으로 고른 것과 같은 결과를 코드로: 영업팀(D01)만
salesOnly: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "코드 대신 보이는 이름으로 고르기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('list').addEventListener('change', (event) => actions.list(api, event.target.value));
document.getElementById('salesOnly').addEventListener('click', () => actions.salesOnly(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="필터 목록"
disabled={!api}
onChange={(event) => api && actions.list(api, event.target.value)}
>
<option value="shown">보이는 이름 (기본)</option>
<option value="raw">원래 코드</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.salesOnly(api)}
>영업팀(D01)만</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>필터 지우기</button>
</div>
<Grid style={{ height: 540 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// 데이터에는 코드(D01, 1…)가 들어 있고, 화면에는 formatValue로 읽기 좋은 이름을 보여 주는 표예요.
const DEPT: Record<string, string> = {
D01: '영업팀',
D02: '개발팀',
D03: '인사팀',
D04: '디자인팀',
};
const STATUS: Record<number, string> = { 1: '재직', 2: '휴직', 3: '퇴직 예정' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: '이름', width: 110 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// 목록에 코드(D01)를 보일지, 화면에 보이는 이름(영업팀)을 보일지 정해요.
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: '상태',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'][i % 6] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// 부서·상태 칸의 값 목록에 무엇을 보일지 바꿔요. 걸려 있던 필터는 지워요.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// 표시 이름으로 고른 것과 같은 결과를 코드로: 영업팀(D01)만
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="필터 목록"
:disabled="!api"
@change="api && actions.list(api, ($event.target as HTMLSelectElement).value)"
>
<option value="shown" selected>보이는 이름 (기본)</option>
<option value="raw">원래 코드</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.salesOnly(api)"
>영업팀(D01)만</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">필터 지우기</button>
</div>
<Grid style="height: 540px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// 데이터에는 코드(D01, 1…)가 들어 있고, 화면에는 formatValue로 읽기 좋은 이름을 보여 주는 표예요.
const DEPT: Record<string, string> = {
D01: '영업팀',
D02: '개발팀',
D03: '인사팀',
D04: '디자인팀',
};
const STATUS: Record<number, string> = { 1: '재직', 2: '휴직', 3: '퇴직 예정' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: '이름', width: 110 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// 목록에 코드(D01)를 보일지, 화면에 보이는 이름(영업팀)을 보일지 정해요.
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: '상태',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'][i % 6] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// 부서·상태 칸의 값 목록에 무엇을 보일지 바꿔요. 걸려 있던 필터는 지워요.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// 표시 이름으로 고른 것과 같은 결과를 코드로: 영업팀(D01)만
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, 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.list(api, $any($event.target).value)"
>
<option value="shown" selected>보이는 이름 (기본)</option>
<option value="raw">원래 코드</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.salesOnly(api)"
>영업팀(D01)만</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>필터 지우기</button>
</div>
<mx-grid style="height: 540px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// 데이터에는 코드(D01, 1…)가 들어 있고, 화면에는 formatValue로 읽기 좋은 이름을 보여 주는 표예요.
const DEPT: Record<string, string> = {
D01: '영업팀',
D02: '개발팀',
D03: '인사팀',
D04: '디자인팀',
};
const STATUS: Record<number, string> = { 1: '재직', 2: '휴직', 3: '퇴직 예정' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: '이름', width: 110 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// 목록에 코드(D01)를 보일지, 화면에 보이는 이름(영업팀)을 보일지 정해요.
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: '상태',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'][i % 6] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// 부서·상태 칸의 값 목록에 무엇을 보일지 바꿔요. 걸려 있던 필터는 지워요.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// 표시 이름으로 고른 것과 같은 결과를 코드로: 영업팀(D01)만
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (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">
<select aria-label="Filter list" id="list">
<option value="shown" selected>Displayed names (default)</option>
<option value="raw">Raw codes</option>
</select>
<button type="button" id="salesOnly">Sales (D01) only</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 540px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('list').addEventListener('change', (event) => actions.list(api, event.target.value));
document.getElementById('salesOnly').addEventListener('click', () => actions.salesOnly(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// The data holds codes (D01, 1...) and formatValue shows readable names on screen.
const DEPT = {
D01: 'Sales',
D02: 'Dev',
D03: 'HR',
D04: 'Design',
};
const STATUS = { 1: 'Active', 2: 'On leave', 3: 'Leaving soon' };
const codes = Object.keys(DEPT);
const columns = (shown) => [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// Decide whether the list shows the code (D01) or the displayed name (Sales).
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: 'Status',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brooks', 'Sophia Lee'][i % 6],
dept: codes[(i * 3) % 4],
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// Change what the Department and Status value lists show. Active filters are cleared.
list: (api, value) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// The same result as picking by displayed name, from code: Sales (D01) only
salesOnly: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (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>Pick filter values by what the user sees</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Filter list" id="list">
<option value="shown" selected>Displayed names (default)</option>
<option value="raw">Raw codes</option>
</select>
<button type="button" id="salesOnly">Sales (D01) only</button>
<button type="button" id="clear">Clear filter</button>
</div>
<div id="grid" style="height: 540px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// The data holds codes (D01, 1...) and formatValue shows readable names on screen.
const DEPT = {
D01: 'Sales',
D02: 'Dev',
D03: 'HR',
D04: 'Design',
};
const STATUS = { 1: 'Active', 2: 'On leave', 3: 'Leaving soon' };
const codes = Object.keys(DEPT);
const columns = (shown) => [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// Decide whether the list shows the code (D01) or the displayed name (Sales).
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: 'Status',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
const options = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brooks', 'Sophia Lee'][i % 6],
dept: codes[(i * 3) % 4],
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
const actions = {
// Change what the Department and Status value lists show. Active filters are cleared.
list: (api, value) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// The same result as picking by displayed name, from code: Sales (D01) only
salesOnly: (api) => api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (api) => api.setFilterModel(null),
};
options.ariaLabel = "Pick filter values by what the user sees";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('list').addEventListener('change', (event) => actions.list(api, event.target.value));
document.getElementById('salesOnly').addEventListener('click', () => actions.salesOnly(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Filter list"
disabled={!api}
onChange={(event) => api && actions.list(api, event.target.value)}
>
<option value="shown">Displayed names (default)</option>
<option value="raw">Raw codes</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.salesOnly(api)}
>Sales (D01) only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear filter</button>
</div>
<Grid style={{ height: 540 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// The data holds codes (D01, 1...) and formatValue shows readable names on screen.
const DEPT: Record<string, string> = {
D01: 'Sales',
D02: 'Dev',
D03: 'HR',
D04: 'Design',
};
const STATUS: Record<number, string> = { 1: 'Active', 2: 'On leave', 3: 'Leaving soon' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// Decide whether the list shows the code (D01) or the displayed name (Sales).
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: 'Status',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brooks', 'Sophia Lee'][
i % 6
] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// Change what the Department and Status value lists show. Active filters are cleared.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// The same result as picking by displayed name, from code: Sales (D01) only
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (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 { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Filter list"
:disabled="!api"
@change="api && actions.list(api, ($event.target as HTMLSelectElement).value)"
>
<option value="shown" selected>Displayed names (default)</option>
<option value="raw">Raw codes</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.salesOnly(api)"
>Sales (D01) only</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear filter</button>
</div>
<Grid style="height: 540px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// The data holds codes (D01, 1...) and formatValue shows readable names on screen.
const DEPT: Record<string, string> = {
D01: 'Sales',
D02: 'Dev',
D03: 'HR',
D04: 'Design',
};
const STATUS: Record<number, string> = { 1: 'Active', 2: 'On leave', 3: 'Leaving soon' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// Decide whether the list shows the code (D01) or the displayed name (Sales).
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: 'Status',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brooks', 'Sophia Lee'][
i % 6
] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// Change what the Department and Status value lists show. Active filters are cleared.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// The same result as picking by displayed name, from code: Sales (D01) only
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (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 } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Filter list"
[disabled]="!api"
(change)="api && actions.list(api, $any($event.target).value)"
>
<option value="shown" selected>Displayed names (default)</option>
<option value="raw">Raw codes</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.salesOnly(api)"
>Sales (D01) only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear filter</button>
</div>
<mx-grid style="height: 540px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
status: number;
}
// The data holds codes (D01, 1...) and formatValue shows readable names on screen.
const DEPT: Record<string, string> = {
D01: 'Sales',
D02: 'Dev',
D03: 'HR',
D04: 'Design',
};
const STATUS: Record<number, string> = { 1: 'Active', 2: 'On leave', 3: 'Leaving soon' };
const codes = Object.keys(DEPT);
const columns = (shown: boolean): GridOptions<Row>['columns'] => [
{ id: 'name', title: 'Name', width: 130 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 150,
formatValue: (value) => DEPT[String(value)] ?? String(value),
// Decide whether the list shows the code (D01) or the displayed name (Sales).
filter: shown ? undefined : { options: codes.map((code) => ({ value: code, label: code })) },
},
{
id: 'status',
title: 'Status',
kind: 'select',
width: 130,
formatValue: (value) => STATUS[Number(value)] ?? String(value),
filter: shown
? undefined
: { options: [1, 2, 3].map((code) => ({ value: code, label: String(code) })) },
},
];
export const options: GridOptions<Row> = {
filterRow: true,
columns: columns(true),
rows: Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
name: ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brooks', 'Sophia Lee'][
i % 6
] as string,
dept: codes[(i * 3) % 4] as string,
status: 1 + ((i * 5) % 3),
})),
rowKey: 'id',
};
export const actions = {
// Change what the Department and Status value lists show. Active filters are cleared.
list: (api: GridApi<Row>, value?: string) => {
api.setFilterModel(null);
api.setColumns(columns(value !== 'raw'));
},
// The same result as picking by displayed name, from code: Sales (D01) only
salesOnly: (api: GridApi<Row>) =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'dept', operator: 'in', value: ['D01'] }],
}),
clear: (api: GridApi<Row>) => api.setFilterModel(null),
};