10만 행과 100만 행 비교하기Compare 100,000 and 1,000,000 rows
화면에 보이는 줄만 그리기 때문에 10만 행이든 100만 행이든 스크롤은 부드러워요. 크기를 바꿔 행을 넣고, 정렬·필터에 걸리는 시간을 내 컴퓨터에서 직접 재서 비교해 보세요.Only the rows on screen are drawn, so scrolling stays smooth at 100,000 or 1,000,000 rows. Switch the size and measure sorting and filtering on your own machine.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="행 수" id="size">
<option value="100000" selected>10만 행 (기본)</option>
<option value="1000000">100만 행</option>
</select>
<button type="button" id="sortAmount">금액 정렬</button>
<button type="button" id="filterSeoul">서울만 보기</button>
<button type="button" id="reset">정렬·필터 풀기</button>
<button type="button" id="bottom">맨 아래로</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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
document.getElementById('sortAmount').addEventListener('click', () => actions.sortAmount(api));
document.getElementById('filterSeoul').addEventListener('click', () => actions.filterSeoul(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
document.getElementById('bottom').addEventListener('click', () => actions.bottom(api));const REGIONS = ['서울', '경기', '부산', '대구'];
function makeRows(count) {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `고객 ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// 화면에 보이는 줄만 그리기 때문에, 10만 행이든 100만 행이든 스크롤은 같은 속도예요.
export const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: '고객', width: 170 },
{ id: 'region', title: '지역', width: 100 },
{
id: 'amount',
title: '금액(천원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({ ko: '100,000행을 불러왔어요', en: 'Loaded 100,000 rows' });
return () => {
say = () => { };
};
}
const n = (value) => value.toLocaleString('ko-KR');
// 시간은 지금 쓰는 컴퓨터와 브라우저에서 잰 값이에요. 두 크기를 서로 비교해 보세요.
const timed = (run, api) => {
const start = performance.now();
const result = run();
// 정렬·필터는 보이는 행을 구할 때 계산되기 때문에, 첫 줄을 읽어서 계산이 끝난 뒤의 시간을 재요.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api, value) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say({
ko: `${n(count)}행: 만드는 데 ${generate}, 화면에 넣는 데 ${load}`,
en: `${n(count)} rows: ${generate} to create, ${load} to put on screen`,
});
},
sortAmount: (api) => {
const [, took] = timed(() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]), api);
say({ ko: `금액 정렬: ${took}`, en: `Sort by amount: ${took}` });
},
filterSeoul: (api) => {
const [, took] = timed(() => api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: '서울' }],
}), api);
say({
ko: `지역이 서울인 행만: ${took}, ${n(api.getVisibleRowCount())}행`,
en: `Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`,
});
},
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
say({ ko: '정렬과 필터를 풀었어요', en: 'Sort and filter cleared' });
},
bottom: (api) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0)
api.scrollToIndex(last);
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>10만 행과 100만 행 비교하기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="행 수" id="size">
<option value="100000" selected>10만 행 (기본)</option>
<option value="1000000">100만 행</option>
</select>
<button type="button" id="sortAmount">금액 정렬</button>
<button type="button" id="filterSeoul">서울만 보기</button>
<button type="button" id="reset">정렬·필터 풀기</button>
<button type="button" id="bottom">맨 아래로</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 REGIONS = ['서울', '경기', '부산', '대구'];
function makeRows(count) {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `고객 ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// 화면에 보이는 줄만 그리기 때문에, 10만 행이든 100만 행이든 스크롤은 같은 속도예요.
const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: '고객', width: 170 },
{ id: 'region', title: '지역', width: 100 },
{
id: 'amount',
title: '금액(천원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
log({ ko: '100,000행을 불러왔어요', en: 'Loaded 100,000 rows' });
return () => {
say = () => { };
};
}
const n = (value) => value.toLocaleString('ko-KR');
// 시간은 지금 쓰는 컴퓨터와 브라우저에서 잰 값이에요. 두 크기를 서로 비교해 보세요.
const timed = (run, api) => {
const start = performance.now();
const result = run();
// 정렬·필터는 보이는 행을 구할 때 계산되기 때문에, 첫 줄을 읽어서 계산이 끝난 뒤의 시간을 재요.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
const actions = {
size: (api, value) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say({
ko: `${n(count)}행: 만드는 데 ${generate}, 화면에 넣는 데 ${load}`,
en: `${n(count)} rows: ${generate} to create, ${load} to put on screen`,
});
},
sortAmount: (api) => {
const [, took] = timed(() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]), api);
say({ ko: `금액 정렬: ${took}`, en: `Sort by amount: ${took}` });
},
filterSeoul: (api) => {
const [, took] = timed(() => api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: '서울' }],
}), api);
say({
ko: `지역이 서울인 행만: ${took}, ${n(api.getVisibleRowCount())}행`,
en: `Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`,
});
},
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
say({ ko: '정렬과 필터를 풀었어요', en: 'Sort and filter cleared' });
},
bottom: (api) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0)
api.scrollToIndex(last);
},
};
options.ariaLabel = "10만 행과 100만 행 비교하기";
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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
document.getElementById('sortAmount').addEventListener('click', () => actions.sortAmount(api));
document.getElementById('filterSeoul').addEventListener('click', () => actions.filterSeoul(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
document.getElementById('bottom').addEventListener('click', () => actions.bottom(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">
<select
aria-label="행 수"
disabled={!api}
onChange={(event) => api && actions.size(api, event.target.value)}
>
<option value="100000">10만 행 (기본)</option>
<option value="1000000">100만 행</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortAmount(api)}
>금액 정렬</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filterSeoul(api)}
>서울만 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>정렬·필터 풀기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.bottom(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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['서울', '경기', '부산', '대구'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `고객 ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// 화면에 보이는 줄만 그리기 때문에, 10만 행이든 100만 행이든 스크롤은 같은 속도예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: '고객', width: 170 },
{ id: 'region', title: '지역', width: 100 },
{
id: 'amount',
title: '금액(천원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({ ko: '100,000행을 불러왔어요', en: 'Loaded 100,000 rows' });
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('ko-KR');
// 시간은 지금 쓰는 컴퓨터와 브라우저에서 잰 값이에요. 두 크기를 서로 비교해 보세요.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// 정렬·필터는 보이는 행을 구할 때 계산되기 때문에, 첫 줄을 읽어서 계산이 끝난 뒤의 시간을 재요.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say({
ko: `${n(count)}행: 만드는 데 ${generate}, 화면에 넣는 데 ${load}`,
en: `${n(count)} rows: ${generate} to create, ${load} to put on screen`,
});
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say({ ko: `금액 정렬: ${took}`, en: `Sort by amount: ${took}` });
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: '서울' }],
}),
api,
);
say({
ko: `지역이 서울인 행만: ${took}, ${n(api.getVisibleRowCount())}행`,
en: `Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`,
});
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say({ ko: '정렬과 필터를 풀었어요', en: 'Sort and filter cleared' });
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="행 수"
:disabled="!api"
@change="api && actions.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="100000" selected>10만 행 (기본)</option>
<option value="1000000">100만 행</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.sortAmount(api)"
>금액 정렬</button>
<button
type="button"
:disabled="!api"
@click="api && actions.filterSeoul(api)"
>서울만 보기</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">정렬·필터 풀기</button>
<button type="button" :disabled="!api" @click="api && actions.bottom(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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['서울', '경기', '부산', '대구'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `고객 ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// 화면에 보이는 줄만 그리기 때문에, 10만 행이든 100만 행이든 스크롤은 같은 속도예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: '고객', width: 170 },
{ id: 'region', title: '지역', width: 100 },
{
id: 'amount',
title: '금액(천원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({ ko: '100,000행을 불러왔어요', en: 'Loaded 100,000 rows' });
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('ko-KR');
// 시간은 지금 쓰는 컴퓨터와 브라우저에서 잰 값이에요. 두 크기를 서로 비교해 보세요.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// 정렬·필터는 보이는 행을 구할 때 계산되기 때문에, 첫 줄을 읽어서 계산이 끝난 뒤의 시간을 재요.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say({
ko: `${n(count)}행: 만드는 데 ${generate}, 화면에 넣는 데 ${load}`,
en: `${n(count)} rows: ${generate} to create, ${load} to put on screen`,
});
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say({ ko: `금액 정렬: ${took}`, en: `Sort by amount: ${took}` });
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: '서울' }],
}),
api,
);
say({
ko: `지역이 서울인 행만: ${took}, ${n(api.getVisibleRowCount())}행`,
en: `Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`,
});
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say({ ko: '정렬과 필터를 풀었어요', en: 'Sort and filter cleared' });
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="행 수"
[disabled]="!api"
(change)="api && actions.size(api, $any($event.target).value)"
>
<option value="100000" selected>10만 행 (기본)</option>
<option value="1000000">100만 행</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortAmount(api)"
>금액 정렬</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filterSeoul(api)"
>서울만 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>정렬·필터 풀기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.bottom(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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['서울', '경기', '부산', '대구'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `고객 ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// 화면에 보이는 줄만 그리기 때문에, 10만 행이든 100만 행이든 스크롤은 같은 속도예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: '고객', width: 170 },
{ id: 'region', title: '지역', width: 100 },
{
id: 'amount',
title: '금액(천원)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({ ko: '100,000행을 불러왔어요', en: 'Loaded 100,000 rows' });
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('ko-KR');
// 시간은 지금 쓰는 컴퓨터와 브라우저에서 잰 값이에요. 두 크기를 서로 비교해 보세요.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// 정렬·필터는 보이는 행을 구할 때 계산되기 때문에, 첫 줄을 읽어서 계산이 끝난 뒤의 시간을 재요.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say({
ko: `${n(count)}행: 만드는 데 ${generate}, 화면에 넣는 데 ${load}`,
en: `${n(count)} rows: ${generate} to create, ${load} to put on screen`,
});
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say({ ko: `금액 정렬: ${took}`, en: `Sort by amount: ${took}` });
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: '서울' }],
}),
api,
);
say({
ko: `지역이 서울인 행만: ${took}, ${n(api.getVisibleRowCount())}행`,
en: `Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`,
});
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say({ ko: '정렬과 필터를 풀었어요', en: 'Sort and filter cleared' });
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};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="Row count" id="size">
<option value="100000" selected>100,000 rows (default)</option>
<option value="1000000">1,000,000 rows</option>
</select>
<button type="button" id="sortAmount">Sort by amount</button>
<button type="button" id="filterSeoul">Seoul only</button>
<button type="button" id="reset">Clear sort and filter</button>
<button type="button" id="bottom">Go to bottom</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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
document.getElementById('sortAmount').addEventListener('click', () => actions.sortAmount(api));
document.getElementById('filterSeoul').addEventListener('click', () => actions.filterSeoul(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
document.getElementById('bottom').addEventListener('click', () => actions.bottom(api));const REGIONS = ['Seoul', 'Gyeonggi', 'Busan', 'Daegu'];
function makeRows(count) {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Customer ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// Only the visible lines are drawn, so scrolling runs at the same speed whether there are 100,000 rows or 1,000,000.
export const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: 'Customer', width: 170 },
{ id: 'region', title: 'Region', width: 100 },
{
id: 'amount',
title: 'Amount ($K)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log('Loaded 100,000 rows');
return () => {
say = () => { };
};
}
const n = (value) => value.toLocaleString('en-US');
// The times are measured on the computer and browser you are using now. Compare the two sizes with each other.
const timed = (run, api) => {
const start = performance.now();
const result = run();
// Sort and filter are computed when the visible rows are requested, so read the first line to time the finished calculation.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api, value) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say(`${n(count)} rows: ${generate} to create, ${load} to put on screen`);
},
sortAmount: (api) => {
const [, took] = timed(() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]), api);
say(`Sort by amount: ${took}`);
},
filterSeoul: (api) => {
const [, took] = timed(() => api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: 'Seoul' }],
}), api);
say(`Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`);
},
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
say('Sort and filter cleared');
},
bottom: (api) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0)
api.scrollToIndex(last);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Compare 100,000 and 1,000,000 rows</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Row count" id="size">
<option value="100000" selected>100,000 rows (default)</option>
<option value="1000000">1,000,000 rows</option>
</select>
<button type="button" id="sortAmount">Sort by amount</button>
<button type="button" id="filterSeoul">Seoul only</button>
<button type="button" id="reset">Clear sort and filter</button>
<button type="button" id="bottom">Go to bottom</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 REGIONS = ['Seoul', 'Gyeonggi', 'Busan', 'Daegu'];
function makeRows(count) {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Customer ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// Only the visible lines are drawn, so scrolling runs at the same speed whether there are 100,000 rows or 1,000,000.
const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: 'Customer', width: 170 },
{ id: 'region', title: 'Region', width: 100 },
{
id: 'amount',
title: 'Amount ($K)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
log('Loaded 100,000 rows');
return () => {
say = () => { };
};
}
const n = (value) => value.toLocaleString('en-US');
// The times are measured on the computer and browser you are using now. Compare the two sizes with each other.
const timed = (run, api) => {
const start = performance.now();
const result = run();
// Sort and filter are computed when the visible rows are requested, so read the first line to time the finished calculation.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
const actions = {
size: (api, value) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say(`${n(count)} rows: ${generate} to create, ${load} to put on screen`);
},
sortAmount: (api) => {
const [, took] = timed(() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]), api);
say(`Sort by amount: ${took}`);
},
filterSeoul: (api) => {
const [, took] = timed(() => api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: 'Seoul' }],
}), api);
say(`Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`);
},
reset: (api) => {
api.setSortModel([]);
api.setFilterModel(null);
say('Sort and filter cleared');
},
bottom: (api) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0)
api.scrollToIndex(last);
},
};
options.ariaLabel = "Compare 100,000 and 1,000,000 rows";
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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
document.getElementById('sortAmount').addEventListener('click', () => actions.sortAmount(api));
document.getElementById('filterSeoul').addEventListener('click', () => actions.filterSeoul(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));
document.getElementById('bottom').addEventListener('click', () => actions.bottom(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">
<select
aria-label="Row count"
disabled={!api}
onChange={(event) => api && actions.size(api, event.target.value)}
>
<option value="100000">100,000 rows (default)</option>
<option value="1000000">1,000,000 rows</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortAmount(api)}
>Sort by amount</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filterSeoul(api)}
>Seoul only</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>Clear sort and filter</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.bottom(api)}
>Go to bottom</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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['Seoul', 'Gyeonggi', 'Busan', 'Daegu'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Customer ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// Only the visible lines are drawn, so scrolling runs at the same speed whether there are 100,000 rows or 1,000,000.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: 'Customer', width: 170 },
{ id: 'region', title: 'Region', width: 100 },
{
id: 'amount',
title: 'Amount ($K)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Loaded 100,000 rows');
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('en-US');
// The times are measured on the computer and browser you are using now. Compare the two sizes with each other.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// Sort and filter are computed when the visible rows are requested, so read the first line to time the finished calculation.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say(`${n(count)} rows: ${generate} to create, ${load} to put on screen`);
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say(`Sort by amount: ${took}`);
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: 'Seoul' }],
}),
api,
);
say(`Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`);
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say('Sort and filter cleared');
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};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">
<select
aria-label="Row count"
:disabled="!api"
@change="api && actions.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="100000" selected>100,000 rows (default)</option>
<option value="1000000">1,000,000 rows</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.sortAmount(api)"
>Sort by amount</button>
<button
type="button"
:disabled="!api"
@click="api && actions.filterSeoul(api)"
>Seoul only</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">Clear sort and filter</button>
<button type="button" :disabled="!api" @click="api && actions.bottom(api)">Go to bottom</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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['Seoul', 'Gyeonggi', 'Busan', 'Daegu'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Customer ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// Only the visible lines are drawn, so scrolling runs at the same speed whether there are 100,000 rows or 1,000,000.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: 'Customer', width: 170 },
{ id: 'region', title: 'Region', width: 100 },
{
id: 'amount',
title: 'Amount ($K)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Loaded 100,000 rows');
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('en-US');
// The times are measured on the computer and browser you are using now. Compare the two sizes with each other.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// Sort and filter are computed when the visible rows are requested, so read the first line to time the finished calculation.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say(`${n(count)} rows: ${generate} to create, ${load} to put on screen`);
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say(`Sort by amount: ${took}`);
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: 'Seoul' }],
}),
api,
);
say(`Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`);
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say('Sort and filter cleared');
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};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">
<select
aria-label="Row count"
[disabled]="!api"
(change)="api && actions.size(api, $any($event.target).value)"
>
<option value="100000" selected>100,000 rows (default)</option>
<option value="1000000">1,000,000 rows</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortAmount(api)"
>Sort by amount</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filterSeoul(api)"
>Seoul only</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>Clear sort and filter</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.bottom(api)"
>Go to bottom</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;
name: string;
region: string;
amount: number;
}
const REGIONS = ['Seoul', 'Gyeonggi', 'Busan', 'Daegu'];
function makeRows(count: number): Row[] {
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Customer ${i + 1}`,
region: REGIONS[i % REGIONS.length] ?? '',
amount: 100 + ((i * 7919) % 90_000),
}));
}
// Only the visible lines are drawn, so scrolling runs at the same speed whether there are 100,000 rows or 1,000,000.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 100, align: 'end' },
{ id: 'name', title: 'Customer', width: 170 },
{ id: 'region', title: 'Region', width: 100 },
{
id: 'amount',
title: 'Amount ($K)',
kind: 'number',
width: 130,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: makeRows(100_000),
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log('Loaded 100,000 rows');
return () => {
say = () => {};
};
}
const n = (value: number): string => value.toLocaleString('en-US');
// The times are measured on the computer and browser you are using now. Compare the two sizes with each other.
const timed = <T>(run: () => T, api?: GridApi<Row>): [T, string] => {
const start = performance.now();
const result = run();
// Sort and filter are computed when the visible rows are requested, so read the first line to time the finished calculation.
api?.getRowAtVisibleIndex(0);
return [result, `${Math.round(performance.now() - start)}ms`];
};
export const actions = {
size: (api: GridApi<Row>, value?: string) => {
const count = Number(value) || 100_000;
const [rows, generate] = timed(() => makeRows(count));
const [, load] = timed(() => api.setRows(rows));
say(`${n(count)} rows: ${generate} to create, ${load} to put on screen`);
},
sortAmount: (api: GridApi<Row>) => {
const [, took] = timed(
() => api.setSortModel([{ columnId: 'amount', direction: 'desc' }]),
api,
);
say(`Sort by amount: ${took}`);
},
filterSeoul: (api: GridApi<Row>) => {
const [, took] = timed(
() =>
api.setFilterModel({
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: 'Seoul' }],
}),
api,
);
say(`Only rows in Seoul: ${took}, ${n(api.getVisibleRowCount())} rows`);
},
reset: (api: GridApi<Row>) => {
api.setSortModel([]);
api.setFilterModel(null);
say('Sort and filter cleared');
},
bottom: (api: GridApi<Row>) => {
const last = api.getVisibleRowCount() - 1;
if (last >= 0) api.scrollToIndex(last);
},
};