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

10만 행도 가볍게 쓰는 요령Keeping 100,000 rows light

표에 10만 행을 넣어도 화면에는 보이는 줄만 그려져서 스크롤과 정렬이 가벼워요. 여기에 프레임워크 쪽에서 지킬 요령을 더했어요. React는 행을 한 번만 만들고 스크롤 이벤트를 받지 않기, Vue는 감시를 가볍게 하는 상자에 담기, Angular는 받을 이벤트를 좁히기예요. React, Vue, Angular 탭에는 각 프레임워크의 방식으로 쓴 같은 예제가 들어 있어요.Even with 100,000 rows only the visible lines are drawn, so scrolling and sorting stay light. The framework tabs add what to watch: in React build the rows once and skip the scroll event, in Vue keep them in a light-weight reactive box, in Angular narrow the events you receive. The React, Vue and Angular tabs hold the same example written the way each framework does it.

심화Advanced
직접 써 보기Live preview10만 행도 가볍게 쓰는 요령Keeping 100,000 rows light

실행 화면은 JavaScript 버전이에요. 아래 탭의 React·Vue·Angular 코드는 같은 예제를 각 프레임워크로 직접 쓴 코드예요.The preview runs the JavaScript version. The React, Vue, Angular tabs below hold the same example written for each framework.

코드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="middle">가운데로 가기</button>
    <button type="button" id="last">맨 끝으로 가기</button>
    <button type="button" id="sortBySalary">월급 높은 순으로</button>
    <button type="button" id="clear">정렬 풀기</button>
  </div>
  <div id="grid" style="height: 440px"></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('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('sortBySalary').addEventListener('click', () => actions.sortBySalary(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
export const TOTAL = 100_000;
const DEPTS = ['개발팀', '디자인팀', '영업팀', '인사팀'];
/** 10만 행을 한 번에 만들어요. 화면에는 보이는 줄만 그려져서 행이 많아도 가벼워요. */
export function makeRows(count = TOTAL) {
  return Array.from({ length: count }, (_, i) => ({
    id: i + 1,
    name: `직원 ${i + 1}`,
    dept: DEPTS[i % DEPTS.length],
    salary: 300 + ((i * 37) % 500),
  }));
}
export const options = {
  columns: [
    { id: 'id', title: '번호', kind: 'number', width: 90, align: 'end' },
    { id: 'name', title: '이름', width: 140 },
    { id: 'dept', title: '부서', width: 120 },
    { id: 'salary', title: '월급(만원)', kind: 'number', width: 130, align: 'end' },
  ],
  rows: makeRows(),
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: `${TOTAL.toLocaleString('ko-KR')}행을 한 번에 넣었어요`,
    en: `Put in ${TOTAL.toLocaleString('en-US')} rows at once`,
  });
  return api.on('sortChanged', ({ sortModel }) => {
    log({
      ko: sortModel.length ? '정렬했어요 (10만 행도 바로 끝나요)' : '정렬을 풀었어요',
      en: sortModel.length ? 'Sorted (even 100,000 rows finish at once)' : 'Sort cleared',
    });
  });
}
export const actions = {
  middle: (api) => api.scrollToIndex(Math.floor(TOTAL / 2)),
  last: (api) => api.scrollToIndex(TOTAL - 1),
  sortBySalary: (api) => api.setSortModel([{ columnId: 'salary', direction: 'desc' }]),
  clear: (api) => api.setSortModel([]),
};

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="middle">Jump to the middle</button>
    <button type="button" id="last">Jump to the end</button>
    <button type="button" id="sortBySalary">Sort by salary, high first</button>
    <button type="button" id="clear">Clear sort</button>
  </div>
  <div id="grid" style="height: 440px"></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('middle').addEventListener('click', () => actions.middle(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('sortBySalary').addEventListener('click', () => actions.sortBySalary(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
export const TOTAL = 100_000;
const DEPTS = ['Dev', 'Design', 'Sales', 'HR'];
/** Creates 100,000 rows at once. Only the visible lines are drawn, so it stays light even with many rows. */
export function makeRows(count = TOTAL) {
  return Array.from({ length: count }, (_, i) => ({
    id: i + 1,
    name: `Employee ${i + 1}`,
    dept: DEPTS[i % DEPTS.length],
    salary: 300 + ((i * 37) % 500),
  }));
}
export const options = {
  columns: [
    { id: 'id', title: 'No.', kind: 'number', width: 90, align: 'end' },
    { id: 'name', title: 'Name', width: 140 },
    { id: 'dept', title: 'Department', width: 120 },
    { id: 'salary', title: 'Monthly pay ($100)', kind: 'number', width: 160, align: 'end' },
  ],
  rows: makeRows(),
  rowKey: 'id',
};
export function setup(api, log) {
  log(`Put in ${TOTAL.toLocaleString('en-US')} rows at once`);
  return api.on('sortChanged', ({ sortModel }) => {
    log(sortModel.length ? 'Sorted (even 100,000 rows finish at once)' : 'Sort cleared');
  });
}
export const actions = {
  middle: (api) => api.scrollToIndex(Math.floor(TOTAL / 2)),
  last: (api) => api.scrollToIndex(TOTAL - 1),
  sortBySalary: (api) => api.setSortModel([{ columnId: 'salary', direction: 'desc' }]),
  clear: (api) => api.setSortModel([]),
};