본문으로 건너뛰기Skip to content
예제 첫화면Examples home

스크롤바와 휠, 가상화 정하기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.

활용Intermediate
직접 써 보기Live preview스크롤바와 휠, 가상화 정하기Choose scrollbars, wheel and virtualization

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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.' });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
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.');
  },
};