맨 아래까지 내리면 더 불러오기Load more when you reach the bottom
처음에는 100행만 보여 주고, 스크롤이 맨 아래에 닿으면 20행씩 더 받아서 뒤에 이어 붙여요. 받는 동안 같은 요청이 겹치지 않게 막고, 연습용으로 열 번까지만 받아요.Show 100 rows first, then fetch 20 more each time scrolling reaches the bottom and append them. Overlapping requests are blocked, and it stops after ten loads for this demo.
코드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="toEnd">맨 아래로 가기</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 360px"></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('toEnd').addEventListener('click', () => actions.toEnd(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const customers = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const products = [
'무선 이어폰',
'노트북 14형',
'스마트워치',
'태블릿 11형',
'보조배터리',
'블루투스 스피커',
];
const makeRow = (id) => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19000 + ((id * 7919) % 60) * 10000,
});
const makeRows = (from, count) => Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // 처음에 보여 주는 행 수
const PAGE = 20; // 맨 아래에 닿을 때마다 더 받는 행 수
const MAX_LOADS = 10; // 연습용 상한. 서버 부하를 줄이는 것처럼 열 번까지만 받아요.
const ROW_HEIGHT = 32;
export const options = {
columns: [
{ id: 'id', title: '주문 번호', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: '고객', width: 100 },
{ id: 'product', title: '상품', width: 150 },
{ id: 'quantity', title: '수량', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say = () => { };
// 서버 요청을 흉내 내요. 실제로는 fetch(...)로 다음 구간만 받아 오는 자리예요.
const request = (from) => new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api) {
if (busy || loads >= MAX_LOADS)
return;
busy = true; // 응답이 오기 전에 또 요청하지 않게 막아요.
say({
ko: `맨 아래에 닿았어요. ${PAGE}행을 더 받는 중…`,
en: `Reached the bottom. Loading ${PAGE} more rows…`,
});
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed())
return;
api.addRows(rows); // 기존 행 뒤에 이어 붙여요. 스크롤 위치는 그대로예요.
loads += 1;
busy = false;
say({
ko: loads >= MAX_LOADS
? `${api.getRowCount()}행. 연습용 상한(${MAX_LOADS}번)에 닿아 더 받지 않아요.`
: `${api.getRowCount()}행이 됐어요. (추가 요청 ${loads}/${MAX_LOADS})`,
en: loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
});
}
export function setup(api, log) {
say = log;
log({
ko: `처음 ${FIRST}행. 스크롤을 맨 아래까지 내리면 ${PAGE}행씩 더 받아요.`,
en: `First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`,
});
// endReached: 스크롤이 맨 아래에 가까워지면(endThreshold px 이내) 한 번 알려 줘요.
return api.on('endReached', () => {
if (!resetting)
void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api) => {
// 맨 아래에서 행을 줄이면 스크롤이 끝으로 밀려서 바로 또 불러오게 돼요. 먼저 위로 올리고, 잠깐 알림을 무시해요.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say({ ko: `처음 ${FIRST}행으로 되돌렸어요.`, en: `Back to the first ${FIRST} rows.` });
},
};<!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="toEnd">맨 아래로 가기</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const products = [
'무선 이어폰',
'노트북 14형',
'스마트워치',
'태블릿 11형',
'보조배터리',
'블루투스 스피커',
];
const makeRow = (id) => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19000 + ((id * 7919) % 60) * 10000,
});
const makeRows = (from, count) => Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // 처음에 보여 주는 행 수
const PAGE = 20; // 맨 아래에 닿을 때마다 더 받는 행 수
const MAX_LOADS = 10; // 연습용 상한. 서버 부하를 줄이는 것처럼 열 번까지만 받아요.
const ROW_HEIGHT = 32;
const options = {
columns: [
{ id: 'id', title: '주문 번호', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: '고객', width: 100 },
{ id: 'product', title: '상품', width: 150 },
{ id: 'quantity', title: '수량', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say = () => { };
// 서버 요청을 흉내 내요. 실제로는 fetch(...)로 다음 구간만 받아 오는 자리예요.
const request = (from) => new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api) {
if (busy || loads >= MAX_LOADS)
return;
busy = true; // 응답이 오기 전에 또 요청하지 않게 막아요.
say({
ko: `맨 아래에 닿았어요. ${PAGE}행을 더 받는 중…`,
en: `Reached the bottom. Loading ${PAGE} more rows…`,
});
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed())
return;
api.addRows(rows); // 기존 행 뒤에 이어 붙여요. 스크롤 위치는 그대로예요.
loads += 1;
busy = false;
say({
ko: loads >= MAX_LOADS
? `${api.getRowCount()}행. 연습용 상한(${MAX_LOADS}번)에 닿아 더 받지 않아요.`
: `${api.getRowCount()}행이 됐어요. (추가 요청 ${loads}/${MAX_LOADS})`,
en: loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
});
}
function setup(api, log) {
say = log;
log({
ko: `처음 ${FIRST}행. 스크롤을 맨 아래까지 내리면 ${PAGE}행씩 더 받아요.`,
en: `First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`,
});
// endReached: 스크롤이 맨 아래에 가까워지면(endThreshold px 이내) 한 번 알려 줘요.
return api.on('endReached', () => {
if (!resetting)
void loadMore(api);
});
}
let resetting = false;
const actions = {
toEnd: (api) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api) => {
// 맨 아래에서 행을 줄이면 스크롤이 끝으로 밀려서 바로 또 불러오게 돼요. 먼저 위로 올리고, 잠깐 알림을 무시해요.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say({ ko: `처음 ${FIRST}행으로 되돌렸어요.`, en: `Back to the first ${FIRST} rows.` });
},
};
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('toEnd').addEventListener('click', () => actions.toEnd(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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.toEnd(api)}
>맨 아래로 가기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>처음으로</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const products = [
'무선 이어폰',
'노트북 14형',
'스마트워치',
'태블릿 11형',
'보조배터리',
'블루투스 스피커',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19000 + ((id * 7919) % 60) * 10000,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // 처음에 보여 주는 행 수
const PAGE = 20; // 맨 아래에 닿을 때마다 더 받는 행 수
const MAX_LOADS = 10; // 연습용 상한. 서버 부하를 줄이는 것처럼 열 번까지만 받아요.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '주문 번호', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: '고객', width: 100 },
{ id: 'product', title: '상품', width: 150 },
{ id: 'quantity', title: '수량', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// 서버 요청을 흉내 내요. 실제로는 fetch(...)로 다음 구간만 받아 오는 자리예요.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // 응답이 오기 전에 또 요청하지 않게 막아요.
say({
ko: `맨 아래에 닿았어요. ${PAGE}행을 더 받는 중…`,
en: `Reached the bottom. Loading ${PAGE} more rows…`,
});
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // 기존 행 뒤에 이어 붙여요. 스크롤 위치는 그대로예요.
loads += 1;
busy = false;
say({
ko:
loads >= MAX_LOADS
? `${api.getRowCount()}행. 연습용 상한(${MAX_LOADS}번)에 닿아 더 받지 않아요.`
: `${api.getRowCount()}행이 됐어요. (추가 요청 ${loads}/${MAX_LOADS})`,
en:
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `처음 ${FIRST}행. 스크롤을 맨 아래까지 내리면 ${PAGE}행씩 더 받아요.`,
en: `First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`,
});
// endReached: 스크롤이 맨 아래에 가까워지면(endThreshold px 이내) 한 번 알려 줘요.
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// 맨 아래에서 행을 줄이면 스크롤이 끝으로 밀려서 바로 또 불러오게 돼요. 먼저 위로 올리고, 잠깐 알림을 무시해요.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say({ ko: `처음 ${FIRST}행으로 되돌렸어요.`, en: `Back to the first ${FIRST} rows.` });
},
};버튼을 누르면 이 예제의 코드가 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.toEnd(api)">맨 아래로 가기</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">처음으로</button>
</div>
<Grid style="height: 360px" :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;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const products = [
'무선 이어폰',
'노트북 14형',
'스마트워치',
'태블릿 11형',
'보조배터리',
'블루투스 스피커',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19000 + ((id * 7919) % 60) * 10000,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // 처음에 보여 주는 행 수
const PAGE = 20; // 맨 아래에 닿을 때마다 더 받는 행 수
const MAX_LOADS = 10; // 연습용 상한. 서버 부하를 줄이는 것처럼 열 번까지만 받아요.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '주문 번호', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: '고객', width: 100 },
{ id: 'product', title: '상품', width: 150 },
{ id: 'quantity', title: '수량', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// 서버 요청을 흉내 내요. 실제로는 fetch(...)로 다음 구간만 받아 오는 자리예요.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // 응답이 오기 전에 또 요청하지 않게 막아요.
say({
ko: `맨 아래에 닿았어요. ${PAGE}행을 더 받는 중…`,
en: `Reached the bottom. Loading ${PAGE} more rows…`,
});
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // 기존 행 뒤에 이어 붙여요. 스크롤 위치는 그대로예요.
loads += 1;
busy = false;
say({
ko:
loads >= MAX_LOADS
? `${api.getRowCount()}행. 연습용 상한(${MAX_LOADS}번)에 닿아 더 받지 않아요.`
: `${api.getRowCount()}행이 됐어요. (추가 요청 ${loads}/${MAX_LOADS})`,
en:
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `처음 ${FIRST}행. 스크롤을 맨 아래까지 내리면 ${PAGE}행씩 더 받아요.`,
en: `First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`,
});
// endReached: 스크롤이 맨 아래에 가까워지면(endThreshold px 이내) 한 번 알려 줘요.
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// 맨 아래에서 행을 줄이면 스크롤이 끝으로 밀려서 바로 또 불러오게 돼요. 먼저 위로 올리고, 잠깐 알림을 무시해요.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say({ ko: `처음 ${FIRST}행으로 되돌렸어요.`, en: `Back to the first ${FIRST} rows.` });
},
};버튼을 누르면 이 예제의 코드가 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.toEnd(api)"
>맨 아래로 가기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>처음으로</button>
</div>
<mx-grid style="height: 360px" [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;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const products = [
'무선 이어폰',
'노트북 14형',
'스마트워치',
'태블릿 11형',
'보조배터리',
'블루투스 스피커',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19000 + ((id * 7919) % 60) * 10000,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // 처음에 보여 주는 행 수
const PAGE = 20; // 맨 아래에 닿을 때마다 더 받는 행 수
const MAX_LOADS = 10; // 연습용 상한. 서버 부하를 줄이는 것처럼 열 번까지만 받아요.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '주문 번호', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: '고객', width: 100 },
{ id: 'product', title: '상품', width: 150 },
{ id: 'quantity', title: '수량', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// 서버 요청을 흉내 내요. 실제로는 fetch(...)로 다음 구간만 받아 오는 자리예요.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // 응답이 오기 전에 또 요청하지 않게 막아요.
say({
ko: `맨 아래에 닿았어요. ${PAGE}행을 더 받는 중…`,
en: `Reached the bottom. Loading ${PAGE} more rows…`,
});
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // 기존 행 뒤에 이어 붙여요. 스크롤 위치는 그대로예요.
loads += 1;
busy = false;
say({
ko:
loads >= MAX_LOADS
? `${api.getRowCount()}행. 연습용 상한(${MAX_LOADS}번)에 닿아 더 받지 않아요.`
: `${api.getRowCount()}행이 됐어요. (추가 요청 ${loads}/${MAX_LOADS})`,
en:
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
});
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: `처음 ${FIRST}행. 스크롤을 맨 아래까지 내리면 ${PAGE}행씩 더 받아요.`,
en: `First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`,
});
// endReached: 스크롤이 맨 아래에 가까워지면(endThreshold px 이내) 한 번 알려 줘요.
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// 맨 아래에서 행을 줄이면 스크롤이 끝으로 밀려서 바로 또 불러오게 돼요. 먼저 위로 올리고, 잠깐 알림을 무시해요.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say({ ko: `처음 ${FIRST}행으로 되돌렸어요.`, en: `Back to the first ${FIRST} rows.` });
},
};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="toEnd">Jump to the end</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 360px"></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('toEnd').addEventListener('click', () => actions.toEnd(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const customers = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const products = [
'Wireless Earbuds',
'Laptop 14"',
'Smartwatch',
'Tablet 11"',
'Power Bank',
'Bluetooth Speaker',
];
const makeRow = (id) => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19 + ((id * 7919) % 60) * 10,
});
const makeRows = (from, count) => Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // Number of rows shown at first
const PAGE = 20; // Number of rows loaded each time the bottom is reached
const MAX_LOADS = 10; // Practice limit. Like easing server load, it loads only up to ten times.
const ROW_HEIGHT = 32;
export const options = {
columns: [
{ id: 'id', title: 'Order No.', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: 'Customer', width: 120 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say = () => { };
// Imitates a server request. In practice this is where fetch(...) would get only the next slice.
const request = (from) => new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api) {
if (busy || loads >= MAX_LOADS)
return;
busy = true; // Block another request before the response arrives.
say(`Reached the bottom. Loading ${PAGE} more rows…`);
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed())
return;
api.addRows(rows); // Append after the existing rows. The scroll position stays as it is.
loads += 1;
busy = false;
say(loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`);
}
export function setup(api, log) {
say = log;
log(`First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`);
// endReached: fires once when the scroll gets near the bottom (within endThreshold px).
return api.on('endReached', () => {
if (!resetting)
void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api) => {
// Shrinking the rows at the bottom pushes the scroll to the end and would load again right away. Scroll up first and ignore the notification briefly.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say(`Back to the first ${FIRST} rows.`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Load more when you reach the bottom</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="toEnd">Jump to the end</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const products = [
'Wireless Earbuds',
'Laptop 14"',
'Smartwatch',
'Tablet 11"',
'Power Bank',
'Bluetooth Speaker',
];
const makeRow = (id) => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19 + ((id * 7919) % 60) * 10,
});
const makeRows = (from, count) => Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // Number of rows shown at first
const PAGE = 20; // Number of rows loaded each time the bottom is reached
const MAX_LOADS = 10; // Practice limit. Like easing server load, it loads only up to ten times.
const ROW_HEIGHT = 32;
const options = {
columns: [
{ id: 'id', title: 'Order No.', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: 'Customer', width: 120 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say = () => { };
// Imitates a server request. In practice this is where fetch(...) would get only the next slice.
const request = (from) => new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api) {
if (busy || loads >= MAX_LOADS)
return;
busy = true; // Block another request before the response arrives.
say(`Reached the bottom. Loading ${PAGE} more rows…`);
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed())
return;
api.addRows(rows); // Append after the existing rows. The scroll position stays as it is.
loads += 1;
busy = false;
say(loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`);
}
function setup(api, log) {
say = log;
log(`First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`);
// endReached: fires once when the scroll gets near the bottom (within endThreshold px).
return api.on('endReached', () => {
if (!resetting)
void loadMore(api);
});
}
let resetting = false;
const actions = {
toEnd: (api) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api) => {
// Shrinking the rows at the bottom pushes the scroll to the end and would load again right away. Scroll up first and ignore the notification briefly.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say(`Back to the first ${FIRST} rows.`);
},
};
options.ariaLabel = "Load more when you reach the bottom";
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('toEnd').addEventListener('click', () => actions.toEnd(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(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.toEnd(api)}
>Jump to the end</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>Reset</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const products = [
'Wireless Earbuds',
'Laptop 14"',
'Smartwatch',
'Tablet 11"',
'Power Bank',
'Bluetooth Speaker',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19 + ((id * 7919) % 60) * 10,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // Number of rows shown at first
const PAGE = 20; // Number of rows loaded each time the bottom is reached
const MAX_LOADS = 10; // Practice limit. Like easing server load, it loads only up to ten times.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'Order No.', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: 'Customer', width: 120 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// Imitates a server request. In practice this is where fetch(...) would get only the next slice.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // Block another request before the response arrives.
say(`Reached the bottom. Loading ${PAGE} more rows…`);
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // Append after the existing rows. The scroll position stays as it is.
loads += 1;
busy = false;
say(
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`);
// endReached: fires once when the scroll gets near the bottom (within endThreshold px).
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// Shrinking the rows at the bottom pushes the scroll to the end and would load again right away. Scroll up first and ignore the notification briefly.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say(`Back to the first ${FIRST} rows.`);
},
};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.toEnd(api)">Jump to the end</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">Reset</button>
</div>
<Grid style="height: 360px" :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;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const products = [
'Wireless Earbuds',
'Laptop 14"',
'Smartwatch',
'Tablet 11"',
'Power Bank',
'Bluetooth Speaker',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19 + ((id * 7919) % 60) * 10,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // Number of rows shown at first
const PAGE = 20; // Number of rows loaded each time the bottom is reached
const MAX_LOADS = 10; // Practice limit. Like easing server load, it loads only up to ten times.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'Order No.', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: 'Customer', width: 120 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// Imitates a server request. In practice this is where fetch(...) would get only the next slice.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // Block another request before the response arrives.
say(`Reached the bottom. Loading ${PAGE} more rows…`);
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // Append after the existing rows. The scroll position stays as it is.
loads += 1;
busy = false;
say(
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`);
// endReached: fires once when the scroll gets near the bottom (within endThreshold px).
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// Shrinking the rows at the bottom pushes the scroll to the end and would load again right away. Scroll up first and ignore the notification briefly.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say(`Back to the first ${FIRST} rows.`);
},
};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.toEnd(api)"
>Jump to the end</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>Reset</button>
</div>
<mx-grid style="height: 360px" [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;
customer: string;
product: string;
quantity: number;
amount: number;
}
const customers = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const products = [
'Wireless Earbuds',
'Laptop 14"',
'Smartwatch',
'Tablet 11"',
'Power Bank',
'Bluetooth Speaker',
];
const makeRow = (id: number): Row => ({
id,
customer: customers[(id * 5) % customers.length],
product: products[(id * 3 + (id >> 2)) % products.length],
quantity: 1 + ((id * 7) % 9),
amount: 19 + ((id * 7919) % 60) * 10,
});
const makeRows = (from: number, count: number): Row[] =>
Array.from({ length: count }, (_, i) => makeRow(from + i));
const FIRST = 100; // Number of rows shown at first
const PAGE = 20; // Number of rows loaded each time the bottom is reached
const MAX_LOADS = 10; // Practice limit. Like easing server load, it loads only up to ten times.
const ROW_HEIGHT = 32;
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'Order No.', kind: 'number', width: 100, align: 'end' },
{ id: 'customer', title: 'Customer', width: 120 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 80, align: 'end' },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: makeRows(1, FIRST),
rowKey: 'id',
rowHeight: ROW_HEIGHT,
showRowNumbers: true,
};
let loads = 0;
let busy = false;
let say: (message: LogText) => void = () => {};
// Imitates a server request. In practice this is where fetch(...) would get only the next slice.
const request = (from: number): Promise<Row[]> =>
new Promise((resolve) => setTimeout(() => resolve(makeRows(from, PAGE)), 500));
async function loadMore(api: GridApi<Row>): Promise<void> {
if (busy || loads >= MAX_LOADS) return;
busy = true; // Block another request before the response arrives.
say(`Reached the bottom. Loading ${PAGE} more rows…`);
const from = api.getRowCount() + 1;
const rows = await request(from);
if (api.isDestroyed()) return;
api.addRows(rows); // Append after the existing rows. The scroll position stays as it is.
loads += 1;
busy = false;
say(
loads >= MAX_LOADS
? `${api.getRowCount()} rows. Reached the practice limit (${MAX_LOADS} requests), so no more are loaded.`
: `Now ${api.getRowCount()} rows. (extra requests ${loads}/${MAX_LOADS})`,
);
}
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(`First ${FIRST} rows. Scroll to the bottom to load ${PAGE} more at a time.`);
// endReached: fires once when the scroll gets near the bottom (within endThreshold px).
return api.on('endReached', () => {
if (!resetting) void loadMore(api);
});
}
let resetting = false;
export const actions = {
toEnd: (api: GridApi<Row>) => api.scrollToIndex(api.getVisibleRowCount() - 1),
reset: (api: GridApi<Row>) => {
// Shrinking the rows at the bottom pushes the scroll to the end and would load again right away. Scroll up first and ignore the notification briefly.
resetting = true;
api.setScroll({ top: 0 });
loads = 0;
busy = false;
api.setRows(makeRows(1, FIRST));
requestAnimationFrame(() => requestAnimationFrame(() => (resetting = false)));
say(`Back to the first ${FIRST} rows.`);
},
};