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

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.

활용Intermediate
직접 써 보기Live preview10만 행과 100만 행 비교하기Compare 100,000 and 1,000,000 rows

코드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">
    <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>
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('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));
example.js
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);
  },
};

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">
    <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>
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('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));
example.js
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);
  },
};