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

헤더 높이를 넉넉하게, 또는 촘촘하게Make the header taller or tighter

헤더 높이 설정 하나로 헤더 한 줄의 높이를 정해요. 헤더가 두 단이면 모든 단이 같은 높이로 늘고 줄어요. 제목이 두 줄인 칸은 헤더를 높이면 잘리지 않고 다 보여요.One header height setting sets the height of a header line. With two-level headers every level grows and shrinks together. Raise it and a two-line title is no longer cut off.

입문Beginner
직접 써 보기Live preview헤더 높이를 넉넉하게, 또는 촘촘하게Make the header taller or tighter

코드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="height">
      <option value="24">24px (촘촘하게)</option>
      <option value="36" selected>36px (기본)</option>
      <option value="48">48px</option>
      <option value="64">64px (넉넉하게)</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('height').addEventListener('change', (event) => actions.height(api, event.target.value));
example.js
const teams = ['개발1팀', '개발2팀', '디자인팀', '영업팀', '운영팀', '인사팀'];
// headerHeight는 헤더 한 줄의 높이(px)예요. 헤더가 두 단이면 두 줄 모두 같은 높이로 늘고 줄어요(줄마다 다르게는 정할 수 없어요).
// 제목에 줄바꿈(\n)을 넣은 칸은 헤더를 높여야 두 줄이 다 보여요.
export const options = {
  columns: [
    { id: 'team', title: '팀\n(소속)', width: 130 },
    ...['q1', 'q2', 'q3', 'q4'].map((id, i) => ({
      id,
      title: `${i + 1}분기`,
      kind: 'number',
      width: 110,
      align: 'end',
    })),
  ],
  headerGroups: [
    { id: 'sales', title: '분기별 매출\n(단위: 만 원)', children: ['q1', 'q2', 'q3', 'q4'] },
  ],
  rows: teams.map((team, i) => ({
    id: i + 1,
    team,
    q1: 2100 + ((i * 410) % 900),
    q2: 2300 + ((i * 330) % 800),
    q3: 1900 + ((i * 520) % 1100),
    q4: 2600 + ((i * 270) % 700),
  })),
  rowKey: 'id',
  headerHeight: 36,
};
export const actions = {
  height: (api, value) => api.setOptions({ headerHeight: Number(value ?? 36) }),
};

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="Header row height" id="height">
      <option value="24">24px (tight)</option>
      <option value="36" selected>36px (default)</option>
      <option value="48">48px</option>
      <option value="64">64px (roomy)</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('height').addEventListener('change', (event) => actions.height(api, event.target.value));
example.js
const teams = ['Dev 1', 'Dev 2', 'Design', 'Sales', 'Ops', 'HR'];
// headerHeight is the height of one header row in px. With a two-level header both rows grow and shrink to the same height (you cannot set it per row).
// A cell whose title contains a line break (\n) needs a taller header to show both lines.
export const options = {
  columns: [
    { id: 'team', title: 'Team\n(Dept.)', width: 130 },
    ...['q1', 'q2', 'q3', 'q4'].map((id, i) => ({
      id,
      title: `Q${i + 1}`,
      kind: 'number',
      width: 110,
      align: 'end',
    })),
  ],
  headerGroups: [
    { id: 'sales', title: 'Sales by quarter\n($)', children: ['q1', 'q2', 'q3', 'q4'] },
  ],
  rows: teams.map((team, i) => ({
    id: i + 1,
    team,
    q1: 10 * (2100 + ((i * 410) % 900)),
    q2: 10 * (2300 + ((i * 330) % 800)),
    q3: 10 * (1900 + ((i * 520) % 1100)),
    q4: 10 * (2600 + ((i * 270) % 700)),
  })),
  rowKey: 'id',
  headerHeight: 36,
};
export const actions = {
  height: (api, value) => api.setOptions({ headerHeight: Number(value ?? 36) }),
};