아이콘·이모지와 글자를 함께 보여 주기Show an icon or emoji together with text
파일 종류, 국기, 날씨처럼 그림 하나를 글자 앞에 붙여서 한눈에 알아보게 해요. 그림은 꾸밈이고, 뜻은 항상 옆의 글자가 전해요.Put a small picture before the text, such as file type, flag or weather, for quick recognition. The picture is decoration; the text always carries the meaning.
코드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="icons">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 280px"></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('icons').addEventListener('change', (event) => actions.icons(api, event.target.value));const ICONS = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS = {
sunny: '맑음',
cloudy: '흐림',
rain: '비',
snow: '눈',
};
// 국기 이모지는 나라 코드 두 글자로 만들 수 있어요. 모르는 코드는 흰 깃발이에요.
const flag = (code) => /^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// 이모지는 기기마다 모양이 달라서, 그림은 꾸밈(aria-hidden)이고 뜻은 항상 옆의 글자가 전해요.
const iconText = (iconOf) => () => {
let icon;
let text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() { },
};
};
export const options = {
columns: [
{
id: 'file',
title: '이름',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: '크기', width: 80, align: 'end' },
{
id: 'country',
title: '국가 코드',
width: 110,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: '날씨',
width: 100,
formatValue: (v) => `${withIcon ? (WEATHER[v] ?? '') + ' ' : ''}${WORDS[v] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: '계약서 모음', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: '3분기 보고서.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: '예산-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{ id: 4, file: '현장 사진.png', type: 'image', size: '1.1 MB', country: 'NO', weather: 'snow' },
{ id: 5, file: '백업.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
withIcon = true;
log({
ko: '알 수 없는 국가 코드("??")는 흰 깃발로 보여요.',
en: 'An unknown country code ("??") shows a white flag.',
});
}
export const actions = {
icons: (api, value) => {
withIcon = value !== 'off';
api.refresh(); // 칸을 다시 그려서 그림을 넣거나 빼요
say({
ko: withIcon ? '그림을 글자 앞에 붙여 보여요.' : '그림 없이 글자만 보여요.',
en: withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.',
});
},
};<!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="icons">
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ICONS = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS = {
sunny: '맑음',
cloudy: '흐림',
rain: '비',
snow: '눈',
};
// 국기 이모지는 나라 코드 두 글자로 만들 수 있어요. 모르는 코드는 흰 깃발이에요.
const flag = (code) => /^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// 이모지는 기기마다 모양이 달라서, 그림은 꾸밈(aria-hidden)이고 뜻은 항상 옆의 글자가 전해요.
const iconText = (iconOf) => () => {
let icon;
let text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() { },
};
};
const options = {
columns: [
{
id: 'file',
title: '이름',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: '크기', width: 80, align: 'end' },
{
id: 'country',
title: '국가 코드',
width: 110,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: '날씨',
width: 100,
formatValue: (v) => `${withIcon ? (WEATHER[v] ?? '') + ' ' : ''}${WORDS[v] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: '계약서 모음', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: '3분기 보고서.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: '예산-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{ id: 4, file: '현장 사진.png', type: 'image', size: '1.1 MB', country: 'NO', weather: 'snow' },
{ id: 5, file: '백업.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
withIcon = true;
log({
ko: '알 수 없는 국가 코드("??")는 흰 깃발로 보여요.',
en: 'An unknown country code ("??") shows a white flag.',
});
}
const actions = {
icons: (api, value) => {
withIcon = value !== 'off';
api.refresh(); // 칸을 다시 그려서 그림을 넣거나 빼요
say({
ko: withIcon ? '그림을 글자 앞에 붙여 보여요.' : '그림 없이 글자만 보여요.',
en: withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.',
});
},
};
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('icons').addEventListener('change', (event) => actions.icons(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.icons(api, event.target.value)}
>
<option value="on">켜기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: '맑음',
cloudy: '흐림',
rain: '비',
snow: '눈',
};
// 국기 이모지는 나라 코드 두 글자로 만들 수 있어요. 모르는 코드는 흰 깃발이에요.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// 이모지는 기기마다 모양이 달라서, 그림은 꾸밈(aria-hidden)이고 뜻은 항상 옆의 글자가 전해요.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: '이름',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: '크기', width: 80, align: 'end' },
{
id: 'country',
title: '국가 코드',
width: 110,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: '날씨',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: '계약서 모음', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: '3분기 보고서.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: '예산-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{ id: 4, file: '현장 사진.png', type: 'image', size: '1.1 MB', country: 'NO', weather: 'snow' },
{ id: 5, file: '백업.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log({
ko: '알 수 없는 국가 코드("??")는 흰 깃발로 보여요.',
en: 'An unknown country code ("??") shows a white flag.',
});
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // 칸을 다시 그려서 그림을 넣거나 빼요
say({
ko: withIcon ? '그림을 글자 앞에 붙여 보여요.' : '그림 없이 글자만 보여요.',
en: withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.',
});
},
};버튼을 누르면 이 예제의 코드가 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.icons(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style="height: 280px" :options="options" @ready="onReady" />
</template>import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: '맑음',
cloudy: '흐림',
rain: '비',
snow: '눈',
};
// 국기 이모지는 나라 코드 두 글자로 만들 수 있어요. 모르는 코드는 흰 깃발이에요.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// 이모지는 기기마다 모양이 달라서, 그림은 꾸밈(aria-hidden)이고 뜻은 항상 옆의 글자가 전해요.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: '이름',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: '크기', width: 80, align: 'end' },
{
id: 'country',
title: '국가 코드',
width: 110,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: '날씨',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: '계약서 모음', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: '3분기 보고서.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: '예산-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{ id: 4, file: '현장 사진.png', type: 'image', size: '1.1 MB', country: 'NO', weather: 'snow' },
{ id: 5, file: '백업.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log({
ko: '알 수 없는 국가 코드("??")는 흰 깃발로 보여요.',
en: 'An unknown country code ("??") shows a white flag.',
});
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // 칸을 다시 그려서 그림을 넣거나 빼요
say({
ko: withIcon ? '그림을 글자 앞에 붙여 보여요.' : '그림 없이 글자만 보여요.',
en: withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.',
});
},
};버튼을 누르면 이 예제의 코드가 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.icons(api, $any($event.target).value)"
>
<option value="on" selected>켜기</option>
<option value="off">끄기</option>
</select>
</div>
<mx-grid style="height: 280px" [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 { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: '맑음',
cloudy: '흐림',
rain: '비',
snow: '눈',
};
// 국기 이모지는 나라 코드 두 글자로 만들 수 있어요. 모르는 코드는 흰 깃발이에요.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// 이모지는 기기마다 모양이 달라서, 그림은 꾸밈(aria-hidden)이고 뜻은 항상 옆의 글자가 전해요.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: '이름',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: '크기', width: 80, align: 'end' },
{
id: 'country',
title: '국가 코드',
width: 110,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: '날씨',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: '계약서 모음', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: '3분기 보고서.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: '예산-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{ id: 4, file: '현장 사진.png', type: 'image', size: '1.1 MB', country: 'NO', weather: 'snow' },
{ id: 5, file: '백업.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log({
ko: '알 수 없는 국가 코드("??")는 흰 깃발로 보여요.',
en: 'An unknown country code ("??") shows a white flag.',
});
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // 칸을 다시 그려서 그림을 넣거나 빼요
say({
ko: withIcon ? '그림을 글자 앞에 붙여 보여요.' : '그림 없이 글자만 보여요.',
en: withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.',
});
},
};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="Icons" id="icons">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 280px"></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('icons').addEventListener('change', (event) => actions.icons(api, event.target.value));const ICONS = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS = {
sunny: 'Sunny',
cloudy: 'Cloudy',
rain: 'Rain',
snow: 'Snow',
};
// A flag emoji can be made from a two-letter country code. An unknown code gives a white flag.
const flag = (code) => /^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// Emoji look different on each device, so the picture is decoration (aria-hidden) and the text next to it always carries the meaning.
const iconText = (iconOf) => () => {
let icon;
let text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() { },
};
};
export const options = {
columns: [
{
id: 'file',
title: 'Name',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: 'Size', width: 80, align: 'end' },
{
id: 'country',
title: 'Country code',
width: 130,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: 'Weather',
width: 100,
formatValue: (v) => `${withIcon ? (WEATHER[v] ?? '') + ' ' : ''}${WORDS[v] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: 'Contracts', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: 'Q3 report.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: 'Budget-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{
id: 4,
file: 'Site photo.png',
type: 'image',
size: '1.1 MB',
country: 'NO',
weather: 'snow',
},
{ id: 5, file: 'Backup.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
withIcon = true;
log('An unknown country code ("??") shows a white flag.');
}
export const actions = {
icons: (api, value) => {
withIcon = value !== 'off';
api.refresh(); // redraw the cells to add or remove the pictures
say(withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Show an icon or emoji together with text</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Icons" id="icons">
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ICONS = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS = {
sunny: 'Sunny',
cloudy: 'Cloudy',
rain: 'Rain',
snow: 'Snow',
};
// A flag emoji can be made from a two-letter country code. An unknown code gives a white flag.
const flag = (code) => /^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// Emoji look different on each device, so the picture is decoration (aria-hidden) and the text next to it always carries the meaning.
const iconText = (iconOf) => () => {
let icon;
let text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() { },
};
};
const options = {
columns: [
{
id: 'file',
title: 'Name',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: 'Size', width: 80, align: 'end' },
{
id: 'country',
title: 'Country code',
width: 130,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: 'Weather',
width: 100,
formatValue: (v) => `${withIcon ? (WEATHER[v] ?? '') + ' ' : ''}${WORDS[v] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: 'Contracts', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: 'Q3 report.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: 'Budget-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{
id: 4,
file: 'Site photo.png',
type: 'image',
size: '1.1 MB',
country: 'NO',
weather: 'snow',
},
{ id: 5, file: 'Backup.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
withIcon = true;
log('An unknown country code ("??") shows a white flag.');
}
const actions = {
icons: (api, value) => {
withIcon = value !== 'off';
api.refresh(); // redraw the cells to add or remove the pictures
say(withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.');
},
};
options.ariaLabel = "Show an icon or emoji together with text";
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('icons').addEventListener('change', (event) => actions.icons(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="Icons"
disabled={!api}
onChange={(event) => api && actions.icons(api, event.target.value)}
>
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: 'Sunny',
cloudy: 'Cloudy',
rain: 'Rain',
snow: 'Snow',
};
// A flag emoji can be made from a two-letter country code. An unknown code gives a white flag.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// Emoji look different on each device, so the picture is decoration (aria-hidden) and the text next to it always carries the meaning.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: 'Name',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: 'Size', width: 80, align: 'end' },
{
id: 'country',
title: 'Country code',
width: 130,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: 'Weather',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: 'Contracts', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: 'Q3 report.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: 'Budget-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{
id: 4,
file: 'Site photo.png',
type: 'image',
size: '1.1 MB',
country: 'NO',
weather: 'snow',
},
{ id: 5, file: 'Backup.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log('An unknown country code ("??") shows a white flag.');
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // redraw the cells to add or remove the pictures
say(withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.');
},
};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="Icons"
:disabled="!api"
@change="api && actions.icons(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<Grid style="height: 280px" :options="options" @ready="onReady" />
</template>import type { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: 'Sunny',
cloudy: 'Cloudy',
rain: 'Rain',
snow: 'Snow',
};
// A flag emoji can be made from a two-letter country code. An unknown code gives a white flag.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// Emoji look different on each device, so the picture is decoration (aria-hidden) and the text next to it always carries the meaning.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: 'Name',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: 'Size', width: 80, align: 'end' },
{
id: 'country',
title: 'Country code',
width: 130,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: 'Weather',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: 'Contracts', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: 'Q3 report.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: 'Budget-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{
id: 4,
file: 'Site photo.png',
type: 'image',
size: '1.1 MB',
country: 'NO',
weather: 'snow',
},
{ id: 5, file: 'Backup.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log('An unknown country code ("??") shows a white flag.');
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // redraw the cells to add or remove the pictures
say(withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.');
},
};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="Icons"
[disabled]="!api"
(change)="api && actions.icons(api, $any($event.target).value)"
>
<option value="on" selected>On</option>
<option value="off">Off</option>
</select>
</div>
<mx-grid style="height: 280px" [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 { CellRendererAdapter, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
type: 'folder' | 'pdf' | 'sheet' | 'image' | 'zip';
size: string;
country: string;
weather: 'sunny' | 'cloudy' | 'rain' | 'snow';
}
const ICONS: Record<Row['type'], string> = {
folder: '📁',
pdf: '📕',
sheet: '📊',
image: '🖼️',
zip: '🗜️',
};
const WEATHER: Record<Row['weather'], string> = {
sunny: '☀️',
cloudy: '☁️',
rain: '🌧️',
snow: '❄️',
};
const WORDS: Record<Row['weather'], string> = {
sunny: 'Sunny',
cloudy: 'Cloudy',
rain: 'Rain',
snow: 'Snow',
};
// A flag emoji can be made from a two-letter country code. An unknown code gives a white flag.
const flag = (code: string): string =>
/^[A-Z]{2}$/.test(code)
? String.fromCodePoint(...[...code].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
: '🏳️';
let withIcon = true;
// Emoji look different on each device, so the picture is decoration (aria-hidden) and the text next to it always carries the meaning.
const iconText =
(iconOf: (row: Row) => string): (() => CellRendererAdapter<Row>) =>
() => {
let icon: HTMLSpanElement;
let text: Text;
return {
mount(el, ctx) {
icon = document.createElement('span');
icon.setAttribute('aria-hidden', 'true');
icon.style.marginRight = '6px';
text = document.createTextNode('');
el.append(icon, text);
this.update(ctx);
},
update(ctx) {
icon.textContent = withIcon ? iconOf(ctx.row) : '';
text.data = ctx.text;
},
destroy() {},
};
};
export const options: GridOptions<Row> = {
columns: [
{
id: 'file',
title: 'Name',
width: 180,
cellRenderer: iconText((row) => ICONS[row.type] ?? '📄'),
},
{ id: 'size', title: 'Size', width: 80, align: 'end' },
{
id: 'country',
title: 'Country code',
width: 130,
cellRenderer: iconText((row) => flag(row.country)),
},
{
id: 'weather',
title: 'Weather',
width: 100,
formatValue: (v) =>
`${withIcon ? (WEATHER[v as Row['weather']] ?? '') + ' ' : ''}${WORDS[v as Row['weather']] ?? String(v)}`,
},
],
rows: [
{ id: 1, file: 'Contracts', type: 'folder', size: '—', country: 'KR', weather: 'cloudy' },
{
id: 2,
file: 'Q3 report.pdf',
type: 'pdf',
size: '2.4 MB',
country: 'US',
weather: 'sunny',
},
{
id: 3,
file: 'Budget-2027.xlsx',
type: 'sheet',
size: '380 KB',
country: 'DE',
weather: 'rain',
},
{
id: 4,
file: 'Site photo.png',
type: 'image',
size: '1.1 MB',
country: 'NO',
weather: 'snow',
},
{ id: 5, file: 'Backup.zip', type: 'zip', size: '48 MB', country: '??', weather: 'sunny' },
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withIcon = true;
log('An unknown country code ("??") shows a white flag.');
}
export const actions = {
icons: (api: GridApi<Row>, value?: string) => {
withIcon = value !== 'off';
api.refresh(); // redraw the cells to add or remove the pictures
say(withIcon ? 'Showing the icon before the text.' : 'Showing text only, without the icon.');
},
};