머리글 안 드롭다운Dropdown inside a header
headerRenderer: 'dropdown'은 머리글에 목록 버튼을 둬요. 고른 값은 onSelect로 앱에 전달되고 이 예제는 그 값으로 행을 걸러요. applyToTitle이면 버튼에 컬럼 제목과 고른 이름이 함께 나와요.headerRenderer: 'dropdown' puts a list button in the header. The chosen value reaches the app through onSelect, and this example filters the rows with it. With applyToTitle the button shows the column title together with the chosen name.
코드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="dev">개발로 바꾸기</button>
<button type="button" id="all">전체로 되돌리기</button>
</div>
<div id="grid" style="height: 380px"></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('dev').addEventListener('click', () => actions.dev(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));// 영어 페이지는 컬럼 제목·목록·데이터를 모두 영어로 보여요.
const en = document.documentElement.dataset.lang === 'en';
const TEAMS = en ? ['Dev', 'Design', 'Sales'] : ['개발', '디자인', '영업'];
const CITIES = en ? ['Seoul', 'Busan', 'Daegu'] : ['서울', '부산', '대구'];
const ALL = en ? 'All' : '전체';
const ROWS = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: en ? `Staff ${i + 1}` : `사원 ${i + 1}`,
team: TEAMS[i % 3],
city: CITIES[(i * 2) % 3],
}));
let say = () => { };
let apiRef = null;
/** 고른 팀으로 보이는 행을 거른다(앱이 하는 일: 드롭다운은 값만 알려 줘요). */
function filterTeam(team) {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120 },
{
id: 'team',
title: en ? 'Team' : '팀',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: en ? 'City' : '도시', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api, log) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) => say({
ko: `${e.columnId} 머리글에서 '${e.label}' 고름`,
en: `Picked '${e.label}' in the ${e.columnId} header`,
}));
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api) => {
// 값만 바꾸면 목록과 onSelect는 그대로 남아요.
api.setHeaderRendererParams('team', { value: TEAMS[0] });
filterTeam(TEAMS[0]);
say({
ko: "setHeaderRendererParams: value '개발'",
en: "setHeaderRendererParams: value 'dev'",
});
},
all: (api) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say({ ko: '전체로 되돌림', en: 'Back to all' });
},
};<!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="dev">개발로 바꾸기</button>
<button type="button" id="all">전체로 되돌리기</button>
</div>
<div id="grid" style="height: 380px"></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 TEAMS = en ? ['Dev', 'Design', 'Sales'] : ['개발', '디자인', '영업'];
const CITIES = en ? ['Seoul', 'Busan', 'Daegu'] : ['서울', '부산', '대구'];
const ALL = en ? 'All' : '전체';
const ROWS = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: en ? `Staff ${i + 1}` : `사원 ${i + 1}`,
team: TEAMS[i % 3],
city: CITIES[(i * 2) % 3],
}));
let say = () => { };
let apiRef = null;
/** 고른 팀으로 보이는 행을 거른다(앱이 하는 일: 드롭다운은 값만 알려 줘요). */
function filterTeam(team) {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
const options = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120 },
{
id: 'team',
title: en ? 'Team' : '팀',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: en ? 'City' : '도시', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
function setup(api, log) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) => say({
ko: `${e.columnId} 머리글에서 '${e.label}' 고름`,
en: `Picked '${e.label}' in the ${e.columnId} header`,
}));
return () => {
off();
apiRef = null;
};
}
const actions = {
dev: (api) => {
// 값만 바꾸면 목록과 onSelect는 그대로 남아요.
api.setHeaderRendererParams('team', { value: TEAMS[0] });
filterTeam(TEAMS[0]);
say({
ko: "setHeaderRendererParams: value '개발'",
en: "setHeaderRendererParams: value 'dev'",
});
},
all: (api) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say({ ko: '전체로 되돌림', en: 'Back to all' });
},
};
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('dev').addEventListener('click', () => actions.dev(api));
document.getElementById('all').addEventListener('click', () => actions.all(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.dev(api)}
>개발로 바꾸기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>전체로 되돌리기</button>
</div>
<Grid style={{ height: 380 }} 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;
city: string;
}
// 영어 페이지는 컬럼 제목·목록·데이터를 모두 영어로 보여요.
const en = document.documentElement.dataset.lang === 'en';
const TEAMS = en ? ['Dev', 'Design', 'Sales'] : ['개발', '디자인', '영업'];
const CITIES = en ? ['Seoul', 'Busan', 'Daegu'] : ['서울', '부산', '대구'];
const ALL = en ? 'All' : '전체';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: en ? `Staff ${i + 1}` : `사원 ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** 고른 팀으로 보이는 행을 거른다(앱이 하는 일: 드롭다운은 값만 알려 줘요). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120 },
{
id: 'team',
title: en ? 'Team' : '팀',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: en ? 'City' : '도시', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say({
ko: `${e.columnId} 머리글에서 '${e.label}' 고름`,
en: `Picked '${e.label}' in the ${e.columnId} header`,
}),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// 값만 바꾸면 목록과 onSelect는 그대로 남아요.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say({
ko: "setHeaderRendererParams: value '개발'",
en: "setHeaderRendererParams: value 'dev'",
});
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say({ ko: '전체로 되돌림', en: 'Back to all' });
},
};버튼을 누르면 이 예제의 코드가 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.dev(api)">개발로 바꾸기</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">전체로 되돌리기</button>
</div>
<Grid style="height: 380px" :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;
city: string;
}
// 영어 페이지는 컬럼 제목·목록·데이터를 모두 영어로 보여요.
const en = document.documentElement.dataset.lang === 'en';
const TEAMS = en ? ['Dev', 'Design', 'Sales'] : ['개발', '디자인', '영업'];
const CITIES = en ? ['Seoul', 'Busan', 'Daegu'] : ['서울', '부산', '대구'];
const ALL = en ? 'All' : '전체';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: en ? `Staff ${i + 1}` : `사원 ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** 고른 팀으로 보이는 행을 거른다(앱이 하는 일: 드롭다운은 값만 알려 줘요). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120 },
{
id: 'team',
title: en ? 'Team' : '팀',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: en ? 'City' : '도시', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say({
ko: `${e.columnId} 머리글에서 '${e.label}' 고름`,
en: `Picked '${e.label}' in the ${e.columnId} header`,
}),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// 값만 바꾸면 목록과 onSelect는 그대로 남아요.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say({
ko: "setHeaderRendererParams: value '개발'",
en: "setHeaderRendererParams: value 'dev'",
});
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say({ ko: '전체로 되돌림', en: 'Back to all' });
},
};버튼을 누르면 이 예제의 코드가 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.dev(api)"
>개발로 바꾸기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>전체로 되돌리기</button>
</div>
<mx-grid style="height: 380px" [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;
city: string;
}
// 영어 페이지는 컬럼 제목·목록·데이터를 모두 영어로 보여요.
const en = document.documentElement.dataset.lang === 'en';
const TEAMS = en ? ['Dev', 'Design', 'Sales'] : ['개발', '디자인', '영업'];
const CITIES = en ? ['Seoul', 'Busan', 'Daegu'] : ['서울', '부산', '대구'];
const ALL = en ? 'All' : '전체';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: en ? `Staff ${i + 1}` : `사원 ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** 고른 팀으로 보이는 행을 거른다(앱이 하는 일: 드롭다운은 값만 알려 줘요). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: en ? 'Name' : '이름', width: 120 },
{
id: 'team',
title: en ? 'Team' : '팀',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: en ? 'City' : '도시', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say({
ko: `${e.columnId} 머리글에서 '${e.label}' 고름`,
en: `Picked '${e.label}' in the ${e.columnId} header`,
}),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// 값만 바꾸면 목록과 onSelect는 그대로 남아요.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say({
ko: "setHeaderRendererParams: value '개발'",
en: "setHeaderRendererParams: value 'dev'",
});
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say({ ko: '전체로 되돌림', en: 'Back to all' });
},
};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="dev">Set to Dev</button>
<button type="button" id="all">Back to All</button>
</div>
<div id="grid" style="height: 380px"></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('dev').addEventListener('click', () => actions.dev(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['Seoul', 'Busan', 'Daegu'];
const ALL = 'All';
const ROWS = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `Staff ${i + 1}`,
team: TEAMS[i % 3],
city: CITIES[(i * 2) % 3],
}));
let say = () => { };
let apiRef = null;
/** Filter the visible rows by the chosen team (the app's job: the dropdown only reports the value). */
function filterTeam(team) {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{
id: 'team',
title: 'Team',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: 'City', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api, log) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) => say(`Picked '${e.label}' in the ${e.columnId} header`));
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api) => {
// Changing only the value keeps the list and onSelect as they are.
api.setHeaderRendererParams('team', { value: TEAMS[0] });
filterTeam(TEAMS[0]);
say("setHeaderRendererParams: value 'dev'");
},
all: (api) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say('Back to all');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dropdown inside a header</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="dev">Set to Dev</button>
<button type="button" id="all">Back to All</button>
</div>
<div id="grid" style="height: 380px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['Seoul', 'Busan', 'Daegu'];
const ALL = 'All';
const ROWS = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `Staff ${i + 1}`,
team: TEAMS[i % 3],
city: CITIES[(i * 2) % 3],
}));
let say = () => { };
let apiRef = null;
/** Filter the visible rows by the chosen team (the app's job: the dropdown only reports the value). */
function filterTeam(team) {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
const options = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{
id: 'team',
title: 'Team',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: 'City', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
function setup(api, log) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) => say(`Picked '${e.label}' in the ${e.columnId} header`));
return () => {
off();
apiRef = null;
};
}
const actions = {
dev: (api) => {
// Changing only the value keeps the list and onSelect as they are.
api.setHeaderRendererParams('team', { value: TEAMS[0] });
filterTeam(TEAMS[0]);
say("setHeaderRendererParams: value 'dev'");
},
all: (api) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say('Back to all');
},
};
options.ariaLabel = "Dropdown inside a header";
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('dev').addEventListener('click', () => actions.dev(api));
document.getElementById('all').addEventListener('click', () => actions.all(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.dev(api)}
>Set to Dev</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>Back to All</button>
</div>
<Grid style={{ height: 380 }} 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;
city: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['Seoul', 'Busan', 'Daegu'];
const ALL = 'All';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `Staff ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** Filter the visible rows by the chosen team (the app's job: the dropdown only reports the value). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{
id: 'team',
title: 'Team',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: 'City', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say(`Picked '${e.label}' in the ${e.columnId} header`),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// Changing only the value keeps the list and onSelect as they are.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say("setHeaderRendererParams: value 'dev'");
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say('Back to all');
},
};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.dev(api)">Set to Dev</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">Back to All</button>
</div>
<Grid style="height: 380px" :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;
city: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['Seoul', 'Busan', 'Daegu'];
const ALL = 'All';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `Staff ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** Filter the visible rows by the chosen team (the app's job: the dropdown only reports the value). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{
id: 'team',
title: 'Team',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: 'City', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say(`Picked '${e.label}' in the ${e.columnId} header`),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// Changing only the value keeps the list and onSelect as they are.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say("setHeaderRendererParams: value 'dev'");
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say('Back to all');
},
};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.dev(api)"
>Set to Dev</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>Back to All</button>
</div>
<mx-grid style="height: 380px" [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;
city: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['Seoul', 'Busan', 'Daegu'];
const ALL = 'All';
const ROWS: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `Staff ${i + 1}`,
team: TEAMS[i % 3] as string,
city: CITIES[(i * 2) % 3] as string,
}));
let say: (message: LogText) => void = () => {};
let apiRef: GridApi<Row> | null = null;
/** Filter the visible rows by the chosen team (the app's job: the dropdown only reports the value). */
function filterTeam(team: string | number | null): void {
apiRef?.setQuickFilter(team === null || team === 'all' ? '' : String(team));
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{
id: 'team',
title: 'Team',
width: 160,
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: ALL }, ...TEAMS.map((t) => ({ value: t, label: t }))],
value: 'all',
applyToTitle: true,
onSelect: ({ value }) => filterTeam(value),
},
},
{ id: 'city', title: 'City', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
apiRef = api;
const off = api.on('headerDropdownChanged', (e) =>
say(`Picked '${e.label}' in the ${e.columnId} header`),
);
return () => {
off();
apiRef = null;
};
}
export const actions = {
dev: (api: GridApi<Row>) => {
// Changing only the value keeps the list and onSelect as they are.
api.setHeaderRendererParams('team', { value: TEAMS[0] as string });
filterTeam(TEAMS[0] as string);
say("setHeaderRendererParams: value 'dev'");
},
all: (api: GridApi<Row>) => {
api.setHeaderRendererParams('team', { value: 'all' });
filterTeam('all');
say('Back to all');
},
};