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

줄마다 다른 높이Different row heights

우선순위가 높은 업무 줄은 크게, 낮은 줄은 작게 보여 줘요. 줄마다 높이를 다르게 정할 수 있어요.High-priority task rows are tall and low-priority rows are short. Each row can have its own height.

활용Intermediate
직접 써 보기Live preview줄마다 다른 높이Different row heights

코드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="taller">높음 키우기</button>
    <button type="button" id="shorter">높음 줄이기</button>
  </div>
  <div id="grid" style="height: 420px"></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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));
example.js
const titles = [
  '로그인 이동 오류 수정',
  '가격 페이지 갱신',
  '데이터베이스 이전',
  '배포 노트 작성',
  '코드 검토',
  '다음 스프린트 계획',
  '오래된 티켓 정리',
  '백업 점검',
];
let tall = 64;
// 줄 높이는 함수로 정해요. 우선순위가 높으면 크게, 낮으면 작게 보여요(그룹·총계 줄은 기본 높이를 써요).
const heightOf = (row) => row.priority === '높음' ? tall : row.priority === '보통' ? 40 : 28;
export const options = {
  columns: [
    { id: 'title', title: '업무', width: 190 },
    { id: 'priority', title: '우선순위', width: 90 },
    {
      id: 'height',
      title: '줄 높이(px)',
      kind: 'number',
      width: 100,
      align: 'end',
      getValue: (row) => heightOf(row),
    },
  ],
  rows: Array.from({ length: 8 }, (_, i) => ({
    id: i + 1,
    title: titles[i % titles.length],
    priority: ['높음', '보통', '낮음', '보통'][i % 4],
  })),
  rowKey: 'id',
  rowHeight: heightOf,
};
let say = () => { };
export function setup(_api, log) {
  tall = 64;
  say = log;
  log({
    ko: '우선순위가 높은 줄은 64px, 보통은 40px, 낮음은 28px이에요.',
    en: 'High priority rows are 64px, normal 40px, low 28px.',
  });
}
export const actions = {
  // 함수가 바깥 값을 읽으니, 그리드에 다시 재라고 알려야 해요.
  taller: (api) => {
    tall += 16;
    api.refresh();
    say({ ko: `높음 줄을 ${tall}px로 키웠어요.`, en: `High rows enlarged to ${tall}px.` });
  },
  shorter: (api) => {
    tall = Math.max(32, tall - 16);
    api.refresh();
    say({ ko: `높음 줄을 ${tall}px로 줄였어요.`, en: `High rows reduced to ${tall}px.` });
  },
};

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="taller">Taller high rows</button>
    <button type="button" id="shorter">Shorter high rows</button>
  </div>
  <div id="grid" style="height: 420px"></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('taller').addEventListener('click', () => actions.taller(api));
document.getElementById('shorter').addEventListener('click', () => actions.shorter(api));
example.js
const titles = [
  'Fix login redirect bug',
  'Update pricing page',
  'Migrate the database',
  'Write release notes',
  'Code review',
  'Plan the next sprint',
  'Clean up old tickets',
  'Check backups',
];
let tall = 64;
// Row height is set by a function. Higher priority rows are taller, lower ones shorter (group and total rows use the default height).
const heightOf = (row) => row.priority === 'High' ? tall : row.priority === 'Normal' ? 40 : 28;
export const options = {
  columns: [
    { id: 'title', title: 'Task', width: 190 },
    { id: 'priority', title: 'Priority', width: 90 },
    {
      id: 'height',
      title: 'Row height (px)',
      kind: 'number',
      width: 100,
      align: 'end',
      getValue: (row) => heightOf(row),
    },
  ],
  rows: Array.from({ length: 8 }, (_, i) => ({
    id: i + 1,
    title: titles[i % titles.length],
    priority: ['High', 'Normal', 'Low', 'Normal'][i % 4],
  })),
  rowKey: 'id',
  rowHeight: heightOf,
};
let say = () => { };
export function setup(_api, log) {
  tall = 64;
  say = log;
  log('High priority rows are 64px, normal 40px, low 28px.');
}
export const actions = {
  // The function reads an outside value, so the grid must be told to measure again.
  taller: (api) => {
    tall += 16;
    api.refresh();
    say(`High rows enlarged to ${tall}px.`);
  },
  shorter: (api) => {
    tall = Math.max(32, tall - 16);
    api.refresh();
    say(`High rows reduced to ${tall}px.`);
  },
};