아이콘: 값에 따라 바꾸기Icons: switch by value
cellRenderer 'icon'은 값에 맞는 글자·이모지·SVG 아이콘을 그려요. map으로 값과 아이콘을 짝지우고, position으로 셀 글자 앞·뒤에 놓고, tone으로 색을 정해요. 허용되지 않는 SVG는 그리지 않아요.cellRenderer 'icon' draws a text, emoji or SVG icon that fits the value. map pairs values with icons, position puts it before or after the cell text, and tone sets the color. SVG that is not allowed is not drawn.
코드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="position">
<option value="before" selected>글자 앞</option>
<option value="after">글자 뒤</option>
<option value="only">아이콘만</option>
</select>
</div>
<div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));const rows = [
{ id: 1, task: '배포 점검', status: 'ok', level: 'low' },
{ id: 2, task: '백업 확인', status: 'warn', level: 'mid' },
{ id: 3, task: '로그 정리', status: 'fail', level: 'high' },
{ id: 4, task: '알 수 없는 값', status: 'unknown', level: 'bad' },
];
// icon의 글자·이모지는 4자 이하, SVG는 허용 목록(path·circle 등)만 받아요. 스크립트나 이벤트 속성이 있으면 그리지 않고 error 이벤트로 알려요.
const CHECK = '<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c) => `<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position) => [
{ id: 'task', title: '작업', width: 150 },
{
id: 'status',
title: '상태',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info',
label: (c) => `상태: ${String(c.value)}`,
},
},
{
id: 'level',
title: '표시',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success',
size: 18,
},
},
];
export const options = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api, log) {
log({
ko: '"배치"를 바꿔 아이콘의 위치를 비교해 보세요. 알 수 없는 값(마지막 줄)은 비어 있어요.',
en: 'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
});
}
export const actions = {
position: (api, value) => api.setColumns(columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before')),
};<!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="position">
<option value="before" selected>글자 앞</option>
<option value="after">글자 뒤</option>
<option value="only">아이콘만</option>
</select>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, task: '배포 점검', status: 'ok', level: 'low' },
{ id: 2, task: '백업 확인', status: 'warn', level: 'mid' },
{ id: 3, task: '로그 정리', status: 'fail', level: 'high' },
{ id: 4, task: '알 수 없는 값', status: 'unknown', level: 'bad' },
];
// icon의 글자·이모지는 4자 이하, SVG는 허용 목록(path·circle 등)만 받아요. 스크립트나 이벤트 속성이 있으면 그리지 않고 error 이벤트로 알려요.
const CHECK = '<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c) => `<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position) => [
{ id: 'task', title: '작업', width: 150 },
{
id: 'status',
title: '상태',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info',
label: (c) => `상태: ${String(c.value)}`,
},
},
{
id: 'level',
title: '표시',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success',
size: 18,
},
},
];
const options = { columns: columns('before'), rows, rowKey: 'id' };
function setup(_api, log) {
log({
ko: '"배치"를 바꿔 아이콘의 위치를 비교해 보세요. 알 수 없는 값(마지막 줄)은 비어 있어요.',
en: 'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
});
}
const actions = {
position: (api, value) => api.setColumns(columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before')),
};
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
</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.position(api, event.target.value)}
>
<option value="before">글자 앞</option>
<option value="after">글자 뒤</option>
<option value="only">아이콘만</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: '배포 점검', status: 'ok', level: 'low' },
{ id: 2, task: '백업 확인', status: 'warn', level: 'mid' },
{ id: 3, task: '로그 정리', status: 'fail', level: 'high' },
{ id: 4, task: '알 수 없는 값', status: 'unknown', level: 'bad' },
];
// icon의 글자·이모지는 4자 이하, SVG는 허용 목록(path·circle 등)만 받아요. 스크립트나 이벤트 속성이 있으면 그리지 않고 error 이벤트로 알려요.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: '작업', width: 150 },
{
id: 'status',
title: '상태',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `상태: ${String(c.value)}`,
},
},
{
id: 'level',
title: '표시',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"배치"를 바꿔 아이콘의 위치를 비교해 보세요. 알 수 없는 값(마지막 줄)은 비어 있어요.',
en: 'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};버튼을 누르면 이 예제의 코드가 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.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="before" selected>글자 앞</option>
<option value="after">글자 뒤</option>
<option value="only">아이콘만</option>
</select>
</div>
<Grid style="height: 200px" :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;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: '배포 점검', status: 'ok', level: 'low' },
{ id: 2, task: '백업 확인', status: 'warn', level: 'mid' },
{ id: 3, task: '로그 정리', status: 'fail', level: 'high' },
{ id: 4, task: '알 수 없는 값', status: 'unknown', level: 'bad' },
];
// icon의 글자·이모지는 4자 이하, SVG는 허용 목록(path·circle 등)만 받아요. 스크립트나 이벤트 속성이 있으면 그리지 않고 error 이벤트로 알려요.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: '작업', width: 150 },
{
id: 'status',
title: '상태',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `상태: ${String(c.value)}`,
},
},
{
id: 'level',
title: '표시',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"배치"를 바꿔 아이콘의 위치를 비교해 보세요. 알 수 없는 값(마지막 줄)은 비어 있어요.',
en: 'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};버튼을 누르면 이 예제의 코드가 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.position(api, $any($event.target).value)"
>
<option value="before" selected>글자 앞</option>
<option value="after">글자 뒤</option>
<option value="only">아이콘만</option>
</select>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: '배포 점검', status: 'ok', level: 'low' },
{ id: 2, task: '백업 확인', status: 'warn', level: 'mid' },
{ id: 3, task: '로그 정리', status: 'fail', level: 'high' },
{ id: 4, task: '알 수 없는 값', status: 'unknown', level: 'bad' },
];
// icon의 글자·이모지는 4자 이하, SVG는 허용 목록(path·circle 등)만 받아요. 스크립트나 이벤트 속성이 있으면 그리지 않고 error 이벤트로 알려요.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: '작업', width: 150 },
{
id: 'status',
title: '상태',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `상태: ${String(c.value)}`,
},
},
{
id: 'level',
title: '표시',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"배치"를 바꿔 아이콘의 위치를 비교해 보세요. 알 수 없는 값(마지막 줄)은 비어 있어요.',
en: 'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
});
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};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="Position" id="position">
<option value="before" selected>Before text</option>
<option value="after">After text</option>
<option value="only">Icon only</option>
</select>
</div>
<div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));const rows = [
{ id: 1, task: 'Deploy check', status: 'ok', level: 'low' },
{ id: 2, task: 'Verify backup', status: 'warn', level: 'mid' },
{ id: 3, task: 'Clean up logs', status: 'fail', level: 'high' },
{ id: 4, task: 'Unknown value', status: 'unknown', level: 'bad' },
];
// Icon text/emoji is at most 4 characters; SVG accepts only an allow list (path, circle, ...). Scripts or event attributes are not drawn and are reported through the error event.
const CHECK = '<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c) => `<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position) => [
{ id: 'task', title: 'Task', width: 150 },
{
id: 'status',
title: 'Status',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info',
label: (c) => `Status: ${String(c.value)}`,
},
},
{
id: 'level',
title: 'Indicator',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success',
size: 18,
},
},
];
export const options = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api, log) {
log('Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.');
}
export const actions = {
position: (api, value) => api.setColumns(columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before')),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Icons: switch by value</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Position" id="position">
<option value="before" selected>Before text</option>
<option value="after">After text</option>
<option value="only">Icon only</option>
</select>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = [
{ id: 1, task: 'Deploy check', status: 'ok', level: 'low' },
{ id: 2, task: 'Verify backup', status: 'warn', level: 'mid' },
{ id: 3, task: 'Clean up logs', status: 'fail', level: 'high' },
{ id: 4, task: 'Unknown value', status: 'unknown', level: 'bad' },
];
// Icon text/emoji is at most 4 characters; SVG accepts only an allow list (path, circle, ...). Scripts or event attributes are not drawn and are reported through the error event.
const CHECK = '<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c) => `<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position) => [
{ id: 'task', title: 'Task', width: 150 },
{
id: 'status',
title: 'Status',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info',
label: (c) => `Status: ${String(c.value)}`,
},
},
{
id: 'level',
title: 'Indicator',
width: 150,
cellRenderer: 'icon',
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success',
size: 18,
},
},
];
const options = { columns: columns('before'), rows, rowKey: 'id' };
function setup(_api, log) {
log('Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.');
}
const actions = {
position: (api, value) => api.setColumns(columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before')),
};
options.ariaLabel = "Icons: switch by value";
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('position').addEventListener('change', (event) => actions.position(api, event.target.value));
</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="Position"
disabled={!api}
onChange={(event) => api && actions.position(api, event.target.value)}
>
<option value="before">Before text</option>
<option value="after">After text</option>
<option value="only">Icon only</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: 'Deploy check', status: 'ok', level: 'low' },
{ id: 2, task: 'Verify backup', status: 'warn', level: 'mid' },
{ id: 3, task: 'Clean up logs', status: 'fail', level: 'high' },
{ id: 4, task: 'Unknown value', status: 'unknown', level: 'bad' },
];
// Icon text/emoji is at most 4 characters; SVG accepts only an allow list (path, circle, ...). Scripts or event attributes are not drawn and are reported through the error event.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: 'Task', width: 150 },
{
id: 'status',
title: 'Status',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `Status: ${String(c.value)}`,
},
},
{
id: 'level',
title: 'Indicator',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
);
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};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="Position"
:disabled="!api"
@change="api && actions.position(api, ($event.target as HTMLSelectElement).value)"
>
<option value="before" selected>Before text</option>
<option value="after">After text</option>
<option value="only">Icon only</option>
</select>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: 'Deploy check', status: 'ok', level: 'low' },
{ id: 2, task: 'Verify backup', status: 'warn', level: 'mid' },
{ id: 3, task: 'Clean up logs', status: 'fail', level: 'high' },
{ id: 4, task: 'Unknown value', status: 'unknown', level: 'bad' },
];
// Icon text/emoji is at most 4 characters; SVG accepts only an allow list (path, circle, ...). Scripts or event attributes are not drawn and are reported through the error event.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: 'Task', width: 150 },
{
id: 'status',
title: 'Status',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `Status: ${String(c.value)}`,
},
},
{
id: 'level',
title: 'Indicator',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
);
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};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="Position"
[disabled]="!api"
(change)="api && actions.position(api, $any($event.target).value)"
>
<option value="before" selected>Before text</option>
<option value="after">After text</option>
<option value="only">Icon only</option>
</select>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
task: string;
status: string;
level: string;
}
const rows: Row[] = [
{ id: 1, task: 'Deploy check', status: 'ok', level: 'low' },
{ id: 2, task: 'Verify backup', status: 'warn', level: 'mid' },
{ id: 3, task: 'Clean up logs', status: 'fail', level: 'high' },
{ id: 4, task: 'Unknown value', status: 'unknown', level: 'bad' },
];
// Icon text/emoji is at most 4 characters; SVG accepts only an allow list (path, circle, ...). Scripts or event attributes are not drawn and are reported through the error event.
const CHECK =
'<svg viewBox="0 0 16 16"><path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
const DOT = (c: string): string =>
`<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="${c}"/></svg>`;
const columns = (position: 'before' | 'after' | 'only') => [
{ id: 'task', title: 'Task', width: 150 },
{
id: 'status',
title: 'Status',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { ok: '✔', warn: '⚠', fail: '✘' },
position,
tone: 'info' as const,
label: (c: { value: unknown }) => `Status: ${String(c.value)}`,
},
},
{
id: 'level',
title: 'Indicator',
width: 150,
cellRenderer: 'icon' as const,
cellRendererParams: {
map: { low: CHECK, mid: DOT('currentColor'), high: DOT('#b42318') },
position,
tone: 'success' as const,
size: 18,
},
},
];
export const options: GridOptions<Row> = { columns: columns('before'), rows, rowKey: 'id' };
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Change "Position" to compare where the icon sits. An unknown value (the last row) stays empty.',
);
}
export const actions = {
position: (api: GridApi<Row>, value?: string) =>
api.setColumns(
columns(value === 'after' ? 'after' : value === 'only' ? 'only' : 'before') as never,
),
};