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

행이 미끄러지는 움직임Rows that slide

motion: true면 정렬·행 추가·삭제에서 행이 제자리로 미끄러지고, 새 행은 나타나며, 지운 행은 사라져요. 필터 메뉴 같은 팝업도 부드럽게 열려요. 기본은 꺼져 있고 모션 줄이기 설정을 따라요.With motion: true rows slide into place on sort, add and remove, new rows fade in and removed rows fade out. Popups such as the filter menu open softly. It is off by default and follows the reduced-motion setting.

입문Beginner
직접 써 보기Live preview행이 미끄러지는 움직임Rows that slide

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

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

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

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="sort">정렬 바꾸기</button>
    <button type="button" id="add">행 추가</button>
    <button type="button" id="remove">행 삭제</button>
    <button type="button" id="motion">움직임 켜기·끄기</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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('add').addEventListener('click', () => actions.add(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('motion').addEventListener('click', () => actions.motion(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
const rows = Array.from({ length: 14 }, (_, i) => ({
  id: i + 1,
  name: `${en ? 'Item' : '항목'} ${String.fromCharCode(65 + i)}`,
  score: (i * 37) % 100,
}));
let nextId = 100;
export const options = {
  columns: [
    { id: 'name', title: en ? 'Name' : '이름', width: 160, sortable: true },
    { id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 110, sortable: true },
  ],
  rows,
  rowKey: 'id',
  // motion: true면 정렬·추가·삭제에서 행이 미끄러지고 팝업이 부드럽게 열려요(기본은 꺼짐).
  motion: true,
};
export const actions = {
  add: (api) => {
    nextId += 1;
    api.addRows([{ id: nextId, name: `${en ? 'New' : '새 항목'} ${nextId}`, score: nextId % 100 }], 2);
  },
  remove: (api) => {
    const row = api.getVisibleRows()[2];
    if (row)
      api.removeRows([row.id]);
  },
  sort: (api) => {
    const asc = api.getSortModel()[0]?.direction !== 'asc';
    api.setSortModel([{ columnId: 'score', direction: asc ? 'asc' : 'desc' }]);
  },
  motion: (api) => api.setOptions({ motion: !api.getOptions().motion }),
};

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="sort">Toggle sort</button>
    <button type="button" id="add">Add row</button>
    <button type="button" id="remove">Remove row</button>
    <button type="button" id="motion">Motion on/off</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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('sort').addEventListener('click', () => actions.sort(api));
document.getElementById('add').addEventListener('click', () => actions.add(api));
document.getElementById('remove').addEventListener('click', () => actions.remove(api));
document.getElementById('motion').addEventListener('click', () => actions.motion(api));
example.js
const rows = Array.from({ length: 14 }, (_, i) => ({
  id: i + 1,
  name: `Item ${String.fromCharCode(65 + i)}`,
  score: (i * 37) % 100,
}));
let nextId = 100;
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 160, sortable: true },
    { id: 'score', title: 'Score', kind: 'number', width: 110, sortable: true },
  ],
  rows,
  rowKey: 'id',
  // With motion: true, rows slide on sort, add and remove, and popups open smoothly (off by default).
  motion: true,
};
export const actions = {
  add: (api) => {
    nextId += 1;
    api.addRows([{ id: nextId, name: `New ${nextId}`, score: nextId % 100 }], 2);
  },
  remove: (api) => {
    const row = api.getVisibleRows()[2];
    if (row)
      api.removeRows([row.id]);
  },
  sort: (api) => {
    const asc = api.getSortModel()[0]?.direction !== 'asc';
    api.setSortModel([{ columnId: 'score', direction: asc ? 'asc' : 'desc' }]);
  },
  motion: (api) => api.setOptions({ motion: !api.getOptions().motion }),
};