스크롤바와 휠, 가상화 정하기Choose scrollbars, wheel and virtualization
scrollbars로 축마다 스크롤바를 항상 보이거나 숨기고, wheel로 휠을 페이지에 넘기며, virtualize로 가상화를 끄고, tabIndex로 Tab 순서를 정해요. 모두 옵션이고 안 주면 기존과 같아요.scrollbars always shows or hides the bars per axis, wheel hands the wheel to the page, virtualize turns virtualization off and tabIndex sets the Tab order. They are all options; without them nothing changes.
코드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="bars">스크롤바 항상</button>
<button type="button" id="hide">세로 숨김</button>
<button type="button" id="go">300번 행으로</button>
<button type="button" id="virtual">가상화 끄기</button>
<button type="button" id="wheel">휠 넘기기</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 280px"></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('bars').addEventListener('click', () => actions.bars(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('go').addEventListener('click', () => actions.go(api));
document.getElementById('virtual').addEventListener('click', () => actions.virtual(api));
document.getElementById('wheel').addEventListener('click', () => actions.wheel(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const rows = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `품목 ${i + 1}`,
qty: (i * 7) % 100,
}));
// 모든 옵션은 안 주면 기존과 같아요. tabIndex는 그리드 루트의 tabindex(기본 0), scrollbars는 축마다 보임·숨김,
// virtualize는 행·컬럼 가상화, wheel은 휠을 페이지로 넘길지예요.
export const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 80 },
{ id: 'name', title: '품목', width: 160 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say = () => undefined;
export function setup(_grid, log) {
say = log;
}
const drawn = () => document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say({ ko: '스크롤바를 항상 보여요.', en: 'Scrollbars are always shown.' });
},
hide: (grid) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say({
ko: '세로 스크롤바를 숨겼어요. 코드로는 스크롤돼요.',
en: 'Hid the vertical bar. Code can still scroll.',
});
},
go: (grid) => grid.scrollToIndex(299),
virtual: (grid) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say({ ko: `그린 행 ${drawn()}개(전체 500개)`, en: `${drawn()} rows drawn (of 500)` }), 50);
},
wheel: (grid) => {
grid.setOptions({ wheel: 'passThrough' });
say({ ko: '휠을 페이지로 넘겨요.', en: 'The wheel goes to the page.' });
},
reset: (grid) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say({ ko: '기본으로 돌렸어요.', en: 'Back to the defaults.' });
},
};<!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="bars">스크롤바 항상</button>
<button type="button" id="hide">세로 숨김</button>
<button type="button" id="go">300번 행으로</button>
<button type="button" id="virtual">가상화 끄기</button>
<button type="button" id="wheel">휠 넘기기</button>
<button type="button" id="reset">처음으로</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `품목 ${i + 1}`,
qty: (i * 7) % 100,
}));
// 모든 옵션은 안 주면 기존과 같아요. tabIndex는 그리드 루트의 tabindex(기본 0), scrollbars는 축마다 보임·숨김,
// virtualize는 행·컬럼 가상화, wheel은 휠을 페이지로 넘길지예요.
const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 80 },
{ id: 'name', title: '품목', width: 160 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say = () => undefined;
function setup(_grid, log) {
say = log;
}
const drawn = () => document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
const actions = {
bars: (grid) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say({ ko: '스크롤바를 항상 보여요.', en: 'Scrollbars are always shown.' });
},
hide: (grid) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say({
ko: '세로 스크롤바를 숨겼어요. 코드로는 스크롤돼요.',
en: 'Hid the vertical bar. Code can still scroll.',
});
},
go: (grid) => grid.scrollToIndex(299),
virtual: (grid) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say({ ko: `그린 행 ${drawn()}개(전체 500개)`, en: `${drawn()} rows drawn (of 500)` }), 50);
},
wheel: (grid) => {
grid.setOptions({ wheel: 'passThrough' });
say({ ko: '휠을 페이지로 넘겨요.', en: 'The wheel goes to the page.' });
},
reset: (grid) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say({ ko: '기본으로 돌렸어요.', en: 'Back to the defaults.' });
},
};
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('bars').addEventListener('click', () => actions.bars(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('go').addEventListener('click', () => actions.go(api));
document.getElementById('virtual').addEventListener('click', () => actions.virtual(api));
document.getElementById('wheel').addEventListener('click', () => actions.wheel(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.bars(api)}
>스크롤바 항상</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(api)}
>세로 숨김</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.go(api)}
>300번 행으로</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.virtual(api)}
>가상화 끄기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.wheel(api)}
>휠 넘기기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>처음으로</button>
</div>
<Grid style={{ height: 280 }} 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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `품목 ${i + 1}`,
qty: (i * 7) % 100,
}));
// 모든 옵션은 안 주면 기존과 같아요. tabIndex는 그리드 루트의 tabindex(기본 0), scrollbars는 축마다 보임·숨김,
// virtualize는 행·컬럼 가상화, wheel은 휠을 페이지로 넘길지예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 80 },
{ id: 'name', title: '품목', width: 160 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say({ ko: '스크롤바를 항상 보여요.', en: 'Scrollbars are always shown.' });
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say({
ko: '세로 스크롤바를 숨겼어요. 코드로는 스크롤돼요.',
en: 'Hid the vertical bar. Code can still scroll.',
});
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(
() => say({ ko: `그린 행 ${drawn()}개(전체 500개)`, en: `${drawn()} rows drawn (of 500)` }),
50,
);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say({ ko: '휠을 페이지로 넘겨요.', en: 'The wheel goes to the page.' });
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say({ ko: '기본으로 돌렸어요.', en: 'Back to the defaults.' });
},
};버튼을 누르면 이 예제의 코드가 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.bars(api)">스크롤바 항상</button>
<button type="button" :disabled="!api" @click="api && actions.hide(api)">세로 숨김</button>
<button type="button" :disabled="!api" @click="api && actions.go(api)">300번 행으로</button>
<button type="button" :disabled="!api" @click="api && actions.virtual(api)">가상화 끄기</button>
<button type="button" :disabled="!api" @click="api && actions.wheel(api)">휠 넘기기</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">처음으로</button>
</div>
<Grid style="height: 280px" :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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `품목 ${i + 1}`,
qty: (i * 7) % 100,
}));
// 모든 옵션은 안 주면 기존과 같아요. tabIndex는 그리드 루트의 tabindex(기본 0), scrollbars는 축마다 보임·숨김,
// virtualize는 행·컬럼 가상화, wheel은 휠을 페이지로 넘길지예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 80 },
{ id: 'name', title: '품목', width: 160 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say({ ko: '스크롤바를 항상 보여요.', en: 'Scrollbars are always shown.' });
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say({
ko: '세로 스크롤바를 숨겼어요. 코드로는 스크롤돼요.',
en: 'Hid the vertical bar. Code can still scroll.',
});
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(
() => say({ ko: `그린 행 ${drawn()}개(전체 500개)`, en: `${drawn()} rows drawn (of 500)` }),
50,
);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say({ ko: '휠을 페이지로 넘겨요.', en: 'The wheel goes to the page.' });
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say({ ko: '기본으로 돌렸어요.', en: 'Back to the defaults.' });
},
};버튼을 누르면 이 예제의 코드가 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.bars(api)"
>스크롤바 항상</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(api)"
>세로 숨김</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.go(api)"
>300번 행으로</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.virtual(api)"
>가상화 끄기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.wheel(api)"
>휠 넘기기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>처음으로</button>
</div>
<mx-grid style="height: 280px" [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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `품목 ${i + 1}`,
qty: (i * 7) % 100,
}));
// 모든 옵션은 안 주면 기존과 같아요. tabIndex는 그리드 루트의 tabindex(기본 0), scrollbars는 축마다 보임·숨김,
// virtualize는 행·컬럼 가상화, wheel은 휠을 페이지로 넘길지예요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 80 },
{ id: 'name', title: '품목', width: 160 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say({ ko: '스크롤바를 항상 보여요.', en: 'Scrollbars are always shown.' });
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say({
ko: '세로 스크롤바를 숨겼어요. 코드로는 스크롤돼요.',
en: 'Hid the vertical bar. Code can still scroll.',
});
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(
() => say({ ko: `그린 행 ${drawn()}개(전체 500개)`, en: `${drawn()} rows drawn (of 500)` }),
50,
);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say({ ko: '휠을 페이지로 넘겨요.', en: 'The wheel goes to the page.' });
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say({ ko: '기본으로 돌렸어요.', en: 'Back to the defaults.' });
},
};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="bars">Bars always</button>
<button type="button" id="hide">Hide vertical</button>
<button type="button" id="go">Go to row 300</button>
<button type="button" id="virtual">Virtualization off</button>
<button type="button" id="wheel">Pass wheel</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 280px"></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('bars').addEventListener('click', () => actions.bars(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('go').addEventListener('click', () => actions.go(api));
document.getElementById('virtual').addEventListener('click', () => actions.virtual(api));
document.getElementById('wheel').addEventListener('click', () => actions.wheel(api));
document.getElementById('reset').addEventListener('click', () => actions.reset(api));const rows = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 100,
}));
// Every option behaves as before when omitted. tabIndex is the grid root's tabindex (default 0), scrollbars shows or hides
// each axis, virtualize toggles row and column virtualization, and wheel decides whether the wheel passes to the page.
export const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 80 },
{ id: 'name', title: 'Item', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say = () => undefined;
export function setup(_grid, log) {
say = log;
}
const drawn = () => document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say('Scrollbars are always shown.');
},
hide: (grid) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say('Hid the vertical bar. Code can still scroll.');
},
go: (grid) => grid.scrollToIndex(299),
virtual: (grid) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say(`${drawn()} rows drawn (of 500)`), 50);
},
wheel: (grid) => {
grid.setOptions({ wheel: 'passThrough' });
say('The wheel goes to the page.');
},
reset: (grid) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say('Back to the defaults.');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Choose scrollbars, wheel and virtualization</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="bars">Bars always</button>
<button type="button" id="hide">Hide vertical</button>
<button type="button" id="go">Go to row 300</button>
<button type="button" id="virtual">Virtualization off</button>
<button type="button" id="wheel">Pass wheel</button>
<button type="button" id="reset">Reset</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 100,
}));
// Every option behaves as before when omitted. tabIndex is the grid root's tabindex (default 0), scrollbars shows or hides
// each axis, virtualize toggles row and column virtualization, and wheel decides whether the wheel passes to the page.
const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 80 },
{ id: 'name', title: 'Item', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say = () => undefined;
function setup(_grid, log) {
say = log;
}
const drawn = () => document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
const actions = {
bars: (grid) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say('Scrollbars are always shown.');
},
hide: (grid) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say('Hid the vertical bar. Code can still scroll.');
},
go: (grid) => grid.scrollToIndex(299),
virtual: (grid) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say(`${drawn()} rows drawn (of 500)`), 50);
},
wheel: (grid) => {
grid.setOptions({ wheel: 'passThrough' });
say('The wheel goes to the page.');
},
reset: (grid) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say('Back to the defaults.');
},
};
options.ariaLabel = "Choose scrollbars, wheel and virtualization";
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('bars').addEventListener('click', () => actions.bars(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('go').addEventListener('click', () => actions.go(api));
document.getElementById('virtual').addEventListener('click', () => actions.virtual(api));
document.getElementById('wheel').addEventListener('click', () => actions.wheel(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.bars(api)}
>Bars always</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(api)}
>Hide vertical</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.go(api)}
>Go to row 300</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.virtual(api)}
>Virtualization off</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.wheel(api)}
>Pass wheel</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.reset(api)}
>Reset</button>
</div>
<Grid style={{ height: 280 }} 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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 100,
}));
// Every option behaves as before when omitted. tabIndex is the grid root's tabindex (default 0), scrollbars shows or hides
// each axis, virtualize toggles row and column virtualization, and wheel decides whether the wheel passes to the page.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 80 },
{ id: 'name', title: 'Item', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say('Scrollbars are always shown.');
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say('Hid the vertical bar. Code can still scroll.');
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say(`${drawn()} rows drawn (of 500)`), 50);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say('The wheel goes to the page.');
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say('Back to the defaults.');
},
};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.bars(api)">Bars always</button>
<button type="button" :disabled="!api" @click="api && actions.hide(api)">Hide vertical</button>
<button type="button" :disabled="!api" @click="api && actions.go(api)">Go to row 300</button>
<button type="button" :disabled="!api" @click="api && actions.virtual(api)">Virtualization off</button>
<button type="button" :disabled="!api" @click="api && actions.wheel(api)">Pass wheel</button>
<button type="button" :disabled="!api" @click="api && actions.reset(api)">Reset</button>
</div>
<Grid style="height: 280px" :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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 100,
}));
// Every option behaves as before when omitted. tabIndex is the grid root's tabindex (default 0), scrollbars shows or hides
// each axis, virtualize toggles row and column virtualization, and wheel decides whether the wheel passes to the page.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 80 },
{ id: 'name', title: 'Item', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say('Scrollbars are always shown.');
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say('Hid the vertical bar. Code can still scroll.');
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say(`${drawn()} rows drawn (of 500)`), 50);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say('The wheel goes to the page.');
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say('Back to the defaults.');
},
};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.bars(api)"
>Bars always</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(api)"
>Hide vertical</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.go(api)"
>Go to row 300</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.virtual(api)"
>Virtualization off</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.wheel(api)"
>Pass wheel</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.reset(api)"
>Reset</button>
</div>
<mx-grid style="height: 280px" [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;
qty: number;
}
const rows: Row[] = Array.from({ length: 500 }, (_, i) => ({
id: i + 1,
name: `Item ${i + 1}`,
qty: (i * 7) % 100,
}));
// Every option behaves as before when omitted. tabIndex is the grid root's tabindex (default 0), scrollbars shows or hides
// each axis, virtualize toggles row and column virtualization, and wheel decides whether the wheel passes to the page.
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 80 },
{ id: 'name', title: 'Item', width: 160 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows,
rowKey: 'id',
tabIndex: 0,
};
let say: (message: LogText) => void = () => undefined;
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
}
const drawn = (): number =>
document.querySelectorAll('.mxg-body .mxg-row[data-row-index]:not([style*="display: none"])')
.length;
export const actions = {
bars: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { x: 'always', y: 'always' } });
say('Scrollbars are always shown.');
},
hide: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: { y: 'hidden' } });
say('Hid the vertical bar. Code can still scroll.');
},
go: (grid: GridApi<Row>) => grid.scrollToIndex(299),
virtual: (grid: GridApi<Row>) => {
grid.setOptions({ virtualize: { rows: false } });
setTimeout(() => say(`${drawn()} rows drawn (of 500)`), 50);
},
wheel: (grid: GridApi<Row>) => {
grid.setOptions({ wheel: 'passThrough' });
say('The wheel goes to the page.');
},
reset: (grid: GridApi<Row>) => {
grid.setOptions({ scrollbars: {}, virtualize: {}, wheel: 'grid' });
say('Back to the defaults.');
},
};