10만 줄 트리: 펼치기·찾아가기·검색A 100,000-row tree: expand, jump and search
지역·거점·장비 10만 줄 트리를 열고 접고, 한 장비로 곧바로 찾아가고, 이름으로 검색해요. 보이는 줄만 그려서 많아도 가벼워요.Expand and collapse a 100,000-row region/site/device tree, jump to one device and search by name. Only visible rows are drawn.
코드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="sites">거점까지 펼치기</button>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
<button type="button" id="deep">50,000번째 줄로 가기</button>
<input
type="text"
aria-label="검색"
placeholder="이름 검색 (예: 장비 3-7)"
id="find"
/>
</div>
<div id="grid" style="height: 330px"></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('sites').addEventListener('click', () => actions.sites(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('deep').addEventListener('click', () => actions.deep(api));
document.getElementById('find').addEventListener('input', (event) => actions.find(api, event.target.value));// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word) => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0)
return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0;
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word) => (batchim(word) ? '을' : '를');
// 지역 20곳 × 거점 50곳 × 장비 99대 = 약 10만 줄이에요. 그리드는 보이는 줄만 그려서 많아도 가벼워요.
const regions = [
'서울',
'부산',
'대구',
'인천',
'광주',
'대전',
'울산',
'세종',
'수원',
'성남',
'고양',
'용인',
'창원',
'청주',
'전주',
'천안',
'포항',
'제주',
'춘천',
'목포',
];
const rows = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({ id: regionId, parentId: null, name: `${regions[r]} 지역`, kind: '지역', value: r });
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} ${s + 1}호 센터`,
kind: '거점',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `장비 ${r + 1}-${s + 1}-${d + 1}`,
kind: '장비',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options = {
columns: [
{ id: 'name', title: '이름', width: 240 },
{ id: 'kind', title: '구분', width: 80 },
{ id: 'value', title: '측정값', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 불러왔어요. 지금은 지역 20곳만 보여요.`,
en: `Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`,
});
}
export const actions = {
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
sites: (api) => {
api.expandToDepth(1);
say({
ko: `거점까지 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개`,
en: `Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
});
},
collapseAll: (api) => {
api.collapseAll();
say({ ko: '모두 접었어요.', en: 'Collapsed all.' });
},
// 위 단계를 모두 펼친 다음 그 줄로 스크롤해요.
deep: (api) => {
const row = api.getRowByKey(50_000);
// 찾기로 가려져 있으면 그 줄로 갈 수 없어서(오류), 먼저 찾기를 지워요.
if (api.getFilterModel() !== null)
api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row)
say({ ko: `${row.name}${eulReul(row.name)} 찾아갔어요.`, en: `Went to ${row.name}.` });
},
find: (api, value) => {
const text = (value ?? '').trim();
api.setFilterModel(text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null);
const found = api.getVisibleRowCount().toLocaleString('ko-KR');
say({
ko: text ? `"${text}" 찾기: ${found}개 줄이 보여요.` : '찾기를 지웠어요.',
en: text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.',
});
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>10만 줄 트리: 펼치기·찾아가기·검색</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="sites">거점까지 펼치기</button>
<button type="button" id="expandAll">모두 펼치기</button>
<button type="button" id="collapseAll">모두 접기</button>
<button type="button" id="deep">50,000번째 줄로 가기</button>
<input
type="text"
aria-label="검색"
placeholder="이름 검색 (예: 장비 3-7)"
id="find"
/>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word) => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0)
return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0;
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word) => (batchim(word) ? '을' : '를');
// 지역 20곳 × 거점 50곳 × 장비 99대 = 약 10만 줄이에요. 그리드는 보이는 줄만 그려서 많아도 가벼워요.
const regions = [
'서울',
'부산',
'대구',
'인천',
'광주',
'대전',
'울산',
'세종',
'수원',
'성남',
'고양',
'용인',
'창원',
'청주',
'전주',
'천안',
'포항',
'제주',
'춘천',
'목포',
];
const rows = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({ id: regionId, parentId: null, name: `${regions[r]} 지역`, kind: '지역', value: r });
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} ${s + 1}호 센터`,
kind: '거점',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `장비 ${r + 1}-${s + 1}-${d + 1}`,
kind: '장비',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
const options = {
columns: [
{ id: 'name', title: '이름', width: 240 },
{ id: 'kind', title: '구분', width: 80 },
{ id: 'value', title: '측정값', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say = () => { };
function setup(_api, log) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 불러왔어요. 지금은 지역 20곳만 보여요.`,
en: `Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`,
});
}
const actions = {
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
sites: (api) => {
api.expandToDepth(1);
say({
ko: `거점까지 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개`,
en: `Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
});
},
collapseAll: (api) => {
api.collapseAll();
say({ ko: '모두 접었어요.', en: 'Collapsed all.' });
},
// 위 단계를 모두 펼친 다음 그 줄로 스크롤해요.
deep: (api) => {
const row = api.getRowByKey(50_000);
// 찾기로 가려져 있으면 그 줄로 갈 수 없어서(오류), 먼저 찾기를 지워요.
if (api.getFilterModel() !== null)
api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row)
say({ ko: `${row.name}${eulReul(row.name)} 찾아갔어요.`, en: `Went to ${row.name}.` });
},
find: (api, value) => {
const text = (value ?? '').trim();
api.setFilterModel(text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null);
const found = api.getVisibleRowCount().toLocaleString('ko-KR');
say({
ko: text ? `"${text}" 찾기: ${found}개 줄이 보여요.` : '찾기를 지웠어요.',
en: text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.',
});
},
};
options.ariaLabel = "10만 줄 트리: 펼치기·찾아가기·검색";
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('sites').addEventListener('click', () => actions.sites(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('deep').addEventListener('click', () => actions.deep(api));
document.getElementById('find').addEventListener('input', (event) => actions.find(api, event.target.value));
</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.sites(api)}
>거점까지 펼치기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>모두 펼치기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>모두 접기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.deep(api)}
>50,000번째 줄로 가기</button>
<input
type="text"
aria-label="검색"
placeholder="이름 검색 (예: 장비 3-7)"
disabled={!api}
onChange={(event) => api && actions.find(api, event.target.value)}
/>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0;
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
// 지역 20곳 × 거점 50곳 × 장비 99대 = 약 10만 줄이에요. 그리드는 보이는 줄만 그려서 많아도 가벼워요.
const regions = [
'서울',
'부산',
'대구',
'인천',
'광주',
'대전',
'울산',
'세종',
'수원',
'성남',
'고양',
'용인',
'창원',
'청주',
'전주',
'천안',
'포항',
'제주',
'춘천',
'목포',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({ id: regionId, parentId: null, name: `${regions[r]} 지역`, kind: '지역', value: r });
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} ${s + 1}호 센터`,
kind: '거점',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `장비 ${r + 1}-${s + 1}-${d + 1}`,
kind: '장비',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 240 },
{ id: 'kind', title: '구분', width: 80 },
{ id: 'value', title: '측정값', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 불러왔어요. 지금은 지역 20곳만 보여요.`,
en: `Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`,
});
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say({
ko: `거점까지 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개`,
en: `Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
});
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say({ ko: '모두 접었어요.', en: 'Collapsed all.' });
},
// 위 단계를 모두 펼친 다음 그 줄로 스크롤해요.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// 찾기로 가려져 있으면 그 줄로 갈 수 없어서(오류), 먼저 찾기를 지워요.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say({ ko: `${row.name}${eulReul(row.name)} 찾아갔어요.`, en: `Went to ${row.name}.` });
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('ko-KR');
say({
ko: text ? `"${text}" 찾기: ${found}개 줄이 보여요.` : '찾기를 지웠어요.',
en: text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.',
});
},
};버튼을 누르면 이 예제의 코드가 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.sites(api)">거점까지 펼치기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>모두 접기</button>
<button type="button" :disabled="!api" @click="api && actions.deep(api)">50,000번째 줄로 가기</button>
<input
type="text"
aria-label="검색"
placeholder="이름 검색 (예: 장비 3-7)"
:disabled="!api"
@input="api && actions.find(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 330px" :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;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0;
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
// 지역 20곳 × 거점 50곳 × 장비 99대 = 약 10만 줄이에요. 그리드는 보이는 줄만 그려서 많아도 가벼워요.
const regions = [
'서울',
'부산',
'대구',
'인천',
'광주',
'대전',
'울산',
'세종',
'수원',
'성남',
'고양',
'용인',
'창원',
'청주',
'전주',
'천안',
'포항',
'제주',
'춘천',
'목포',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({ id: regionId, parentId: null, name: `${regions[r]} 지역`, kind: '지역', value: r });
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} ${s + 1}호 센터`,
kind: '거점',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `장비 ${r + 1}-${s + 1}-${d + 1}`,
kind: '장비',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 240 },
{ id: 'kind', title: '구분', width: 80 },
{ id: 'value', title: '측정값', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 불러왔어요. 지금은 지역 20곳만 보여요.`,
en: `Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`,
});
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say({
ko: `거점까지 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개`,
en: `Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
});
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say({ ko: '모두 접었어요.', en: 'Collapsed all.' });
},
// 위 단계를 모두 펼친 다음 그 줄로 스크롤해요.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// 찾기로 가려져 있으면 그 줄로 갈 수 없어서(오류), 먼저 찾기를 지워요.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say({ ko: `${row.name}${eulReul(row.name)} 찾아갔어요.`, en: `Went to ${row.name}.` });
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('ko-KR');
say({
ko: text ? `"${text}" 찾기: ${found}개 줄이 보여요.` : '찾기를 지웠어요.',
en: text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.',
});
},
};버튼을 누르면 이 예제의 코드가 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.sites(api)"
>거점까지 펼치기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>모두 펼치기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>모두 접기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.deep(api)"
>50,000번째 줄로 가기</button>
<input
type="text"
aria-label="검색"
placeholder="이름 검색 (예: 장비 3-7)"
[disabled]="!api"
(input)="api && actions.find(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 330px" [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;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0;
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
// 지역 20곳 × 거점 50곳 × 장비 99대 = 약 10만 줄이에요. 그리드는 보이는 줄만 그려서 많아도 가벼워요.
const regions = [
'서울',
'부산',
'대구',
'인천',
'광주',
'대전',
'울산',
'세종',
'수원',
'성남',
'고양',
'용인',
'창원',
'청주',
'전주',
'천안',
'포항',
'제주',
'춘천',
'목포',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({ id: regionId, parentId: null, name: `${regions[r]} 지역`, kind: '지역', value: r });
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} ${s + 1}호 센터`,
kind: '거점',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `장비 ${r + 1}-${s + 1}-${d + 1}`,
kind: '장비',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 240 },
{ id: 'kind', title: '구분', width: 80 },
{ id: 'value', title: '측정값', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `${rows.length.toLocaleString('ko-KR')}줄을 불러왔어요. 지금은 지역 20곳만 보여요.`,
en: `Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`,
});
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say({
ko: `모두 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개 (${Math.round(performance.now() - started)}ms)`,
en: `Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
});
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say({
ko: `거점까지 펼쳤어요. 보이는 줄 ${api.getVisibleRowCount().toLocaleString('ko-KR')}개`,
en: `Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
});
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say({ ko: '모두 접었어요.', en: 'Collapsed all.' });
},
// 위 단계를 모두 펼친 다음 그 줄로 스크롤해요.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// 찾기로 가려져 있으면 그 줄로 갈 수 없어서(오류), 먼저 찾기를 지워요.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say({ ko: `${row.name}${eulReul(row.name)} 찾아갔어요.`, en: `Went to ${row.name}.` });
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('ko-KR');
say({
ko: text ? `"${text}" 찾기: ${found}개 줄이 보여요.` : '찾기를 지웠어요.',
en: text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.',
});
},
};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="sites">Expand to sites</button>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
<button type="button" id="deep">Jump to row 50,000</button>
<input
type="text"
aria-label="Search"
placeholder="Search by name (e.g. Device 3-7)"
id="find"
/>
</div>
<div id="grid" style="height: 330px"></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('sites').addEventListener('click', () => actions.sites(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('deep').addEventListener('click', () => actions.deep(api));
document.getElementById('find').addEventListener('input', (event) => actions.find(api, event.target.value));// 20 regions x 50 sites x 99 devices = about 100,000 rows. The grid only draws the visible rows, so it stays light even with this many.
const regions = [
'New York',
'Boston',
'Chicago',
'Houston',
'Phoenix',
'Denver',
'Seattle',
'Portland',
'Austin',
'Dallas',
'Atlanta',
'Miami',
'Detroit',
'Memphis',
'Orlando',
'Nashville',
'Raleigh',
'Honolulu',
'Madison',
'Tucson',
];
const rows = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({
id: regionId,
parentId: null,
name: `${regions[r]} Region`,
kind: 'Region',
value: r,
});
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} Center ${s + 1}`,
kind: 'Site',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `Device ${r + 1}-${s + 1}-${d + 1}`,
kind: 'Device',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 240 },
{ id: 'kind', title: 'Type', width: 80 },
{ id: 'value', title: 'Reading', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say = () => { };
export function setup(_api, log) {
say = log;
log(`Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`);
}
export const actions = {
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say(`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`);
},
sites: (api) => {
api.expandToDepth(1);
say(`Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`);
},
collapseAll: (api) => {
api.collapseAll();
say('Collapsed all.');
},
// Open all the ancestors, then scroll to that row.
deep: (api) => {
const row = api.getRowByKey(50_000);
// A row hidden by the search cannot be reached (it throws), so clear the search first.
if (api.getFilterModel() !== null)
api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row)
say(`Went to ${row.name}.`);
},
find: (api, value) => {
const text = (value ?? '').trim();
api.setFilterModel(text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null);
const found = api.getVisibleRowCount().toLocaleString('en-US');
say(text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A 100,000-row tree: expand, jump and search</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="sites">Expand to sites</button>
<button type="button" id="expandAll">Expand all</button>
<button type="button" id="collapseAll">Collapse all</button>
<button type="button" id="deep">Jump to row 50,000</button>
<input
type="text"
aria-label="Search"
placeholder="Search by name (e.g. Device 3-7)"
id="find"
/>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 20 regions x 50 sites x 99 devices = about 100,000 rows. The grid only draws the visible rows, so it stays light even with this many.
const regions = [
'New York',
'Boston',
'Chicago',
'Houston',
'Phoenix',
'Denver',
'Seattle',
'Portland',
'Austin',
'Dallas',
'Atlanta',
'Miami',
'Detroit',
'Memphis',
'Orlando',
'Nashville',
'Raleigh',
'Honolulu',
'Madison',
'Tucson',
];
const rows = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({
id: regionId,
parentId: null,
name: `${regions[r]} Region`,
kind: 'Region',
value: r,
});
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} Center ${s + 1}`,
kind: 'Site',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `Device ${r + 1}-${s + 1}-${d + 1}`,
kind: 'Device',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
const options = {
columns: [
{ id: 'name', title: 'Name', width: 240 },
{ id: 'kind', title: 'Type', width: 80 },
{ id: 'value', title: 'Reading', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say = () => { };
function setup(_api, log) {
say = log;
log(`Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`);
}
const actions = {
expandAll: (api) => {
const started = performance.now();
api.expandAll();
say(`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`);
},
sites: (api) => {
api.expandToDepth(1);
say(`Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`);
},
collapseAll: (api) => {
api.collapseAll();
say('Collapsed all.');
},
// Open all the ancestors, then scroll to that row.
deep: (api) => {
const row = api.getRowByKey(50_000);
// A row hidden by the search cannot be reached (it throws), so clear the search first.
if (api.getFilterModel() !== null)
api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row)
say(`Went to ${row.name}.`);
},
find: (api, value) => {
const text = (value ?? '').trim();
api.setFilterModel(text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null);
const found = api.getVisibleRowCount().toLocaleString('en-US');
say(text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.');
},
};
options.ariaLabel = "A 100,000-row tree: expand, jump and search";
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('sites').addEventListener('click', () => actions.sites(api));
document.getElementById('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
document.getElementById('deep').addEventListener('click', () => actions.deep(api));
document.getElementById('find').addEventListener('input', (event) => actions.find(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 { 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.sites(api)}
>Expand to sites</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.expandAll(api)}
>Expand all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.collapseAll(api)}
>Collapse all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.deep(api)}
>Jump to row 50,000</button>
<input
type="text"
aria-label="Search"
placeholder="Search by name (e.g. Device 3-7)"
disabled={!api}
onChange={(event) => api && actions.find(api, event.target.value)}
/>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 20 regions x 50 sites x 99 devices = about 100,000 rows. The grid only draws the visible rows, so it stays light even with this many.
const regions = [
'New York',
'Boston',
'Chicago',
'Houston',
'Phoenix',
'Denver',
'Seattle',
'Portland',
'Austin',
'Dallas',
'Atlanta',
'Miami',
'Detroit',
'Memphis',
'Orlando',
'Nashville',
'Raleigh',
'Honolulu',
'Madison',
'Tucson',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({
id: regionId,
parentId: null,
name: `${regions[r]} Region`,
kind: 'Region',
value: r,
});
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} Center ${s + 1}`,
kind: 'Site',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `Device ${r + 1}-${s + 1}-${d + 1}`,
kind: 'Device',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 240 },
{ id: 'kind', title: 'Type', width: 80 },
{ id: 'value', title: 'Reading', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`);
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say(
`Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
);
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say('Collapsed all.');
},
// Open all the ancestors, then scroll to that row.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// A row hidden by the search cannot be reached (it throws), so clear the search first.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say(`Went to ${row.name}.`);
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('en-US');
say(text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.');
},
};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.sites(api)">Expand to sites</button>
<button
type="button"
:disabled="!api"
@click="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
:disabled="!api"
@click="api && actions.collapseAll(api)"
>Collapse all</button>
<button type="button" :disabled="!api" @click="api && actions.deep(api)">Jump to row 50,000</button>
<input
type="text"
aria-label="Search"
placeholder="Search by name (e.g. Device 3-7)"
:disabled="!api"
@input="api && actions.find(api, ($event.target as HTMLInputElement).value)"
/>
</div>
<Grid style="height: 330px" :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;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 20 regions x 50 sites x 99 devices = about 100,000 rows. The grid only draws the visible rows, so it stays light even with this many.
const regions = [
'New York',
'Boston',
'Chicago',
'Houston',
'Phoenix',
'Denver',
'Seattle',
'Portland',
'Austin',
'Dallas',
'Atlanta',
'Miami',
'Detroit',
'Memphis',
'Orlando',
'Nashville',
'Raleigh',
'Honolulu',
'Madison',
'Tucson',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({
id: regionId,
parentId: null,
name: `${regions[r]} Region`,
kind: 'Region',
value: r,
});
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} Center ${s + 1}`,
kind: 'Site',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `Device ${r + 1}-${s + 1}-${d + 1}`,
kind: 'Device',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 240 },
{ id: 'kind', title: 'Type', width: 80 },
{ id: 'value', title: 'Reading', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`);
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say(
`Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
);
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say('Collapsed all.');
},
// Open all the ancestors, then scroll to that row.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// A row hidden by the search cannot be reached (it throws), so clear the search first.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say(`Went to ${row.name}.`);
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('en-US');
say(text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.');
},
};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.sites(api)"
>Expand to sites</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.expandAll(api)"
>Expand all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.collapseAll(api)"
>Collapse all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.deep(api)"
>Jump to row 50,000</button>
<input
type="text"
aria-label="Search"
placeholder="Search by name (e.g. Device 3-7)"
[disabled]="!api"
(input)="api && actions.find(api, $any($event.target).value)"
/>
</div>
<mx-grid style="height: 330px" [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;
parentId: number | null;
name: string;
kind: string;
value: number;
}
// 20 regions x 50 sites x 99 devices = about 100,000 rows. The grid only draws the visible rows, so it stays light even with this many.
const regions = [
'New York',
'Boston',
'Chicago',
'Houston',
'Phoenix',
'Denver',
'Seattle',
'Portland',
'Austin',
'Dallas',
'Atlanta',
'Miami',
'Detroit',
'Memphis',
'Orlando',
'Nashville',
'Raleigh',
'Honolulu',
'Madison',
'Tucson',
];
const rows: Row[] = [];
for (let r = 0; r < 20; r++) {
const regionId = rows.length + 1;
rows.push({
id: regionId,
parentId: null,
name: `${regions[r]} Region`,
kind: 'Region',
value: r,
});
for (let s = 0; s < 50; s++) {
const siteId = rows.length + 1;
rows.push({
id: siteId,
parentId: regionId,
name: `${regions[r]} Center ${s + 1}`,
kind: 'Site',
value: s,
});
for (let d = 0; d < 99; d++) {
rows.push({
id: rows.length + 1,
parentId: siteId,
name: `Device ${r + 1}-${s + 1}-${d + 1}`,
kind: 'Device',
value: (r * 31 + s * 17 + d * 7) % 1000,
});
}
}
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 240 },
{ id: 'kind', title: 'Type', width: 80 },
{ id: 'value', title: 'Reading', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 0 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`Loaded ${rows.length.toLocaleString('en-US')} rows. Only 20 regions show for now.`);
}
export const actions = {
expandAll: (api: GridApi<Row>) => {
const started = performance.now();
api.expandAll();
say(
`Expanded all. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible (${Math.round(performance.now() - started)}ms)`,
);
},
sites: (api: GridApi<Row>) => {
api.expandToDepth(1);
say(
`Expanded down to the sites. ${api.getVisibleRowCount().toLocaleString('en-US')} rows visible`,
);
},
collapseAll: (api: GridApi<Row>) => {
api.collapseAll();
say('Collapsed all.');
},
// Open all the ancestors, then scroll to that row.
deep: (api: GridApi<Row>) => {
const row = api.getRowByKey(50_000);
// A row hidden by the search cannot be reached (it throws), so clear the search first.
if (api.getFilterModel() !== null) api.setFilterModel(null);
api.revealRow(50_000);
api.scrollToIndex(api.getVisibleIndexOfKey(50_000));
if (row) say(`Went to ${row.name}.`);
},
find: (api: GridApi<Row>, value?: string) => {
const text = (value ?? '').trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
const found = api.getVisibleRowCount().toLocaleString('en-US');
say(text ? `Search "${text}": ${found} rows visible.` : 'Search cleared.');
},
};