헤더에 마우스를 올리면 컬럼 설명이 나와요Show a column description on header hover
컬럼이 무슨 뜻인지 헤더에 마우스를 올리면 말풍선으로 알려 줘요. 터치 화면에서는 헤더를 누르면 떠요. 컬럼 묶음(그룹 헤더)에도 달 수 있고, 설명이 있는 곳만 제목 뒤에 ⓘ가 붙어요.Hover a header for a balloon explaining the column; on touch screens, tap it. Column groups can have one too, and only headers with a description carry an info mark.
코드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="on" selected>보이기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 300px"></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 regions = ['서울', '경기·인천', '강원', '충북', '부산', '제주'];
// 설명 글은 한곳에 모아 둬요. 줄바꿈은 \n이고, 길어도 여러 줄로 나뉘어 보여요.
const DESCRIPTIONS = {
region: '영업 담당 권역이에요.\n경기와 인천은 한 권역으로 묶어요.',
q1: '1월~3월 합계(만 원)\n반품은 이미 뺀 금액이에요.',
rate: '(2분기 매출 ÷ 목표) × 100\n100% 이상이면 목표 달성이에요.\n' +
'목표는 연초에 영업팀과 합의한 금액이고, 분기마다 조정될 수 있어요.',
results: '분기별 매출 실적 묶음\n단위는 모두 만 원이에요.',
};
let tipOn = true;
// headerTooltip에 설명을 적으면 헤더에 마우스를 올릴 때(터치에서는 헤더를 누를 때) 말풍선으로 보여요.
// 설명이 있는 컬럼은 제목 뒤에 ⓘ를 붙여서 "여기 설명이 있어요"를 알려 줘요.
const tipOf = (id) => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id, title) => tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// 컬럼 묶음(그룹 헤더)에도 설명을 달 수 있어요.
const groups = () => [
{
id: 'results',
title: withMark('results', '분기 실적'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options = {
columns: [
{ id: 'region', title: withMark('region', '지역'), headerTooltip: tipOf('region'), width: 120 },
{
id: 'q1',
title: withMark('q1', '1분기'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: '2분기', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', '달성률'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: '비고', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: 5200 + ((i * 1370) % 4000),
q2: 5800 + ((i * 910) % 4500),
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? '신규 거래처 증가' : '',
})),
rowKey: 'id',
};
export const actions = {
// 설명을 켜고 끄고, ⓘ 표시도 함께 바꿔요(컬럼 정의만 새로 넘기면 폭·정렬 상태는 그대로예요).
mode: (api, value) => {
tipOn = value !== 'off';
api.setColumns(api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})));
api.setOptions({ headerGroups: groups() });
},
};<!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="on" selected>보이기</option>
<option value="off">끄기</option>
</select>
</div>
<div id="grid" style="height: 300px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const regions = ['서울', '경기·인천', '강원', '충북', '부산', '제주'];
// 설명 글은 한곳에 모아 둬요. 줄바꿈은 \n이고, 길어도 여러 줄로 나뉘어 보여요.
const DESCRIPTIONS = {
region: '영업 담당 권역이에요.\n경기와 인천은 한 권역으로 묶어요.',
q1: '1월~3월 합계(만 원)\n반품은 이미 뺀 금액이에요.',
rate: '(2분기 매출 ÷ 목표) × 100\n100% 이상이면 목표 달성이에요.\n' +
'목표는 연초에 영업팀과 합의한 금액이고, 분기마다 조정될 수 있어요.',
results: '분기별 매출 실적 묶음\n단위는 모두 만 원이에요.',
};
let tipOn = true;
// headerTooltip에 설명을 적으면 헤더에 마우스를 올릴 때(터치에서는 헤더를 누를 때) 말풍선으로 보여요.
// 설명이 있는 컬럼은 제목 뒤에 ⓘ를 붙여서 "여기 설명이 있어요"를 알려 줘요.
const tipOf = (id) => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id, title) => tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// 컬럼 묶음(그룹 헤더)에도 설명을 달 수 있어요.
const groups = () => [
{
id: 'results',
title: withMark('results', '분기 실적'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
const options = {
columns: [
{ id: 'region', title: withMark('region', '지역'), headerTooltip: tipOf('region'), width: 120 },
{
id: 'q1',
title: withMark('q1', '1분기'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: '2분기', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', '달성률'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: '비고', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: 5200 + ((i * 1370) % 4000),
q2: 5800 + ((i * 910) % 4500),
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? '신규 거래처 증가' : '',
})),
rowKey: 'id',
};
const actions = {
// 설명을 켜고 끄고, ⓘ 표시도 함께 바꿔요(컬럼 정의만 새로 넘기면 폭·정렬 상태는 그대로예요).
mode: (api, value) => {
tipOn = value !== 'off';
api.setColumns(api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})));
api.setOptions({ headerGroups: groups() });
},
};
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="on">보이기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions, HeaderGroupDef } from '@maxgrid/react';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['서울', '경기·인천', '강원', '충북', '부산', '제주'];
// 설명 글은 한곳에 모아 둬요. 줄바꿈은 \n이고, 길어도 여러 줄로 나뉘어 보여요.
const DESCRIPTIONS: Record<string, string> = {
region: '영업 담당 권역이에요.\n경기와 인천은 한 권역으로 묶어요.',
q1: '1월~3월 합계(만 원)\n반품은 이미 뺀 금액이에요.',
rate:
'(2분기 매출 ÷ 목표) × 100\n100% 이상이면 목표 달성이에요.\n' +
'목표는 연초에 영업팀과 합의한 금액이고, 분기마다 조정될 수 있어요.',
results: '분기별 매출 실적 묶음\n단위는 모두 만 원이에요.',
};
let tipOn = true;
// headerTooltip에 설명을 적으면 헤더에 마우스를 올릴 때(터치에서는 헤더를 누를 때) 말풍선으로 보여요.
// 설명이 있는 컬럼은 제목 뒤에 ⓘ를 붙여서 "여기 설명이 있어요"를 알려 줘요.
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// 컬럼 묶음(그룹 헤더)에도 설명을 달 수 있어요.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', '분기 실적'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: withMark('region', '지역'), headerTooltip: tipOf('region'), width: 120 },
{
id: 'q1',
title: withMark('q1', '1분기'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: '2분기', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', '달성률'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: '비고', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: 5200 + ((i * 1370) % 4000),
q2: 5800 + ((i * 910) % 4500),
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? '신규 거래처 증가' : '',
})),
rowKey: 'id',
};
export const actions = {
// 설명을 켜고 끄고, ⓘ 표시도 함께 바꿔요(컬럼 정의만 새로 넘기면 폭·정렬 상태는 그대로예요).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};버튼을 누르면 이 예제의 코드가 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="on" selected>보이기</option>
<option value="off">끄기</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions, HeaderGroupDef } from '@maxgrid/vue';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['서울', '경기·인천', '강원', '충북', '부산', '제주'];
// 설명 글은 한곳에 모아 둬요. 줄바꿈은 \n이고, 길어도 여러 줄로 나뉘어 보여요.
const DESCRIPTIONS: Record<string, string> = {
region: '영업 담당 권역이에요.\n경기와 인천은 한 권역으로 묶어요.',
q1: '1월~3월 합계(만 원)\n반품은 이미 뺀 금액이에요.',
rate:
'(2분기 매출 ÷ 목표) × 100\n100% 이상이면 목표 달성이에요.\n' +
'목표는 연초에 영업팀과 합의한 금액이고, 분기마다 조정될 수 있어요.',
results: '분기별 매출 실적 묶음\n단위는 모두 만 원이에요.',
};
let tipOn = true;
// headerTooltip에 설명을 적으면 헤더에 마우스를 올릴 때(터치에서는 헤더를 누를 때) 말풍선으로 보여요.
// 설명이 있는 컬럼은 제목 뒤에 ⓘ를 붙여서 "여기 설명이 있어요"를 알려 줘요.
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// 컬럼 묶음(그룹 헤더)에도 설명을 달 수 있어요.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', '분기 실적'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: withMark('region', '지역'), headerTooltip: tipOf('region'), width: 120 },
{
id: 'q1',
title: withMark('q1', '1분기'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: '2분기', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', '달성률'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: '비고', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: 5200 + ((i * 1370) % 4000),
q2: 5800 + ((i * 910) % 4500),
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? '신규 거래처 증가' : '',
})),
rowKey: 'id',
};
export const actions = {
// 설명을 켜고 끄고, ⓘ 표시도 함께 바꿔요(컬럼 정의만 새로 넘기면 폭·정렬 상태는 그대로예요).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};버튼을 누르면 이 예제의 코드가 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="on" selected>보이기</option>
<option value="off">끄기</option>
</select>
</div>
<mx-grid style="height: 300px" [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, HeaderGroupDef } from '@maxgrid/angular';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['서울', '경기·인천', '강원', '충북', '부산', '제주'];
// 설명 글은 한곳에 모아 둬요. 줄바꿈은 \n이고, 길어도 여러 줄로 나뉘어 보여요.
const DESCRIPTIONS: Record<string, string> = {
region: '영업 담당 권역이에요.\n경기와 인천은 한 권역으로 묶어요.',
q1: '1월~3월 합계(만 원)\n반품은 이미 뺀 금액이에요.',
rate:
'(2분기 매출 ÷ 목표) × 100\n100% 이상이면 목표 달성이에요.\n' +
'목표는 연초에 영업팀과 합의한 금액이고, 분기마다 조정될 수 있어요.',
results: '분기별 매출 실적 묶음\n단위는 모두 만 원이에요.',
};
let tipOn = true;
// headerTooltip에 설명을 적으면 헤더에 마우스를 올릴 때(터치에서는 헤더를 누를 때) 말풍선으로 보여요.
// 설명이 있는 컬럼은 제목 뒤에 ⓘ를 붙여서 "여기 설명이 있어요"를 알려 줘요.
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// 컬럼 묶음(그룹 헤더)에도 설명을 달 수 있어요.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', '분기 실적'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: withMark('region', '지역'), headerTooltip: tipOf('region'), width: 120 },
{
id: 'q1',
title: withMark('q1', '1분기'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: '2분기', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', '달성률'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: '비고', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: 5200 + ((i * 1370) % 4000),
q2: 5800 + ((i * 910) % 4500),
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? '신규 거래처 증가' : '',
})),
rowKey: 'id',
};
export const actions = {
// 설명을 켜고 끄고, ⓘ 표시도 함께 바꿔요(컬럼 정의만 새로 넘기면 폭·정렬 상태는 그대로예요).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};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="Descriptions" id="mode">
<option value="on" selected>Show</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 300px"></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 regions = ['Northeast', 'Mid-Atlantic', 'Midwest', 'South', 'Mountain', 'Pacific'];
// Keep the description texts in one place. A line break is \n, and long text is shown over several lines.
const DESCRIPTIONS = {
region: 'The sales territory.\nNew England is grouped with the Northeast.',
q1: 'January to March total ($)\nReturns are already deducted.',
rate: '(Q2 sales ÷ target) × 100\n100% or more means the target is met.\n' +
'The target is the amount agreed with the sales team at the start of the year and may be adjusted each quarter.',
results: 'Sales results by quarter\nAll amounts are in US dollars.',
};
let tipOn = true;
// Write a description in headerTooltip and it shows as a bubble when the mouse is over the header (on touch, when the header is pressed).
// A column with a description gets an ⓘ after its title to say "there is a description here".
const tipOf = (id) => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id, title) => tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// A column group (group header) can have a description too.
const groups = () => [
{
id: 'results',
title: withMark('results', 'Quarterly results'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options = {
columns: [
{
id: 'region',
title: withMark('region', 'Region'),
headerTooltip: tipOf('region'),
width: 120,
},
{
id: 'q1',
title: withMark('q1', 'Q1'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: 'Q2', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', 'Rate'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: 'Note', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: (5200 + ((i * 1370) % 4000)) * 10,
q2: (5800 + ((i * 910) % 4500)) * 10,
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? 'New accounts growing' : '',
})),
rowKey: 'id',
};
export const actions = {
// Turn the descriptions on and off, and change the ⓘ mark with them (passing only new column definitions keeps the width and align state).
mode: (api, value) => {
tipOn = value !== 'off';
api.setColumns(api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})));
api.setOptions({ headerGroups: groups() });
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Show a column description on header hover</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Descriptions" id="mode">
<option value="on" selected>Show</option>
<option value="off">Off</option>
</select>
</div>
<div id="grid" style="height: 300px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const regions = ['Northeast', 'Mid-Atlantic', 'Midwest', 'South', 'Mountain', 'Pacific'];
// Keep the description texts in one place. A line break is \n, and long text is shown over several lines.
const DESCRIPTIONS = {
region: 'The sales territory.\nNew England is grouped with the Northeast.',
q1: 'January to March total ($)\nReturns are already deducted.',
rate: '(Q2 sales ÷ target) × 100\n100% or more means the target is met.\n' +
'The target is the amount agreed with the sales team at the start of the year and may be adjusted each quarter.',
results: 'Sales results by quarter\nAll amounts are in US dollars.',
};
let tipOn = true;
// Write a description in headerTooltip and it shows as a bubble when the mouse is over the header (on touch, when the header is pressed).
// A column with a description gets an ⓘ after its title to say "there is a description here".
const tipOf = (id) => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id, title) => tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// A column group (group header) can have a description too.
const groups = () => [
{
id: 'results',
title: withMark('results', 'Quarterly results'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
const options = {
columns: [
{
id: 'region',
title: withMark('region', 'Region'),
headerTooltip: tipOf('region'),
width: 120,
},
{
id: 'q1',
title: withMark('q1', 'Q1'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: 'Q2', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', 'Rate'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: 'Note', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: (5200 + ((i * 1370) % 4000)) * 10,
q2: (5800 + ((i * 910) % 4500)) * 10,
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? 'New accounts growing' : '',
})),
rowKey: 'id',
};
const actions = {
// Turn the descriptions on and off, and change the ⓘ mark with them (passing only new column definitions keeps the width and align state).
mode: (api, value) => {
tipOn = value !== 'off';
api.setColumns(api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})));
api.setOptions({ headerGroups: groups() });
},
};
options.ariaLabel = "Show a column description on header hover";
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="Descriptions"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="on">Show</option>
<option value="off">Off</option>
</select>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions, HeaderGroupDef } from '@maxgrid/react';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['Northeast', 'Mid-Atlantic', 'Midwest', 'South', 'Mountain', 'Pacific'];
// Keep the description texts in one place. A line break is \n, and long text is shown over several lines.
const DESCRIPTIONS: Record<string, string> = {
region: 'The sales territory.\nNew England is grouped with the Northeast.',
q1: 'January to March total ($)\nReturns are already deducted.',
rate:
'(Q2 sales ÷ target) × 100\n100% or more means the target is met.\n' +
'The target is the amount agreed with the sales team at the start of the year and may be adjusted each quarter.',
results: 'Sales results by quarter\nAll amounts are in US dollars.',
};
let tipOn = true;
// Write a description in headerTooltip and it shows as a bubble when the mouse is over the header (on touch, when the header is pressed).
// A column with a description gets an ⓘ after its title to say "there is a description here".
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// A column group (group header) can have a description too.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', 'Quarterly results'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{
id: 'region',
title: withMark('region', 'Region'),
headerTooltip: tipOf('region'),
width: 120,
},
{
id: 'q1',
title: withMark('q1', 'Q1'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: 'Q2', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', 'Rate'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: 'Note', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: (5200 + ((i * 1370) % 4000)) * 10,
q2: (5800 + ((i * 910) % 4500)) * 10,
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? 'New accounts growing' : '',
})),
rowKey: 'id',
};
export const actions = {
// Turn the descriptions on and off, and change the ⓘ mark with them (passing only new column definitions keeps the width and align state).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};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="Descriptions"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>Show</option>
<option value="off">Off</option>
</select>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions, HeaderGroupDef } from '@maxgrid/vue';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['Northeast', 'Mid-Atlantic', 'Midwest', 'South', 'Mountain', 'Pacific'];
// Keep the description texts in one place. A line break is \n, and long text is shown over several lines.
const DESCRIPTIONS: Record<string, string> = {
region: 'The sales territory.\nNew England is grouped with the Northeast.',
q1: 'January to March total ($)\nReturns are already deducted.',
rate:
'(Q2 sales ÷ target) × 100\n100% or more means the target is met.\n' +
'The target is the amount agreed with the sales team at the start of the year and may be adjusted each quarter.',
results: 'Sales results by quarter\nAll amounts are in US dollars.',
};
let tipOn = true;
// Write a description in headerTooltip and it shows as a bubble when the mouse is over the header (on touch, when the header is pressed).
// A column with a description gets an ⓘ after its title to say "there is a description here".
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// A column group (group header) can have a description too.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', 'Quarterly results'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{
id: 'region',
title: withMark('region', 'Region'),
headerTooltip: tipOf('region'),
width: 120,
},
{
id: 'q1',
title: withMark('q1', 'Q1'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: 'Q2', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', 'Rate'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: 'Note', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: (5200 + ((i * 1370) % 4000)) * 10,
q2: (5800 + ((i * 910) % 4500)) * 10,
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? 'New accounts growing' : '',
})),
rowKey: 'id',
};
export const actions = {
// Turn the descriptions on and off, and change the ⓘ mark with them (passing only new column definitions keeps the width and align state).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};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="Descriptions"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="on" selected>Show</option>
<option value="off">Off</option>
</select>
</div>
<mx-grid style="height: 300px" [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, HeaderGroupDef } from '@maxgrid/angular';
export interface Row {
id: number;
region: string;
q1: number;
q2: number;
rate: number;
note: string;
}
const regions = ['Northeast', 'Mid-Atlantic', 'Midwest', 'South', 'Mountain', 'Pacific'];
// Keep the description texts in one place. A line break is \n, and long text is shown over several lines.
const DESCRIPTIONS: Record<string, string> = {
region: 'The sales territory.\nNew England is grouped with the Northeast.',
q1: 'January to March total ($)\nReturns are already deducted.',
rate:
'(Q2 sales ÷ target) × 100\n100% or more means the target is met.\n' +
'The target is the amount agreed with the sales team at the start of the year and may be adjusted each quarter.',
results: 'Sales results by quarter\nAll amounts are in US dollars.',
};
let tipOn = true;
// Write a description in headerTooltip and it shows as a bubble when the mouse is over the header (on touch, when the header is pressed).
// A column with a description gets an ⓘ after its title to say "there is a description here".
const tipOf = (id: string): string | undefined => (tipOn ? DESCRIPTIONS[id] : undefined);
const withMark = (id: string, title: string): string =>
tipOn && DESCRIPTIONS[id] ? `${title} ⓘ` : title;
// A column group (group header) can have a description too.
const groups = (): HeaderGroupDef[] => [
{
id: 'results',
title: withMark('results', 'Quarterly results'),
children: ['q1', 'q2'],
headerTooltip: tipOf('results'),
},
];
export const options: GridOptions<Row> = {
columns: [
{
id: 'region',
title: withMark('region', 'Region'),
headerTooltip: tipOf('region'),
width: 120,
},
{
id: 'q1',
title: withMark('q1', 'Q1'),
headerTooltip: tipOf('q1'),
kind: 'number',
width: 110,
align: 'end',
},
{ id: 'q2', title: 'Q2', kind: 'number', width: 110, align: 'end' },
{
id: 'rate',
title: withMark('rate', 'Rate'),
headerTooltip: tipOf('rate'),
kind: 'number',
width: 110,
align: 'end',
formatValue: (value) => `${value}%`,
},
{ id: 'note', title: 'Note', width: 160 },
],
headerGroups: groups(),
rows: regions.map((region, i) => ({
id: i + 1,
region,
q1: (5200 + ((i * 1370) % 4000)) * 10,
q2: (5800 + ((i * 910) % 4500)) * 10,
rate: 82 + ((i * 11) % 30),
note: i % 2 === 0 ? 'New accounts growing' : '',
})),
rowKey: 'id',
};
export const actions = {
// Turn the descriptions on and off, and change the ⓘ mark with them (passing only new column definitions keeps the width and align state).
mode: (api: GridApi<Row>, value?: string) => {
tipOn = value !== 'off';
api.setColumns(
api.getColumns().map((c) => ({
...c,
title: withMark(c.id, (c.title ?? c.id).replace(' ⓘ', '')),
headerTooltip: tipOf(c.id),
})),
);
api.setOptions({ headerGroups: groups() });
},
};