링크 칸: 홈페이지·이메일·전화·티켓Link cells: website, e-mail, phone, ticket
주소 값을 누를 수 있는 링크로 그려요. 이메일은 메일 쓰기로, 전화는 전화 걸기로, 티켓 번호는 baseUrl로 추적 사이트 주소를 만들고 onClick으로 클릭을 먼저 받아요. 안전하지 않은 주소는 링크가 되지 않아요.Draw address values as clickable links: e-mail opens a new message, phone dials, ticket numbers build a tracker address from baseUrl and onClick sees the click first. Unsafe addresses are not turned into links.
코드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="open">
<option value="new" selected>새 창</option>
<option value="same">지금 창</option>
</select>
<button type="button" id="unsafe">위험한 주소 넣기</button>
<button type="button" id="restore">원래 주소로</button>
</div>
<div id="grid" style="height: 260px"></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('open').addEventListener('change', (event) => actions.open(api, event.target.value));
document.getElementById('unsafe').addEventListener('click', () => actions.unsafe(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));// 손가락으로 쓰는 화면(폰)인지 알려 줘요. 이런 화면에서는 누를 곳을 40px 이상으로 키워요.
const coarse = () => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// 이 예제에서만 쓰는 꾸밈 규칙을 화면에 넣고, 정리할 때 함께 지워요.
function addStyle(css) {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
// cellRenderer: 'link'는 값을 누를 수 있는 링크로 그려요. http, https, mailto, tel 주소만 링크가 되고,
// 그 밖의 값(javascript: 같은 것)은 링크 없이 글자로만 보여요.
const rows = [
{
id: 1,
company: '한빛푸드',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+82-2-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: '파란마켓',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+82-51-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: '단풍상회',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+82-62-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: '주소 없는 곳',
site: '',
email: 'info@nosite.example.com',
phone: '+82-42-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = () => [
{ id: 'company', title: '업체', width: 80 },
{
id: 'site',
title: '홈페이지',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: '이메일',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: '전화',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: '티켓',
width: 80,
cellRenderer: 'link',
// baseUrl 뒤에 칸의 글자를 붙여요. onClick은 이동 전에 불리고, preventDefault()로 이동을 멈춰요.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say({
ko: `티켓 ${text}를 눌렀어요. 이동은 멈췄어요(${href}).`,
en: `Clicked ticket ${text}. Navigation was stopped (${href}).`,
});
},
},
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say = () => { };
let removeStyle = () => undefined;
export function setup(_api, log) {
say = log;
newWindow = true;
// 폰에서는 링크를 누르기 쉽게 40px 높이로 키워요.
removeStyle = addStyle('a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }');
log({
ko: '링크는 눌러도 되고, 칸을 고른 뒤 Enter로 칸 안에 들어가 Enter로 열 수도 있어요(Esc로 나와요). 예제 주소라서 실제 페이지는 없어요.',
en: 'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
});
return removeStyle;
}
export const actions = {
open: (api, value) => {
newWindow = value !== 'same';
api.setColumns(columns());
say({
ko: newWindow ? '홈페이지 링크는 새 창에서 열려요.' : '홈페이지 링크는 지금 창에서 열려요.',
en: newWindow
? 'Homepage links open in a new window.'
: 'Homepage links open in this window.',
});
},
unsafe: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say({
ko: '1번 줄 홈페이지를 위험한 주소로 바꿨어요. 링크가 아니라 글자로만 보여요.',
en: 'Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.',
});
},
restore: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say({
ko: '1번 줄 홈페이지를 원래 주소로 되돌렸어요.',
en: 'Changed the homepage of row 1 back to the original address.',
});
},
};<!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="open">
<option value="new" selected>새 창</option>
<option value="same">지금 창</option>
</select>
<button type="button" id="unsafe">위험한 주소 넣기</button>
<button type="button" id="restore">원래 주소로</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 손가락으로 쓰는 화면(폰)인지 알려 줘요. 이런 화면에서는 누를 곳을 40px 이상으로 키워요.
const coarse = () => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// 이 예제에서만 쓰는 꾸밈 규칙을 화면에 넣고, 정리할 때 함께 지워요.
function addStyle(css) {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
// cellRenderer: 'link'는 값을 누를 수 있는 링크로 그려요. http, https, mailto, tel 주소만 링크가 되고,
// 그 밖의 값(javascript: 같은 것)은 링크 없이 글자로만 보여요.
const rows = [
{
id: 1,
company: '한빛푸드',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+82-2-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: '파란마켓',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+82-51-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: '단풍상회',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+82-62-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: '주소 없는 곳',
site: '',
email: 'info@nosite.example.com',
phone: '+82-42-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = () => [
{ id: 'company', title: '업체', width: 80 },
{
id: 'site',
title: '홈페이지',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: '이메일',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: '전화',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: '티켓',
width: 80,
cellRenderer: 'link',
// baseUrl 뒤에 칸의 글자를 붙여요. onClick은 이동 전에 불리고, preventDefault()로 이동을 멈춰요.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say({
ko: `티켓 ${text}를 눌렀어요. 이동은 멈췄어요(${href}).`,
en: `Clicked ticket ${text}. Navigation was stopped (${href}).`,
});
},
},
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say = () => { };
let removeStyle = () => undefined;
function setup(_api, log) {
say = log;
newWindow = true;
// 폰에서는 링크를 누르기 쉽게 40px 높이로 키워요.
removeStyle = addStyle('a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }');
log({
ko: '링크는 눌러도 되고, 칸을 고른 뒤 Enter로 칸 안에 들어가 Enter로 열 수도 있어요(Esc로 나와요). 예제 주소라서 실제 페이지는 없어요.',
en: 'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
});
return removeStyle;
}
const actions = {
open: (api, value) => {
newWindow = value !== 'same';
api.setColumns(columns());
say({
ko: newWindow ? '홈페이지 링크는 새 창에서 열려요.' : '홈페이지 링크는 지금 창에서 열려요.',
en: newWindow
? 'Homepage links open in a new window.'
: 'Homepage links open in this window.',
});
},
unsafe: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say({
ko: '1번 줄 홈페이지를 위험한 주소로 바꿨어요. 링크가 아니라 글자로만 보여요.',
en: 'Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.',
});
},
restore: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say({
ko: '1번 줄 홈페이지를 원래 주소로 되돌렸어요.',
en: 'Changed the homepage of row 1 back to the original address.',
});
},
};
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('open').addEventListener('change', (event) => actions.open(api, event.target.value));
document.getElementById('unsafe').addEventListener('click', () => actions.unsafe(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(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">
<select
aria-label="열리는 곳"
disabled={!api}
onChange={(event) => api && actions.open(api, event.target.value)}
>
<option value="new">새 창</option>
<option value="same">지금 창</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.unsafe(api)}
>위험한 주소 넣기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.restore(api)}
>원래 주소로</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
// 손가락으로 쓰는 화면(폰)인지 알려 줘요. 이런 화면에서는 누를 곳을 40px 이상으로 키워요.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// 이 예제에서만 쓰는 꾸밈 규칙을 화면에 넣고, 정리할 때 함께 지워요.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link'는 값을 누를 수 있는 링크로 그려요. http, https, mailto, tel 주소만 링크가 되고,
// 그 밖의 값(javascript: 같은 것)은 링크 없이 글자로만 보여요.
const rows: Row[] = [
{
id: 1,
company: '한빛푸드',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+82-2-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: '파란마켓',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+82-51-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: '단풍상회',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+82-62-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: '주소 없는 곳',
site: '',
email: 'info@nosite.example.com',
phone: '+82-42-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: '업체', width: 80 },
{
id: 'site',
title: '홈페이지',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: '이메일',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: '전화',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: '티켓',
width: 80,
cellRenderer: 'link',
// baseUrl 뒤에 칸의 글자를 붙여요. onClick은 이동 전에 불리고, preventDefault()로 이동을 멈춰요.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say({
ko: `티켓 ${text}를 눌렀어요. 이동은 멈췄어요(${href}).`,
en: `Clicked ticket ${text}. Navigation was stopped (${href}).`,
});
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// 폰에서는 링크를 누르기 쉽게 40px 높이로 키워요.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log({
ko: '링크는 눌러도 되고, 칸을 고른 뒤 Enter로 칸 안에 들어가 Enter로 열 수도 있어요(Esc로 나와요). 예제 주소라서 실제 페이지는 없어요.',
en: 'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
});
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say({
ko: newWindow ? '홈페이지 링크는 새 창에서 열려요.' : '홈페이지 링크는 지금 창에서 열려요.',
en: newWindow
? 'Homepage links open in a new window.'
: 'Homepage links open in this window.',
});
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say({
ko: '1번 줄 홈페이지를 위험한 주소로 바꿨어요. 링크가 아니라 글자로만 보여요.',
en: 'Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.',
});
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say({
ko: '1번 줄 홈페이지를 원래 주소로 되돌렸어요.',
en: 'Changed the homepage of row 1 back to the original address.',
});
},
};버튼을 누르면 이 예제의 코드가 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.open(api, ($event.target as HTMLSelectElement).value)"
>
<option value="new" selected>새 창</option>
<option value="same">지금 창</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.unsafe(api)">위험한 주소 넣기</button>
<button type="button" :disabled="!api" @click="api && actions.restore(api)">원래 주소로</button>
</div>
<Grid style="height: 260px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
// 손가락으로 쓰는 화면(폰)인지 알려 줘요. 이런 화면에서는 누를 곳을 40px 이상으로 키워요.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// 이 예제에서만 쓰는 꾸밈 규칙을 화면에 넣고, 정리할 때 함께 지워요.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link'는 값을 누를 수 있는 링크로 그려요. http, https, mailto, tel 주소만 링크가 되고,
// 그 밖의 값(javascript: 같은 것)은 링크 없이 글자로만 보여요.
const rows: Row[] = [
{
id: 1,
company: '한빛푸드',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+82-2-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: '파란마켓',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+82-51-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: '단풍상회',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+82-62-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: '주소 없는 곳',
site: '',
email: 'info@nosite.example.com',
phone: '+82-42-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: '업체', width: 80 },
{
id: 'site',
title: '홈페이지',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: '이메일',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: '전화',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: '티켓',
width: 80,
cellRenderer: 'link',
// baseUrl 뒤에 칸의 글자를 붙여요. onClick은 이동 전에 불리고, preventDefault()로 이동을 멈춰요.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say({
ko: `티켓 ${text}를 눌렀어요. 이동은 멈췄어요(${href}).`,
en: `Clicked ticket ${text}. Navigation was stopped (${href}).`,
});
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// 폰에서는 링크를 누르기 쉽게 40px 높이로 키워요.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log({
ko: '링크는 눌러도 되고, 칸을 고른 뒤 Enter로 칸 안에 들어가 Enter로 열 수도 있어요(Esc로 나와요). 예제 주소라서 실제 페이지는 없어요.',
en: 'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
});
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say({
ko: newWindow ? '홈페이지 링크는 새 창에서 열려요.' : '홈페이지 링크는 지금 창에서 열려요.',
en: newWindow
? 'Homepage links open in a new window.'
: 'Homepage links open in this window.',
});
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say({
ko: '1번 줄 홈페이지를 위험한 주소로 바꿨어요. 링크가 아니라 글자로만 보여요.',
en: 'Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.',
});
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say({
ko: '1번 줄 홈페이지를 원래 주소로 되돌렸어요.',
en: 'Changed the homepage of row 1 back to the original address.',
});
},
};버튼을 누르면 이 예제의 코드가 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.open(api, $any($event.target).value)"
>
<option value="new" selected>새 창</option>
<option value="same">지금 창</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.unsafe(api)"
>위험한 주소 넣기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.restore(api)"
>원래 주소로</button>
</div>
<mx-grid style="height: 260px" [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 };
// 손가락으로 쓰는 화면(폰)인지 알려 줘요. 이런 화면에서는 누를 곳을 40px 이상으로 키워요.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// 이 예제에서만 쓰는 꾸밈 규칙을 화면에 넣고, 정리할 때 함께 지워요.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link'는 값을 누를 수 있는 링크로 그려요. http, https, mailto, tel 주소만 링크가 되고,
// 그 밖의 값(javascript: 같은 것)은 링크 없이 글자로만 보여요.
const rows: Row[] = [
{
id: 1,
company: '한빛푸드',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+82-2-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: '파란마켓',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+82-51-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: '단풍상회',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+82-62-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: '주소 없는 곳',
site: '',
email: 'info@nosite.example.com',
phone: '+82-42-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: '업체', width: 80 },
{
id: 'site',
title: '홈페이지',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: '이메일',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: '전화',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: '티켓',
width: 80,
cellRenderer: 'link',
// baseUrl 뒤에 칸의 글자를 붙여요. onClick은 이동 전에 불리고, preventDefault()로 이동을 멈춰요.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say({
ko: `티켓 ${text}를 눌렀어요. 이동은 멈췄어요(${href}).`,
en: `Clicked ticket ${text}. Navigation was stopped (${href}).`,
});
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// 폰에서는 링크를 누르기 쉽게 40px 높이로 키워요.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log({
ko: '링크는 눌러도 되고, 칸을 고른 뒤 Enter로 칸 안에 들어가 Enter로 열 수도 있어요(Esc로 나와요). 예제 주소라서 실제 페이지는 없어요.',
en: 'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
});
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say({
ko: newWindow ? '홈페이지 링크는 새 창에서 열려요.' : '홈페이지 링크는 지금 창에서 열려요.',
en: newWindow
? 'Homepage links open in a new window.'
: 'Homepage links open in this window.',
});
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say({
ko: '1번 줄 홈페이지를 위험한 주소로 바꿨어요. 링크가 아니라 글자로만 보여요.',
en: 'Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.',
});
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say({
ko: '1번 줄 홈페이지를 원래 주소로 되돌렸어요.',
en: 'Changed the homepage of row 1 back to the original address.',
});
},
};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="Opens in" id="open">
<option value="new" selected>New window</option>
<option value="same">Same window</option>
</select>
<button type="button" id="unsafe">Put an unsafe address</button>
<button type="button" id="restore">Restore address</button>
</div>
<div id="grid" style="height: 260px"></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('open').addEventListener('change', (event) => actions.open(api, event.target.value));
document.getElementById('unsafe').addEventListener('click', () => actions.unsafe(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));// Tells whether this is a touch screen (phone). On such screens the tap target grows to at least 40px.
const coarse = () => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// Adds a style rule used only by this example and removes it on cleanup.
function addStyle(css) {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
// cellRenderer: 'link' draws the value as a clickable link. Only http, https, mailto and tel addresses become links;
// any other value (such as javascript:) is shown as plain text without a link.
const rows = [
{
id: 1,
company: 'Harbor Foods',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+1-212-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: 'Blue Market',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+1-415-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: 'Maple Trading',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+1-312-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: 'No website',
site: '',
email: 'info@nosite.example.com',
phone: '+1-617-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = () => [
{ id: 'company', title: 'Company', width: 110 },
{
id: 'site',
title: 'Website',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: 'Email',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: 'Phone',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: 'Ticket',
width: 80,
cellRenderer: 'link',
// The cell text is appended after baseUrl. onClick is called before navigating; preventDefault() stops the navigation.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say(`Clicked ticket ${text}. Navigation was stopped (${href}).`);
},
},
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say = () => { };
let removeStyle = () => undefined;
export function setup(_api, log) {
say = log;
newWindow = true;
// On a phone, links grow to 40px tall so they are easy to tap.
removeStyle = addStyle('a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }');
log('You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.');
return removeStyle;
}
export const actions = {
open: (api, value) => {
newWindow = value !== 'same';
api.setColumns(columns());
say(newWindow ? 'Homepage links open in a new window.' : 'Homepage links open in this window.');
},
unsafe: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say('Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.');
},
restore: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say('Changed the homepage of row 1 back to the original address.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Link cells: website, e-mail, phone, ticket</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Opens in" id="open">
<option value="new" selected>New window</option>
<option value="same">Same window</option>
</select>
<button type="button" id="unsafe">Put an unsafe address</button>
<button type="button" id="restore">Restore address</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// Tells whether this is a touch screen (phone). On such screens the tap target grows to at least 40px.
const coarse = () => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// Adds a style rule used only by this example and removes it on cleanup.
function addStyle(css) {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
// cellRenderer: 'link' draws the value as a clickable link. Only http, https, mailto and tel addresses become links;
// any other value (such as javascript:) is shown as plain text without a link.
const rows = [
{
id: 1,
company: 'Harbor Foods',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+1-212-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: 'Blue Market',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+1-415-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: 'Maple Trading',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+1-312-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: 'No website',
site: '',
email: 'info@nosite.example.com',
phone: '+1-617-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = () => [
{ id: 'company', title: 'Company', width: 110 },
{
id: 'site',
title: 'Website',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: 'Email',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: 'Phone',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: 'Ticket',
width: 80,
cellRenderer: 'link',
// The cell text is appended after baseUrl. onClick is called before navigating; preventDefault() stops the navigation.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say(`Clicked ticket ${text}. Navigation was stopped (${href}).`);
},
},
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say = () => { };
let removeStyle = () => undefined;
function setup(_api, log) {
say = log;
newWindow = true;
// On a phone, links grow to 40px tall so they are easy to tap.
removeStyle = addStyle('a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }');
log('You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.');
return removeStyle;
}
const actions = {
open: (api, value) => {
newWindow = value !== 'same';
api.setColumns(columns());
say(newWindow ? 'Homepage links open in a new window.' : 'Homepage links open in this window.');
},
unsafe: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say('Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.');
},
restore: (api) => {
const row = api.getRowByKey(1);
if (row)
api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say('Changed the homepage of row 1 back to the original address.');
},
};
options.ariaLabel = "Link cells: website, e-mail, phone, ticket";
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('open').addEventListener('change', (event) => actions.open(api, event.target.value));
document.getElementById('unsafe').addEventListener('click', () => actions.unsafe(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(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">
<select
aria-label="Opens in"
disabled={!api}
onChange={(event) => api && actions.open(api, event.target.value)}
>
<option value="new">New window</option>
<option value="same">Same window</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.unsafe(api)}
>Put an unsafe address</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.restore(api)}
>Restore address</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
// Tells whether this is a touch screen (phone). On such screens the tap target grows to at least 40px.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// Adds a style rule used only by this example and removes it on cleanup.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link' draws the value as a clickable link. Only http, https, mailto and tel addresses become links;
// any other value (such as javascript:) is shown as plain text without a link.
const rows: Row[] = [
{
id: 1,
company: 'Harbor Foods',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+1-212-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: 'Blue Market',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+1-415-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: 'Maple Trading',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+1-312-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: 'No website',
site: '',
email: 'info@nosite.example.com',
phone: '+1-617-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: 'Company', width: 110 },
{
id: 'site',
title: 'Website',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: 'Email',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: 'Phone',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: 'Ticket',
width: 80,
cellRenderer: 'link',
// The cell text is appended after baseUrl. onClick is called before navigating; preventDefault() stops the navigation.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say(`Clicked ticket ${text}. Navigation was stopped (${href}).`);
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// On a phone, links grow to 40px tall so they are easy to tap.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log(
'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
);
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say(newWindow ? 'Homepage links open in a new window.' : 'Homepage links open in this window.');
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say('Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.');
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say('Changed the homepage of row 1 back to the original address.');
},
};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="Opens in"
:disabled="!api"
@change="api && actions.open(api, ($event.target as HTMLSelectElement).value)"
>
<option value="new" selected>New window</option>
<option value="same">Same window</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.unsafe(api)">Put an unsafe address</button>
<button type="button" :disabled="!api" @click="api && actions.restore(api)">Restore address</button>
</div>
<Grid style="height: 260px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
// Tells whether this is a touch screen (phone). On such screens the tap target grows to at least 40px.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// Adds a style rule used only by this example and removes it on cleanup.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link' draws the value as a clickable link. Only http, https, mailto and tel addresses become links;
// any other value (such as javascript:) is shown as plain text without a link.
const rows: Row[] = [
{
id: 1,
company: 'Harbor Foods',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+1-212-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: 'Blue Market',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+1-415-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: 'Maple Trading',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+1-312-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: 'No website',
site: '',
email: 'info@nosite.example.com',
phone: '+1-617-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: 'Company', width: 110 },
{
id: 'site',
title: 'Website',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: 'Email',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: 'Phone',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: 'Ticket',
width: 80,
cellRenderer: 'link',
// The cell text is appended after baseUrl. onClick is called before navigating; preventDefault() stops the navigation.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say(`Clicked ticket ${text}. Navigation was stopped (${href}).`);
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// On a phone, links grow to 40px tall so they are easy to tap.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log(
'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
);
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say(newWindow ? 'Homepage links open in a new window.' : 'Homepage links open in this window.');
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say('Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.');
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say('Changed the homepage of row 1 back to the original address.');
},
};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="Opens in"
[disabled]="!api"
(change)="api && actions.open(api, $any($event.target).value)"
>
<option value="new" selected>New window</option>
<option value="same">Same window</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.unsafe(api)"
>Put an unsafe address</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.restore(api)"
>Restore address</button>
</div>
<mx-grid style="height: 260px" [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;
// Tells whether this is a touch screen (phone). On such screens the tap target grows to at least 40px.
const coarse = (): boolean => window.matchMedia('(pointer: coarse), (max-width: 480px)').matches;
// Adds a style rule used only by this example and removes it on cleanup.
function addStyle(css: string): () => void {
const el = document.createElement('style');
el.textContent = css;
document.head.append(el);
return () => el.remove();
}
export interface Row {
id: number;
company: string;
site: string;
email: string;
phone: string;
ticket: string;
}
// cellRenderer: 'link' draws the value as a clickable link. Only http, https, mailto and tel addresses become links;
// any other value (such as javascript:) is shown as plain text without a link.
const rows: Row[] = [
{
id: 1,
company: 'Harbor Foods',
site: 'https://hanbit.example.com',
email: 'sales@hanbit.example.com',
phone: '+1-212-555-0101',
ticket: 'BUG-101',
},
{
id: 2,
company: 'Blue Market',
site: 'https://blue.example.com',
email: 'hello@blue.example.com',
phone: '+1-415-555-0142',
ticket: 'BUG-102',
},
{
id: 3,
company: 'Maple Trading',
site: 'http://maple.example.com',
email: 'orders@maple.example.com',
phone: '+1-312-555-0177',
ticket: 'FEAT-7',
},
{
id: 4,
company: 'No website',
site: '',
email: 'info@nosite.example.com',
phone: '+1-617-555-0100',
ticket: 'OPS-3',
},
];
let newWindow = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'company', title: 'Company', width: 110 },
{
id: 'site',
title: 'Website',
width: 150,
cellRenderer: 'link',
cellRendererParams: { newWindow },
},
{
id: 'email',
title: 'Email',
width: 170,
cellRenderer: 'link',
cellRendererParams: { href: 'mailto:{value}' },
},
{
id: 'phone',
title: 'Phone',
width: 125,
cellRenderer: 'link',
cellRendererParams: { href: 'tel:{value}' },
},
{
id: 'ticket',
title: 'Ticket',
width: 80,
cellRenderer: 'link',
// The cell text is appended after baseUrl. onClick is called before navigating; preventDefault() stops the navigation.
cellRendererParams: {
baseUrl: 'https://tracker.example.com/issues/',
onClick: ({ text, href, event }) => {
event.preventDefault();
say(`Clicked ticket ${text}. Navigation was stopped (${href}).`);
},
},
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
...(coarse() ? { rowHeight: 44 } : {}),
};
let say: (message: LogText) => void = () => {};
let removeStyle: () => void = () => undefined;
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
newWindow = true;
// On a phone, links grow to 40px tall so they are easy to tap.
removeStyle = addStyle(
'a { display: inline-flex; align-items: center; min-height: 24px; } @media (pointer: coarse), (max-width: 480px) { .mxg a { min-height: 40px; } }',
);
log(
'You can click a link, or select a cell, press Enter to go into it and Enter again to open it (Esc to leave). The addresses are examples, so there are no real pages.',
);
return removeStyle;
}
export const actions = {
open: (api: GridApi<Row>, value?: string) => {
newWindow = value !== 'same';
api.setColumns(columns());
say(newWindow ? 'Homepage links open in a new window.' : 'Homepage links open in this window.');
},
unsafe: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'javascript:alert(1)' }]);
say('Changed the homepage of row 1 to an unsafe address. It shows as text, not as a link.');
},
restore: (api: GridApi<Row>) => {
const row = api.getRowByKey(1);
if (row) api.updateRows([{ ...row, site: 'https://hanbit.example.com' }]);
say('Changed the homepage of row 1 back to the original address.');
},
};