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

불러오는 동안 스켈레톤 보이기Show a skeleton while loading

overlays.loading을 'skeleton'으로 두면 불러오는 동안 자리 표시 줄이 보여요. 줄 수는 skeletonRows로 정하고, 줄은 행이 아니라서 선택이나 내보내기에 닿지 않아요.Set overlays.loading to 'skeleton' and placeholder rows show while loading. skeletonRows sets how many; the rows are not grid rows, so selection and export never see them.

활용Intermediate
직접 써 보기Live preview불러오는 동안 스켈레톤 보이기Show a skeleton while loading

코드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="load">불러오기 시작</button>
    <button type="button" id="rows">줄 수 3/8</button>
  </div>
  <div id="grid" style="height: 260px"></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('load').addEventListener('click', () => actions.load(api));
document.getElementById('rows').addEventListener('click', () => actions.rows(api));
example.js
const rows = [
  { id: 1, name: '김서연', dept: '개발', pay: 5200 },
  { id: 2, name: '이준호', dept: '영업', pay: 4800 },
  { id: 3, name: '박민지', dept: '개발', pay: 5000 },
];
// overlays.loading을 'skeleton'으로 두면 loading이 true인 동안 자리 표시 줄이 보여요. 줄 수는 skeletonRows(1~30)예요.
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 120 },
    { id: 'dept', title: '부서', width: 100 },
    { id: 'pay', title: '급여', kind: 'number', width: 110 },
  ],
  rows: [],
  rowKey: 'id',
  loading: true,
  overlays: { loading: 'skeleton', skeletonRows: 8 },
};
let say = () => undefined;
let eight = true;
export function setup(grid, log) {
  say = log;
  log({ ko: '"불러오기 시작"을 눌러 보세요.', en: 'Press "Start loading".' });
  setTimeout(() => grid.setOptions({ loading: false }), 1200);
}
export const actions = {
  load: (grid) => {
    grid.setRows([]);
    grid.setOptions({ loading: true });
    say({ ko: '불러오는 중이에요…', en: 'Loading…' });
    setTimeout(() => {
      grid.setRows(rows);
      grid.setOptions({ loading: false });
      say({ ko: '불러왔어요.', en: 'Loaded.' });
    }, 1500);
  },
  rows: (grid) => {
    eight = !eight;
    grid.setOptions({ overlays: { loading: 'skeleton', skeletonRows: eight ? 8 : 3 } });
    say({ ko: `스켈레톤 ${eight ? 8 : 3}줄`, en: `${eight ? 8 : 3} skeleton rows` });
  },
};

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="load">Start loading</button>
    <button type="button" id="rows">Rows 3/8</button>
  </div>
  <div id="grid" style="height: 260px"></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('load').addEventListener('click', () => actions.load(api));
document.getElementById('rows').addEventListener('click', () => actions.rows(api));
example.js
const rows = [
  { id: 1, name: 'Emma Stone', dept: 'Dev', pay: 5200 },
  { id: 2, name: 'Liam Carter', dept: 'Sales', pay: 4800 },
  { id: 3, name: 'Olivia Hayes', dept: 'Dev', pay: 5000 },
];
// With overlays.loading set to 'skeleton', placeholder rows show while loading is true. The row count is skeletonRows (1 to 30).
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 130 },
    { id: 'dept', title: 'Department', width: 110 },
    { id: 'pay', title: 'Pay', kind: 'number', width: 110 },
  ],
  rows: [],
  rowKey: 'id',
  loading: true,
  overlays: { loading: 'skeleton', skeletonRows: 8 },
};
let say = () => undefined;
let eight = true;
export function setup(grid, log) {
  say = log;
  log('Press "Start loading".');
  setTimeout(() => grid.setOptions({ loading: false }), 1200);
}
export const actions = {
  load: (grid) => {
    grid.setRows([]);
    grid.setOptions({ loading: true });
    say('Loading…');
    setTimeout(() => {
      grid.setRows(rows);
      grid.setOptions({ loading: false });
      say('Loaded.');
    }, 1500);
  },
  rows: (grid) => {
    eight = !eight;
    grid.setOptions({ overlays: { loading: 'skeleton', skeletonRows: eight ? 8 : 3 } });
    say(`${eight ? 8 : 3} skeleton rows`);
  },
};