아이콘을 내 모양으로 바꾸기Replace the grid icons with your own
icons로 정렬 화살표, 펼침 표시, 메뉴 버튼, 필터 버튼을 글자나 SVG로 바꿔요. 컬럼의 icons는 그 컬럼만 바꿔요. 허용 목록에 없는 SVG는 만들 때 거절돼요.icons replaces the sort arrows, the expand marks, the menu button and the filter button with text or SVG. A column's icons changes only that column. An SVG outside the allow list is refused at creation.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="unsafe">위험한 SVG 넣기</button>
</div>
<div id="grid" style="height: 300px"></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('unsafe').addEventListener('click', () => actions.unsafe(api));const rows = [
{ id: 1, team: '영업', name: '김서연', amount: 5200 },
{ id: 2, team: '영업', name: '이준호', amount: 4800 },
{ id: 3, team: '개발', name: '박민지', amount: 6100 },
{ id: 4, team: '개발', name: '최하늘', amount: 5900 },
];
const FUNNEL = '<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons는 이 그리드 전체의 아이콘이에요. 값은 4자 이하의 글자나 SVG 글이고, 주지 않은 것은 기본 모양이에요.
// 컬럼의 icons는 그 컬럼만 바꿔요(여기서는 금액). SVG는 허용 목록(svg·g·path 등)만 쓸 수 있어요.
export const options = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say = () => undefined;
export function setup(_api, log) {
say = log;
log({
ko: '머리글을 눌러 정렬하면 아이콘이 바뀌어요.',
en: 'Sort by clicking a header and watch the icons change.',
});
}
export const actions = {
// 허용 목록 밖(script, onload)이라 거절돼요. 그리드는 그대로이고 오류 메시지만 받아요.
unsafe: (api) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
}
catch (error) {
say(`${error.name}: ${error.message}`);
}
},
};<!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="unsafe">위험한 SVG 넣기</button>
</div>
<div id="grid" style="height: 300px"></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, team: '영업', name: '김서연', amount: 5200 },
{ id: 2, team: '영업', name: '이준호', amount: 4800 },
{ id: 3, team: '개발', name: '박민지', amount: 6100 },
{ id: 4, team: '개발', name: '최하늘', amount: 5900 },
];
const FUNNEL = '<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons는 이 그리드 전체의 아이콘이에요. 값은 4자 이하의 글자나 SVG 글이고, 주지 않은 것은 기본 모양이에요.
// 컬럼의 icons는 그 컬럼만 바꿔요(여기서는 금액). SVG는 허용 목록(svg·g·path 등)만 쓸 수 있어요.
const options = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say = () => undefined;
function setup(_api, log) {
say = log;
log({
ko: '머리글을 눌러 정렬하면 아이콘이 바뀌어요.',
en: 'Sort by clicking a header and watch the icons change.',
});
}
const actions = {
// 허용 목록 밖(script, onload)이라 거절돼요. 그리드는 그대로이고 오류 메시지만 받아요.
unsafe: (api) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
}
catch (error) {
say(`${error.name}: ${error.message}`);
}
},
};
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('unsafe').addEventListener('click', () => actions.unsafe(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.unsafe(api)}
>위험한 SVG 넣기</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: '영업', name: '김서연', amount: 5200 },
{ id: 2, team: '영업', name: '이준호', amount: 4800 },
{ id: 3, team: '개발', name: '박민지', amount: 6100 },
{ id: 4, team: '개발', name: '최하늘', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons는 이 그리드 전체의 아이콘이에요. 값은 4자 이하의 글자나 SVG 글이고, 주지 않은 것은 기본 모양이에요.
// 컬럼의 icons는 그 컬럼만 바꿔요(여기서는 금액). SVG는 허용 목록(svg·g·path 등)만 쓸 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '머리글을 눌러 정렬하면 아이콘이 바뀌어요.',
en: 'Sort by clicking a header and watch the icons change.',
});
}
export const actions = {
// 허용 목록 밖(script, onload)이라 거절돼요. 그리드는 그대로이고 오류 메시지만 받아요.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};버튼을 누르면 이 예제의 코드가 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.unsafe(api)">위험한 SVG 넣기</button>
</div>
<Grid style="height: 300px" :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;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: '영업', name: '김서연', amount: 5200 },
{ id: 2, team: '영업', name: '이준호', amount: 4800 },
{ id: 3, team: '개발', name: '박민지', amount: 6100 },
{ id: 4, team: '개발', name: '최하늘', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons는 이 그리드 전체의 아이콘이에요. 값은 4자 이하의 글자나 SVG 글이고, 주지 않은 것은 기본 모양이에요.
// 컬럼의 icons는 그 컬럼만 바꿔요(여기서는 금액). SVG는 허용 목록(svg·g·path 등)만 쓸 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '머리글을 눌러 정렬하면 아이콘이 바뀌어요.',
en: 'Sort by clicking a header and watch the icons change.',
});
}
export const actions = {
// 허용 목록 밖(script, onload)이라 거절돼요. 그리드는 그대로이고 오류 메시지만 받아요.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};버튼을 누르면 이 예제의 코드가 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.unsafe(api)"
>위험한 SVG 넣기</button>
</div>
<mx-grid style="height: 300px" [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;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: '영업', name: '김서연', amount: 5200 },
{ id: 2, team: '영업', name: '이준호', amount: 4800 },
{ id: 3, team: '개발', name: '박민지', amount: 6100 },
{ id: 4, team: '개발', name: '최하늘', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons는 이 그리드 전체의 아이콘이에요. 값은 4자 이하의 글자나 SVG 글이고, 주지 않은 것은 기본 모양이에요.
// 컬럼의 icons는 그 컬럼만 바꿔요(여기서는 금액). SVG는 허용 목록(svg·g·path 등)만 쓸 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '머리글을 눌러 정렬하면 아이콘이 바뀌어요.',
en: 'Sort by clicking a header and watch the icons change.',
});
}
export const actions = {
// 허용 목록 밖(script, onload)이라 거절돼요. 그리드는 그대로이고 오류 메시지만 받아요.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};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="unsafe">Try an unsafe SVG</button>
</div>
<div id="grid" style="height: 300px"></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('unsafe').addEventListener('click', () => actions.unsafe(api));const rows = [
{ id: 1, team: 'Sales', name: 'Emma Stone', amount: 5200 },
{ id: 2, team: 'Sales', name: 'Liam Carter', amount: 4800 },
{ id: 3, team: 'Dev', name: 'Olivia Hayes', amount: 6100 },
{ id: 4, team: 'Dev', name: 'Noah Reed', amount: 5900 },
];
const FUNNEL = '<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons are the icons for this whole grid. A value is text of up to 4 characters or SVG text, and anything not given keeps the default look.
// A column's icons change only that column (the amount here). SVG may use only the allow list (svg, g, path and so on).
export const options = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say = () => undefined;
export function setup(_api, log) {
say = log;
log('Sort by clicking a header and watch the icons change.');
}
export const actions = {
// It is outside the allow list (script, onload), so it is rejected. The grid stays as it was and you only get an error message.
unsafe: (api) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
}
catch (error) {
say(`${error.name}: ${error.message}`);
}
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Replace the grid icons with your own</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="unsafe">Try an unsafe SVG</button>
</div>
<div id="grid" style="height: 300px"></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, team: 'Sales', name: 'Emma Stone', amount: 5200 },
{ id: 2, team: 'Sales', name: 'Liam Carter', amount: 4800 },
{ id: 3, team: 'Dev', name: 'Olivia Hayes', amount: 6100 },
{ id: 4, team: 'Dev', name: 'Noah Reed', amount: 5900 },
];
const FUNNEL = '<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons are the icons for this whole grid. A value is text of up to 4 characters or SVG text, and anything not given keeps the default look.
// A column's icons change only that column (the amount here). SVG may use only the allow list (svg, g, path and so on).
const options = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say = () => undefined;
function setup(_api, log) {
say = log;
log('Sort by clicking a header and watch the icons change.');
}
const actions = {
// It is outside the allow list (script, onload), so it is rejected. The grid stays as it was and you only get an error message.
unsafe: (api) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
}
catch (error) {
say(`${error.name}: ${error.message}`);
}
},
};
options.ariaLabel = "Replace the grid icons with your own";
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('unsafe').addEventListener('click', () => actions.unsafe(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.unsafe(api)}
>Try an unsafe SVG</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: 'Sales', name: 'Emma Stone', amount: 5200 },
{ id: 2, team: 'Sales', name: 'Liam Carter', amount: 4800 },
{ id: 3, team: 'Dev', name: 'Olivia Hayes', amount: 6100 },
{ id: 4, team: 'Dev', name: 'Noah Reed', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons are the icons for this whole grid. A value is text of up to 4 characters or SVG text, and anything not given keeps the default look.
// A column's icons change only that column (the amount here). SVG may use only the allow list (svg, g, path and so on).
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Sort by clicking a header and watch the icons change.');
}
export const actions = {
// It is outside the allow list (script, onload), so it is rejected. The grid stays as it was and you only get an error message.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};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.unsafe(api)">Try an unsafe SVG</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: 'Sales', name: 'Emma Stone', amount: 5200 },
{ id: 2, team: 'Sales', name: 'Liam Carter', amount: 4800 },
{ id: 3, team: 'Dev', name: 'Olivia Hayes', amount: 6100 },
{ id: 4, team: 'Dev', name: 'Noah Reed', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons are the icons for this whole grid. A value is text of up to 4 characters or SVG text, and anything not given keeps the default look.
// A column's icons change only that column (the amount here). SVG may use only the allow list (svg, g, path and so on).
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Sort by clicking a header and watch the icons change.');
}
export const actions = {
// It is outside the allow list (script, onload), so it is rejected. The grid stays as it was and you only get an error message.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};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.unsafe(api)"
>Try an unsafe SVG</button>
</div>
<mx-grid style="height: 300px" [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;
team: string;
name: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, team: 'Sales', name: 'Emma Stone', amount: 5200 },
{ id: 2, team: 'Sales', name: 'Liam Carter', amount: 4800 },
{ id: 3, team: 'Dev', name: 'Olivia Hayes', amount: 6100 },
{ id: 4, team: 'Dev', name: 'Noah Reed', amount: 5900 },
];
const FUNNEL =
'<svg viewBox="0 0 16 16"><path d="M2 3h12L9.5 8.5V13l-3-1.5V8.5z" fill="currentColor"/></svg>';
// icons are the icons for this whole grid. A value is text of up to 4 characters or SVG text, and anything not given keeps the default look.
// A column's icons change only that column (the amount here). SVG may use only the allow list (svg, g, path and so on).
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 110,
icons: { sortAsc: '▲', sortDesc: '▼' },
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
columnMenu: true,
filterMenu: true,
icons: {
sortAsc: '↑',
sortDesc: '↓',
sortNone: '↕',
expand: '+',
collapse: '-',
menu: '≡',
filter: FUNNEL,
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Sort by clicking a header and watch the icons change.');
}
export const actions = {
// It is outside the allow list (script, onload), so it is rejected. The grid stays as it was and you only get an error message.
unsafe: (api: GridApi<Row>) => {
try {
const open = '<' + 'script>';
api.setOptions({ icons: { menu: `<svg onload="alert(1)">${open}x</svg>` } });
say('accepted?!');
} catch (error) {
say(`${(error as Error).name}: ${(error as Error).message}`);
}
},
};