말풍선 위치와 동작 고르기Choose where and how tooltips appear
tooltipOptions로 말풍선 위치(대상 기준·마우스 근처·위·아래), 마우스 따라가기, 사라짐 지연, 말풍선 위로 포인터 옮기기, 키보드 표시를 정해요. 컬럼의 tooltipRenderer는 말풍선 안을 DOM으로 채워요.tooltipOptions sets placement (near the target, near the pointer, above, below), pointer following, hide delay, moving the pointer onto the tip and keyboard display. A column's tooltipRenderer fills the tip with DOM.
코드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="mode">
<option value="default" selected>기본</option>
<option value="cursor">마우스 따라가기</option>
<option value="hoverable">말풍선 위로 옮기기</option>
<option value="keyboard">키보드 표시</option>
</select>
</div>
<div id="grid" style="height: 240px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base = {
columns: [
{ id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
const small = document.createElement('small');
small.textContent = ` (${ctx.rowKey}번 주문)`;
el.append(strong, small);
},
},
{ id: 'memo', title: '메모', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i],
price: 59000 + i * 30000,
memo,
})),
rowKey: 'id',
};
export const options = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};<!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="mode">
<option value="default" selected>기본</option>
<option value="cursor">마우스 따라가기</option>
<option value="hoverable">말풍선 위로 옮기기</option>
<option value="keyboard">키보드 표시</option>
</select>
</div>
<div id="grid" style="height: 240px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base = {
columns: [
{ id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
const small = document.createElement('small');
small.textContent = ` (${ctx.rowKey}번 주문)`;
el.append(strong, small);
},
},
{ id: 'memo', title: '메모', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i],
price: 59000 + i * 30000,
memo,
})),
rowKey: 'id',
};
const options = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
const actions = {
mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};
options.ariaLabel = "말풍선 위치와 동작 고르기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="말풍선 방식"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="default">기본</option>
<option value="cursor">마우스 따라가기</option>
<option value="hoverable">말풍선 위로 옮기기</option>
<option value="keyboard">키보드 표시</option>
</select>
</div>
<Grid style={{ height: 240 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base: GridOptions<Row> = {
columns: [
{ id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
const small = document.createElement('small');
small.textContent = ` (${ctx.rowKey}번 주문)`;
el.append(strong, small);
},
},
{ id: 'memo', title: '메모', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i] as string,
price: 59000 + i * 30000,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="말풍선 방식"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>기본</option>
<option value="cursor">마우스 따라가기</option>
<option value="hoverable">말풍선 위로 옮기기</option>
<option value="keyboard">키보드 표시</option>
</select>
</div>
<Grid style="height: 240px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base: GridOptions<Row> = {
columns: [
{ id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
const small = document.createElement('small');
small.textContent = ` (${ctx.rowKey}번 주문)`;
el.append(strong, small);
},
},
{ id: 'memo', title: '메모', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i] as string,
price: 59000 + i * 30000,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, 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.mode(api, $any($event.target).value)"
>
<option value="default" selected>기본</option>
<option value="cursor">마우스 따라가기</option>
<option value="hoverable">말풍선 위로 옮기기</option>
<option value="keyboard">키보드 표시</option>
</select>
</div>
<mx-grid style="height: 240px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base: GridOptions<Row> = {
columns: [
{ id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
const small = document.createElement('small');
small.textContent = ` (${ctx.rowKey}번 주문)`;
el.append(strong, small);
},
},
{ id: 'memo', title: '메모', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i] as string,
price: 59000 + i * 30000,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Tooltip mode" id="mode">
<option value="default" selected>Default</option>
<option value="cursor">Follow pointer</option>
<option value="hoverable">Hoverable tip</option>
<option value="keyboard">Keyboard too</option>
</select>
</div>
<div id="grid" style="height: 240px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));const memos = [
'Deliver in the morning',
'Gift wrapping needed',
'',
'Tax invoice early next month',
];
const base = {
columns: [
{
id: 'product',
title: 'Product',
width: 140,
headerTooltip: 'The name of the ordered product.',
},
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
const small = document.createElement('small');
small.textContent = ` (order #${ctx.rowKey})`;
el.append(strong, small);
},
},
{ id: 'memo', title: 'Memo', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i],
price: 59 + i * 30,
memo,
})),
rowKey: 'id',
};
export const options = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Choose where and how tooltips appear</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Tooltip mode" id="mode">
<option value="default" selected>Default</option>
<option value="cursor">Follow pointer</option>
<option value="hoverable">Hoverable tip</option>
<option value="keyboard">Keyboard too</option>
</select>
</div>
<div id="grid" style="height: 240px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const memos = [
'Deliver in the morning',
'Gift wrapping needed',
'',
'Tax invoice early next month',
];
const base = {
columns: [
{
id: 'product',
title: 'Product',
width: 140,
headerTooltip: 'The name of the ordered product.',
},
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
const small = document.createElement('small');
small.textContent = ` (order #${ctx.rowKey})`;
el.append(strong, small);
},
},
{ id: 'memo', title: 'Memo', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i],
price: 59 + i * 30,
memo,
})),
rowKey: 'id',
};
const options = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
const actions = {
mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};
options.ariaLabel = "Choose where and how tooltips appear";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(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 { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<select
aria-label="Tooltip mode"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="default">Default</option>
<option value="cursor">Follow pointer</option>
<option value="hoverable">Hoverable tip</option>
<option value="keyboard">Keyboard too</option>
</select>
</div>
<Grid style={{ height: 240 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = [
'Deliver in the morning',
'Gift wrapping needed',
'',
'Tax invoice early next month',
];
const base: GridOptions<Row> = {
columns: [
{
id: 'product',
title: 'Product',
width: 140,
headerTooltip: 'The name of the ordered product.',
},
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
const small = document.createElement('small');
small.textContent = ` (order #${ctx.rowKey})`;
el.append(strong, small);
},
},
{ id: 'memo', title: 'Memo', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i] as string,
price: 59 + i * 30,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<select
aria-label="Tooltip mode"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="default" selected>Default</option>
<option value="cursor">Follow pointer</option>
<option value="hoverable">Hoverable tip</option>
<option value="keyboard">Keyboard too</option>
</select>
</div>
<Grid style="height: 240px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = [
'Deliver in the morning',
'Gift wrapping needed',
'',
'Tax invoice early next month',
];
const base: GridOptions<Row> = {
columns: [
{
id: 'product',
title: 'Product',
width: 140,
headerTooltip: 'The name of the ordered product.',
},
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
const small = document.createElement('small');
small.textContent = ` (order #${ctx.rowKey})`;
el.append(strong, small);
},
},
{ id: 'memo', title: 'Memo', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i] as string,
price: 59 + i * 30,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Tooltip mode"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="default" selected>Default</option>
<option value="cursor">Follow pointer</option>
<option value="hoverable">Hoverable tip</option>
<option value="keyboard">Keyboard too</option>
</select>
</div>
<mx-grid style="height: 240px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
product: string;
price: number;
memo: string;
}
const memos = [
'Deliver in the morning',
'Gift wrapping needed',
'',
'Tax invoice early next month',
];
const base: GridOptions<Row> = {
columns: [
{
id: 'product',
title: 'Product',
width: 140,
headerTooltip: 'The name of the ordered product.',
},
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
// tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
tooltip: (row) => `${row.price}`,
tooltipRenderer: (ctx, el) => {
const strong = document.createElement('strong');
strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
const small = document.createElement('small');
small.textContent = ` (order #${ctx.rowKey})`;
el.append(strong, small);
},
},
{ id: 'memo', title: 'Memo', width: 220, tooltip: true },
],
rows: memos.map((memo, i) => ({
id: i + 1,
product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i] as string,
price: 59 + i * 30,
memo,
})),
rowKey: 'id',
};
export const options: GridOptions<Row> = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets: Record<string, GridOptions<Row>['tooltipOptions']> = {
default: undefined,
cursor: { placement: 'cursor', follow: true },
hoverable: { hoverable: true, hideDelay: 300 },
keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
mode: (api: GridApi<Row>, value?: string) =>
api.setOptions({ tooltipOptions: presets[value ?? 'default'] as never }),
};