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

행 수에 맞춰 자라는 그리드 높이Grid height that follows the row count

autoGridHeight: { maxRows: 8 }이면 그리드 높이가 머리글 + 줄 수에 맞춰지고, 8줄이 넘으면 그 높이에서 스크롤해요. 컨테이너가 높이를 정하지 않아도 돼요.With autoGridHeight: { maxRows: 8 } the grid is as tall as the header plus its rows, and scrolls past 8 rows. The container does not need a height.

입문Beginner
직접 써 보기Live preview행 수에 맞춰 자라는 그리드 높이Grid height that follows the row count

코드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="few">3줄</button>
    <button type="button" id="some">6줄</button>
    <button type="button" id="many">30줄</button>
  </div>
  <div id="grid" style="height: 360px"></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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(api));
example.js
const make = (count) => Array.from({ length: count }, (_, i) => ({
  id: i + 1,
  name: `사원 ${i + 1}`,
  team: ['개발', '디자인', '영업'][i % 3],
}));
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 140 },
    { id: 'team', title: '팀', width: 120 },
  ],
  rows: make(4),
  rowKey: 'id',
  autoGridHeight: { maxRows: 8 },
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
export const actions = {
  few: (api) => {
    api.setRows(make(3));
    say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
  },
  some: (api) => {
    api.setRows(make(6));
    say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
  },
  many: (api) => {
    api.setRows(make(30));
    say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
  },
};

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="few">3 rows</button>
    <button type="button" id="some">6 rows</button>
    <button type="button" id="many">30 rows</button>
  </div>
  <div id="grid" style="height: 360px"></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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(api));
example.js
const make = (count) => Array.from({ length: count }, (_, i) => ({
  id: i + 1,
  name: `Employee ${i + 1}`,
  team: ['Dev', 'Design', 'Sales'][i % 3],
}));
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 140 },
    { id: 'team', title: 'Team', width: 120 },
  ],
  rows: make(4),
  rowKey: 'id',
  autoGridHeight: { maxRows: 8 },
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
export const actions = {
  few: (api) => {
    api.setRows(make(3));
    say('3 rows: the grid shrinks');
  },
  some: (api) => {
    api.setRows(make(6));
    say('6 rows: as tall as the rows');
  },
  many: (api) => {
    api.setRows(make(30));
    say('30 rows: stops at 8 rows and scrolls');
  },
};