줄마다 다른 높이Different row heights
우선순위가 높은 업무 줄은 크게, 낮은 줄은 작게 보여 줘요. 줄마다 높이를 다르게 정할 수 있어요.High-priority task rows are tall and low-priority rows are short. Each row can have its own height.
코드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">
<button type="button" id="taller">높음 키우기</button>
<button type="button" id="shorter">높음 줄이기</button>
</div>
<div id="grid" style="height: 420px"></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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));const titles = [
'로그인 이동 오류 수정',
'가격 페이지 갱신',
'데이터베이스 이전',
'배포 노트 작성',
'코드 검토',
'다음 스프린트 계획',
'오래된 티켓 정리',
'백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row) => row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
export const options = {
columns: [
{ id: 'title', title: '업무', width: 190 },
{ id: 'priority', title: '우선순위', width: 90 },
{
id: 'height',
title: '줄 높이(px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length],
priority: ['높음', '보통', '낮음', '보통'][i % 4],
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say = () => { };
export function setup(_api, log) {
tall = 64;
say = log;
log({
ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
en: 'High priority rows are 64px, normal 40px, low 28px.',
});
}
export const actions = {
// 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
taller: (api) => {
tall += 16;
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
},
shorter: (api) => {
tall = Math.max(32, tall - 16);
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>줄마다 다른 높이</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="taller">높음 키우기</button>
<button type="button" id="shorter">높음 줄이기</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const titles = [
'로그인 이동 오류 수정',
'가격 페이지 갱신',
'데이터베이스 이전',
'배포 노트 작성',
'코드 검토',
'다음 스프린트 계획',
'오래된 티켓 정리',
'백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row) => row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
const options = {
columns: [
{ id: 'title', title: '업무', width: 190 },
{ id: 'priority', title: '우선순위', width: 90 },
{
id: 'height',
title: '줄 높이(px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length],
priority: ['높음', '보통', '낮음', '보통'][i % 4],
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say = () => { };
function setup(_api, log) {
tall = 64;
say = log;
log({
ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
en: 'High priority rows are 64px, normal 40px, low 28px.',
});
}
const actions = {
// 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
taller: (api) => {
tall += 16;
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
},
shorter: (api) => {
tall = Math.max(32, tall - 16);
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
},
};
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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.taller(api)}
>높음 키우기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shorter(api)}
>높음 줄이기</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: '높음' | '보통' | '낮음';
}
const titles = [
'로그인 이동 오류 수정',
'가격 페이지 갱신',
'데이터베이스 이전',
'배포 노트 작성',
'코드 검토',
'다음 스프린트 계획',
'오래된 티켓 정리',
'백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row: Row): number =>
row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '업무', width: 190 },
{ id: 'priority', title: '우선순위', width: 90 },
{
id: 'height',
title: '줄 높이(px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['높음', '보통', '낮음', '보통'] as const)[i % 4] as '높음' | '보통' | '낮음',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log({
ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
en: 'High priority rows are 64px, normal 40px, low 28px.',
});
}
export const actions = {
// 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.taller(api)">높음 키우기</button>
<button type="button" :disabled="!api" @click="api && actions.shorter(api)">높음 줄이기</button>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: '높음' | '보통' | '낮음';
}
const titles = [
'로그인 이동 오류 수정',
'가격 페이지 갱신',
'데이터베이스 이전',
'배포 노트 작성',
'코드 검토',
'다음 스프린트 계획',
'오래된 티켓 정리',
'백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row: Row): number =>
row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '업무', width: 190 },
{ id: 'priority', title: '우선순위', width: 90 },
{
id: 'height',
title: '줄 높이(px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['높음', '보통', '낮음', '보통'] as const)[i % 4] as '높음' | '보통' | '낮음',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log({
ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
en: 'High priority rows are 64px, normal 40px, low 28px.',
});
}
export const actions = {
// 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.taller(api)"
>높음 키우기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shorter(api)"
>높음 줄이기</button>
</div>
<mx-grid style="height: 420px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: '높음' | '보통' | '낮음';
}
const titles = [
'로그인 이동 오류 수정',
'가격 페이지 갱신',
'데이터베이스 이전',
'배포 노트 작성',
'코드 검토',
'다음 스프린트 계획',
'오래된 티켓 정리',
'백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row: Row): number =>
row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: '업무', width: 190 },
{ id: 'priority', title: '우선순위', width: 90 },
{
id: 'height',
title: '줄 높이(px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['높음', '보통', '낮음', '보통'] as const)[i % 4] as '높음' | '보통' | '낮음',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log({
ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
en: 'High priority rows are 64px, normal 40px, low 28px.',
});
}
export const actions = {
// 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="taller">Taller high rows</button>
<button type="button" id="shorter">Shorter high rows</button>
</div>
<div id="grid" style="height: 420px"></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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));const titles = [
'Fix login redirect bug',
'Update pricing page',
'Migrate the database',
'Write release notes',
'Code review',
'Plan the next sprint',
'Clean up old tickets',
'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row) => row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
export const options = {
columns: [
{ id: 'title', title: 'Task', width: 190 },
{ id: 'priority', title: 'Priority', width: 90 },
{
id: 'height',
title: 'Row height (px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length],
priority: ['High', 'Normal', 'Low', 'Normal'][i % 4],
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say = () => { };
export function setup(_api, log) {
tall = 64;
say = log;
log('High priority rows are 64px, normal 40px, low 28px.');
}
export const actions = {
// The function reads an outside value, so the grid must be told to measure again.
taller: (api) => {
tall += 16;
api.refresh();
say(`High rows enlarged to ${tall}px.`);
},
shorter: (api) => {
tall = Math.max(32, tall - 16);
api.refresh();
say(`High rows reduced to ${tall}px.`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Different row heights</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="taller">Taller high rows</button>
<button type="button" id="shorter">Shorter high rows</button>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const titles = [
'Fix login redirect bug',
'Update pricing page',
'Migrate the database',
'Write release notes',
'Code review',
'Plan the next sprint',
'Clean up old tickets',
'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row) => row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
const options = {
columns: [
{ id: 'title', title: 'Task', width: 190 },
{ id: 'priority', title: 'Priority', width: 90 },
{
id: 'height',
title: 'Row height (px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length],
priority: ['High', 'Normal', 'Low', 'Normal'][i % 4],
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say = () => { };
function setup(_api, log) {
tall = 64;
say = log;
log('High priority rows are 64px, normal 40px, low 28px.');
}
const actions = {
// The function reads an outside value, so the grid must be told to measure again.
taller: (api) => {
tall += 16;
api.refresh();
say(`High rows enlarged to ${tall}px.`);
},
shorter: (api) => {
tall = Math.max(32, tall - 16);
api.refresh();
say(`High rows reduced to ${tall}px.`);
},
};
options.ariaLabel = "Different row heights";
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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.taller(api)}
>Taller high rows</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shorter(api)}
>Shorter high rows</button>
</div>
<Grid style={{ height: 420 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: 'High' | 'Normal' | 'Low';
}
const titles = [
'Fix login redirect bug',
'Update pricing page',
'Migrate the database',
'Write release notes',
'Code review',
'Plan the next sprint',
'Clean up old tickets',
'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row: Row): number =>
row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Task', width: 190 },
{ id: 'priority', title: 'Priority', width: 90 },
{
id: 'height',
title: 'Row height (px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['High', 'Normal', 'Low', 'Normal'] as const)[i % 4] as 'High' | 'Normal' | 'Low',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log('High priority rows are 64px, normal 40px, low 28px.');
}
export const actions = {
// The function reads an outside value, so the grid must be told to measure again.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say(`High rows enlarged to ${tall}px.`);
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say(`High rows reduced to ${tall}px.`);
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.taller(api)">Taller high rows</button>
<button type="button" :disabled="!api" @click="api && actions.shorter(api)">Shorter high rows</button>
</div>
<Grid style="height: 420px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: 'High' | 'Normal' | 'Low';
}
const titles = [
'Fix login redirect bug',
'Update pricing page',
'Migrate the database',
'Write release notes',
'Code review',
'Plan the next sprint',
'Clean up old tickets',
'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row: Row): number =>
row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Task', width: 190 },
{ id: 'priority', title: 'Priority', width: 90 },
{
id: 'height',
title: 'Row height (px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['High', 'Normal', 'Low', 'Normal'] as const)[i % 4] as 'High' | 'Normal' | 'Low',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log('High priority rows are 64px, normal 40px, low 28px.');
}
export const actions = {
// The function reads an outside value, so the grid must be told to measure again.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say(`High rows enlarged to ${tall}px.`);
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say(`High rows reduced to ${tall}px.`);
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.taller(api)"
>Taller high rows</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shorter(api)"
>Shorter high rows</button>
</div>
<mx-grid style="height: 420px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
priority: 'High' | 'Normal' | 'Low';
}
const titles = [
'Fix login redirect bug',
'Update pricing page',
'Migrate the database',
'Write release notes',
'Code review',
'Plan the next sprint',
'Clean up old tickets',
'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row: Row): number =>
row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Task', width: 190 },
{ id: 'priority', title: 'Priority', width: 90 },
{
id: 'height',
title: 'Row height (px)',
kind: 'number',
width: 100,
align: 'end',
getValue: (row) => heightOf(row),
},
],
rows: Array.from({ length: 8 }, (_, i) => ({
id: i + 1,
title: titles[i % titles.length] as string,
priority: (['High', 'Normal', 'Low', 'Normal'] as const)[i % 4] as 'High' | 'Normal' | 'Low',
})),
rowKey: 'id',
rowHeight: heightOf,
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
tall = 64;
say = log;
log('High priority rows are 64px, normal 40px, low 28px.');
}
export const actions = {
// The function reads an outside value, so the grid must be told to measure again.
taller: (api: GridApi<Row>) => {
tall += 16;
api.refresh();
say(`High rows enlarged to ${tall}px.`);
},
shorter: (api: GridApi<Row>) => {
tall = Math.max(32, tall - 16);
api.refresh();
say(`High rows reduced to ${tall}px.`);
},
};