테마(밝게·어둡게)와 칸 여백·줄 높이 바꾸기Switch the theme, cell padding and row height
칸 여백(촘촘·보통·넉넉)은 칸의 좌우 여백을, 줄 높이는 따로 줄 높이를 바꾸고, 테마는 표 안쪽만 밝게나 어둡게 바꿔요. 표 테마를 '사이트 따라가기'로 두면 사이트 설정을 따라가요.Cell padding (compact, normal, comfortable) changes the side gaps, row height changes the line height separately, and the theme switches only the table to light or dark. Follow site goes back to the site setting.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="칸 여백" id="density">
<option value="compact">촘촘하게</option>
<option value="normal" selected>보통 (기본)</option>
<option value="comfortable">넉넉하게</option>
</select>
<select aria-label="줄 높이" id="rowHeight">
<option value="28">28px</option>
<option value="32" selected>32px (기본)</option>
<option value="44">44px</option>
</select>
<select aria-label="그리드 테마" id="theme">
<option value="site" selected>사이트 따라가기 (기본)</option>
<option value="light">밝게</option>
<option value="dark">어둡게</option>
</select>
<button type="button" id="rowNumbers">줄 번호 켬/끔</button>
</div>
<div id="grid" style="height: 360px"></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('density').addEventListener('change', (event) => actions.density(api, event.target.value));
document.getElementById('rowHeight').addEventListener('change', (event) => actions.rowHeight(api, event.target.value));
document.getElementById('theme').addEventListener('change', (event) => actions.theme(api, event.target.value));
document.getElementById('rowNumbers').addEventListener('click', () => actions.rowNumbers(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4],
salary: 320 + i * 41,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// 밀도는 그리드 옵션이에요. 세 값이 칸의 좌우 여백(4·8·12px)을 바꿔요.
density: (api, value) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value });
}
},
// 줄 높이는 따로 rowHeight(px)로 정해요.
rowHeight: (api, value) => api.setOptions({ rowHeight: Number(value) || 32 }),
// 테마는 CSS 속성이에요. 그리드(또는 그 위의 어떤 요소)에 data-mxg-theme="dark" 또는 "light"를 달면
// 그 안쪽만 바뀌어요. 속성을 지우면 사이트 설정을 따라가요.
theme: (_api, value) => {
const root = document.querySelector('.mxg');
if (!root)
return;
if (value === 'light' || value === 'dark')
root.setAttribute('data-mxg-theme', value);
else
root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api) => api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};<!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="density">
<option value="compact">촘촘하게</option>
<option value="normal" selected>보통 (기본)</option>
<option value="comfortable">넉넉하게</option>
</select>
<select aria-label="줄 높이" id="rowHeight">
<option value="28">28px</option>
<option value="32" selected>32px (기본)</option>
<option value="44">44px</option>
</select>
<select aria-label="그리드 테마" id="theme">
<option value="site" selected>사이트 따라가기 (기본)</option>
<option value="light">밝게</option>
<option value="dark">어둡게</option>
</select>
<button type="button" id="rowNumbers">줄 번호 켬/끔</button>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4],
salary: 320 + i * 41,
})),
rowKey: 'id',
density: 'normal',
};
const actions = {
// 밀도는 그리드 옵션이에요. 세 값이 칸의 좌우 여백(4·8·12px)을 바꿔요.
density: (api, value) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value });
}
},
// 줄 높이는 따로 rowHeight(px)로 정해요.
rowHeight: (api, value) => api.setOptions({ rowHeight: Number(value) || 32 }),
// 테마는 CSS 속성이에요. 그리드(또는 그 위의 어떤 요소)에 data-mxg-theme="dark" 또는 "light"를 달면
// 그 안쪽만 바뀌어요. 속성을 지우면 사이트 설정을 따라가요.
theme: (_api, value) => {
const root = document.querySelector('.mxg');
if (!root)
return;
if (value === 'light' || value === 'dark')
root.setAttribute('data-mxg-theme', value);
else
root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api) => api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};
options.ariaLabel = "테마(밝게·어둡게)와 칸 여백·줄 높이 바꾸기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('density').addEventListener('change', (event) => actions.density(api, event.target.value));
document.getElementById('rowHeight').addEventListener('change', (event) => actions.rowHeight(api, event.target.value));
document.getElementById('theme').addEventListener('change', (event) => actions.theme(api, event.target.value));
document.getElementById('rowNumbers').addEventListener('click', () => actions.rowNumbers(api));
</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.density(api, event.target.value)}
>
<option value="compact">촘촘하게</option>
<option value="normal">보통 (기본)</option>
<option value="comfortable">넉넉하게</option>
</select>
<select defaultValue="normal"
aria-label="줄 높이"
disabled={!api}
onChange={(event) => api && actions.rowHeight(api, event.target.value)}
>
<option value="28">28px</option>
<option value="32">32px (기본)</option>
<option value="44">44px</option>
</select>
<select defaultValue="32"
aria-label="그리드 테마"
disabled={!api}
onChange={(event) => api && actions.theme(api, event.target.value)}
>
<option value="site">사이트 따라가기 (기본)</option>
<option value="light">밝게</option>
<option value="dark">어둡게</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.rowNumbers(api)}
>줄 번호 켬/끔</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridDensity, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 320 + i * 41,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// 밀도는 그리드 옵션이에요. 세 값이 칸의 좌우 여백(4·8·12px)을 바꿔요.
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// 줄 높이는 따로 rowHeight(px)로 정해요.
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// 테마는 CSS 속성이에요. 그리드(또는 그 위의 어떤 요소)에 data-mxg-theme="dark" 또는 "light"를 달면
// 그 안쪽만 바뀌어요. 속성을 지우면 사이트 설정을 따라가요.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};버튼을 누르면 이 예제의 코드가 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.density(api, ($event.target as HTMLSelectElement).value)"
>
<option value="compact">촘촘하게</option>
<option value="normal" selected>보통 (기본)</option>
<option value="comfortable">넉넉하게</option>
</select>
<select
aria-label="줄 높이"
:disabled="!api"
@change="api && actions.rowHeight(api, ($event.target as HTMLSelectElement).value)"
>
<option value="28">28px</option>
<option value="32" selected>32px (기본)</option>
<option value="44">44px</option>
</select>
<select
aria-label="그리드 테마"
:disabled="!api"
@change="api && actions.theme(api, ($event.target as HTMLSelectElement).value)"
>
<option value="site" selected>사이트 따라가기 (기본)</option>
<option value="light">밝게</option>
<option value="dark">어둡게</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.rowNumbers(api)"
>줄 번호 켬/끔</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridDensity, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 320 + i * 41,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// 밀도는 그리드 옵션이에요. 세 값이 칸의 좌우 여백(4·8·12px)을 바꿔요.
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// 줄 높이는 따로 rowHeight(px)로 정해요.
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// 테마는 CSS 속성이에요. 그리드(또는 그 위의 어떤 요소)에 data-mxg-theme="dark" 또는 "light"를 달면
// 그 안쪽만 바뀌어요. 속성을 지우면 사이트 설정을 따라가요.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};버튼을 누르면 이 예제의 코드가 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.density(api, $any($event.target).value)"
>
<option value="compact">촘촘하게</option>
<option value="normal" selected>보통 (기본)</option>
<option value="comfortable">넉넉하게</option>
</select>
<select
aria-label="줄 높이"
[disabled]="!api"
(change)="api && actions.rowHeight(api, $any($event.target).value)"
>
<option value="28">28px</option>
<option value="32" selected>32px (기본)</option>
<option value="44">44px</option>
</select>
<select
aria-label="그리드 테마"
[disabled]="!api"
(change)="api && actions.theme(api, $any($event.target).value)"
>
<option value="site" selected>사이트 따라가기 (기본)</option>
<option value="light">밝게</option>
<option value="dark">어둡게</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.rowNumbers(api)"
>줄 번호 켬/끔</button>
</div>
<mx-grid style="height: 360px" [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, GridDensity, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'dept', title: '부서', width: 130 },
{
id: 'salary',
title: '월급(만원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 320 + i * 41,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// 밀도는 그리드 옵션이에요. 세 값이 칸의 좌우 여백(4·8·12px)을 바꿔요.
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// 줄 높이는 따로 rowHeight(px)로 정해요.
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// 테마는 CSS 속성이에요. 그리드(또는 그 위의 어떤 요소)에 data-mxg-theme="dark" 또는 "light"를 달면
// 그 안쪽만 바뀌어요. 속성을 지우면 사이트 설정을 따라가요.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};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="Cell padding" id="density">
<option value="compact">Compact</option>
<option value="normal" selected>Normal (default)</option>
<option value="comfortable">Comfortable</option>
</select>
<select aria-label="Row height" id="rowHeight">
<option value="28">28px</option>
<option value="32" selected>32px (default)</option>
<option value="44">44px</option>
</select>
<select aria-label="Grid theme" id="theme">
<option value="site" selected>Follow site (default)</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button type="button" id="rowNumbers">Toggle row numbers</button>
</div>
<div id="grid" style="height: 360px"></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('density').addEventListener('change', (event) => actions.density(api, event.target.value));
document.getElementById('rowHeight').addEventListener('change', (event) => actions.rowHeight(api, event.target.value));
document.getElementById('theme').addEventListener('change', (event) => actions.theme(api, event.target.value));
document.getElementById('rowNumbers').addEventListener('click', () => actions.rowNumbers(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hall',
'Ava Morgan',
'Mason Gray',
'Mia Foster',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4],
salary: 3200 + i * 410,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// Density is a grid option. The three values change the horizontal cell padding (4/8/12px).
density: (api, value) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value });
}
},
// Row height is set separately with rowHeight (px).
rowHeight: (api, value) => api.setOptions({ rowHeight: Number(value) || 32 }),
// The theme is a CSS attribute. Put data-mxg-theme="dark" or "light" on the grid (or any element above it)
// and only what is inside changes. Remove the attribute to follow the site setting.
theme: (_api, value) => {
const root = document.querySelector('.mxg');
if (!root)
return;
if (value === 'light' || value === 'dark')
root.setAttribute('data-mxg-theme', value);
else
root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api) => api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Switch the theme, cell padding and row height</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Cell padding" id="density">
<option value="compact">Compact</option>
<option value="normal" selected>Normal (default)</option>
<option value="comfortable">Comfortable</option>
</select>
<select aria-label="Row height" id="rowHeight">
<option value="28">28px</option>
<option value="32" selected>32px (default)</option>
<option value="44">44px</option>
</select>
<select aria-label="Grid theme" id="theme">
<option value="site" selected>Follow site (default)</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button type="button" id="rowNumbers">Toggle row numbers</button>
</div>
<div id="grid" style="height: 360px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hall',
'Ava Morgan',
'Mason Gray',
'Mia Foster',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4],
salary: 3200 + i * 410,
})),
rowKey: 'id',
density: 'normal',
};
const actions = {
// Density is a grid option. The three values change the horizontal cell padding (4/8/12px).
density: (api, value) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value });
}
},
// Row height is set separately with rowHeight (px).
rowHeight: (api, value) => api.setOptions({ rowHeight: Number(value) || 32 }),
// The theme is a CSS attribute. Put data-mxg-theme="dark" or "light" on the grid (or any element above it)
// and only what is inside changes. Remove the attribute to follow the site setting.
theme: (_api, value) => {
const root = document.querySelector('.mxg');
if (!root)
return;
if (value === 'light' || value === 'dark')
root.setAttribute('data-mxg-theme', value);
else
root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api) => api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};
options.ariaLabel = "Switch the theme, cell padding and row height";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('density').addEventListener('change', (event) => actions.density(api, event.target.value));
document.getElementById('rowHeight').addEventListener('change', (event) => actions.rowHeight(api, event.target.value));
document.getElementById('theme').addEventListener('change', (event) => actions.theme(api, event.target.value));
document.getElementById('rowNumbers').addEventListener('click', () => actions.rowNumbers(api));
</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="Cell padding"
disabled={!api}
onChange={(event) => api && actions.density(api, event.target.value)}
>
<option value="compact">Compact</option>
<option value="normal">Normal (default)</option>
<option value="comfortable">Comfortable</option>
</select>
<select defaultValue="normal"
aria-label="Row height"
disabled={!api}
onChange={(event) => api && actions.rowHeight(api, event.target.value)}
>
<option value="28">28px</option>
<option value="32">32px (default)</option>
<option value="44">44px</option>
</select>
<select defaultValue="32"
aria-label="Grid theme"
disabled={!api}
onChange={(event) => api && actions.theme(api, event.target.value)}
>
<option value="site">Follow site (default)</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.rowNumbers(api)}
>Toggle row numbers</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridDensity, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hall',
'Ava Morgan',
'Mason Gray',
'Mia Foster',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 3200 + i * 410,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// Density is a grid option. The three values change the horizontal cell padding (4/8/12px).
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// Row height is set separately with rowHeight (px).
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// The theme is a CSS attribute. Put data-mxg-theme="dark" or "light" on the grid (or any element above it)
// and only what is inside changes. Remove the attribute to follow the site setting.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};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="Cell padding"
:disabled="!api"
@change="api && actions.density(api, ($event.target as HTMLSelectElement).value)"
>
<option value="compact">Compact</option>
<option value="normal" selected>Normal (default)</option>
<option value="comfortable">Comfortable</option>
</select>
<select
aria-label="Row height"
:disabled="!api"
@change="api && actions.rowHeight(api, ($event.target as HTMLSelectElement).value)"
>
<option value="28">28px</option>
<option value="32" selected>32px (default)</option>
<option value="44">44px</option>
</select>
<select
aria-label="Grid theme"
:disabled="!api"
@change="api && actions.theme(api, ($event.target as HTMLSelectElement).value)"
>
<option value="site" selected>Follow site (default)</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.rowNumbers(api)"
>Toggle row numbers</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridDensity, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hall',
'Ava Morgan',
'Mason Gray',
'Mia Foster',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 3200 + i * 410,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// Density is a grid option. The three values change the horizontal cell padding (4/8/12px).
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// Row height is set separately with rowHeight (px).
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// The theme is a CSS attribute. Put data-mxg-theme="dark" or "light" on the grid (or any element above it)
// and only what is inside changes. Remove the attribute to follow the site setting.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};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="Cell padding"
[disabled]="!api"
(change)="api && actions.density(api, $any($event.target).value)"
>
<option value="compact">Compact</option>
<option value="normal" selected>Normal (default)</option>
<option value="comfortable">Comfortable</option>
</select>
<select
aria-label="Row height"
[disabled]="!api"
(change)="api && actions.rowHeight(api, $any($event.target).value)"
>
<option value="28">28px</option>
<option value="32" selected>32px (default)</option>
<option value="44">44px</option>
</select>
<select
aria-label="Grid theme"
[disabled]="!api"
(change)="api && actions.theme(api, $any($event.target).value)"
>
<option value="site" selected>Follow site (default)</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.rowNumbers(api)"
>Toggle row numbers</button>
</div>
<mx-grid style="height: 360px" [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, GridDensity, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
dept: string;
salary: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hall',
'Ava Morgan',
'Mason Gray',
'Mia Foster',
];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'dept', title: 'Dept', width: 130 },
{
id: 'salary',
title: 'Monthly pay ($)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: names.map((name, i) => ({
id: i + 1,
name,
dept: depts[i % 4] as string,
salary: 3200 + i * 410,
})),
rowKey: 'id',
density: 'normal',
};
export const actions = {
// Density is a grid option. The three values change the horizontal cell padding (4/8/12px).
density: (api: GridApi<Row>, value?: string) => {
if (value === 'compact' || value === 'normal' || value === 'comfortable') {
api.setOptions({ density: value satisfies GridDensity });
}
},
// Row height is set separately with rowHeight (px).
rowHeight: (api: GridApi<Row>, value?: string) =>
api.setOptions({ rowHeight: Number(value) || 32 }),
// The theme is a CSS attribute. Put data-mxg-theme="dark" or "light" on the grid (or any element above it)
// and only what is inside changes. Remove the attribute to follow the site setting.
theme: (_api: GridApi<Row>, value?: string) => {
const root = document.querySelector('.mxg');
if (!root) return;
if (value === 'light' || value === 'dark') root.setAttribute('data-mxg-theme', value);
else root.removeAttribute('data-mxg-theme');
},
rowNumbers: (api: GridApi<Row>) =>
api.setOptions({ showRowNumbers: !api.getOptions().showRowNumbers }),
};