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

헤더 ⋮ 메뉴로 정렬·고정·숨기기Sort, pin and hide from the header menu

설정 한 줄로 헤더마다 ⋮ 메뉴가 생겨요. 정렬, 왼쪽·오른쪽 고정, 숨기기, 자동 맞춤, 컬럼 선택, 초기화가 들어 있고, 컬럼 설정(정렬 불가, 폭 고정, 최대 폭)에 따라 메뉴가 알아서 달라져요.One setting adds a ⋮ menu to every header with sort, pin left or right, hide, auto fit, column chooser and reset. The menu adapts to column settings such as not sortable, fixed width or maximum width.

입문Beginner
직접 써 보기Live preview헤더 ⋮ 메뉴로 정렬·고정·숨기기Sort, pin and hide from the header menu

코드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="lock">
      <option value="free" selected>허용 (기본)</option>
      <option value="locked">전체 잠금</option>
    </select>
  </div>
  <div id="grid" style="height: 320px"></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('lock').addEventListener('change', (event) => actions.lock(api, event.target.value));
example.js
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
const notes = [
  '작년 봄에 플랫폼 팀으로 합류했고 결제 연동을 맡고 있어요',
  '디자인 시스템 정비',
  '해외 거래처 담당',
  '신규 입점 상담',
  '재고 시스템 이관',
];
const cities = ['서울', '부산', '대구', '제주', '광주'];
// columnMenu: true면 헤더마다 ⋮ 버튼이 생겨요. 헤더를 오른쪽 클릭하거나, 셀을 고르고 Alt+↓를 눌러도 같은 메뉴가 열려요.
// 메뉴는 컬럼 설정을 존중해요: sortable: false면 정렬 항목이 빠지고, resizable: false면 자동 맞춤이 꺼지고,
// maxWidth가 있으면 자동 맞춤이 그 폭까지만 가요.
export const options = {
  columnMenu: true,
  columns: [
    { id: 'id', title: '번호', width: 70, align: 'end' },
    { id: 'name', title: '이름 (정렬 안 됨)', width: 150, sortable: false },
    { id: 'note', title: '메모 (최대 240px)', width: 150, maxWidth: 240 },
    {
      id: 'score',
      title: '점수 (폭 고정)',
      kind: 'number',
      width: 130,
      resizable: false,
      align: 'end',
    },
    { id: 'city', title: '근무지', width: 110 },
  ],
  headerGroups: [{ id: 'info', title: '인적 사항', collapsible: true, children: ['name', 'note'] }],
  rows: Array.from({ length: 5 }, (_, i) => ({
    id: i + 1,
    name: names[i],
    note: notes[i],
    score: 70 + ((i * 17) % 30),
    city: cities[i],
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const offs = [
    api.on('columnResized', (e) => log({
      ko: `${e.columnId} 폭 ${e.width}px (${e.source})`,
      en: `${e.columnId} width ${e.width}px (${e.source})`,
    })),
    api.on('columnPinned', (e) => log({
      ko: `${e.columnId} 고정: ${e.pinned ?? '해제'} (${e.source})`,
      en: `${e.columnId} pinned: ${e.pinned ?? 'none'} (${e.source})`,
    })),
    api.on('columnVisibilityChanged', (e) => log({
      ko: `${e.columnId} ${e.hidden ? '숨김' : '표시'} (${e.source})`,
      en: `${e.columnId} ${e.hidden ? 'hidden' : 'shown'} (${e.source})`,
    })),
    api.on('sortChanged', (e) => log({
      ko: `정렬: ${e.sortModel.map((s) => `${s.columnId} ${s.direction}`).join(', ') || '없음'}`,
      en: `Sort: ${e.sortModel.map((s) => `${s.columnId} ${s.direction}`).join(', ') || 'none'}`,
    })),
    api.on('columnStateReset', (e) => log({ ko: `초기화 (${e.source})`, en: `Reset (${e.source})` })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  lock: (api, value) => api.setOptions({ columnsResizable: value !== 'locked' }),
};

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="Resizing" id="lock">
      <option value="free" selected>Allowed (default)</option>
      <option value="locked">Locked for all</option>
    </select>
  </div>
  <div id="grid" style="height: 320px"></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('lock').addEventListener('change', (event) => actions.lock(api, event.target.value));
example.js
const names = ['Liam Carter', 'Emma Stone', 'Noah Hayes', 'Olivia Reed', 'Ethan Cole'];
const notes = [
  'Joined the platform team last spring and owns the payment integration',
  'Design system cleanup',
  'Overseas accounts',
  'New listing consultations',
  'Inventory system migration',
];
const cities = ['Seattle', 'Boston', 'Denver', 'Honolulu', 'Austin'];
// columnMenu: true adds a ⋮ button to every header. Right-clicking a header, or selecting a cell and pressing Alt+Down, opens the same menu.
// The menu respects column settings: sortable: false drops the sort items, resizable: false turns off auto fit,
// and with maxWidth auto fit only goes up to that width.
export const options = {
  columnMenu: true,
  columns: [
    { id: 'id', title: 'No', width: 70, align: 'end' },
    { id: 'name', title: 'Name (not sortable)', width: 150, sortable: false },
    { id: 'note', title: 'Note (max 240px)', width: 150, maxWidth: 240 },
    {
      id: 'score',
      title: 'Score (fixed width)',
      kind: 'number',
      width: 130,
      resizable: false,
      align: 'end',
    },
    { id: 'city', title: 'City', width: 110 },
  ],
  headerGroups: [{ id: 'info', title: 'Personal', collapsible: true, children: ['name', 'note'] }],
  rows: Array.from({ length: 5 }, (_, i) => ({
    id: i + 1,
    name: names[i],
    note: notes[i],
    score: 70 + ((i * 17) % 30),
    city: cities[i],
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const offs = [
    api.on('columnResized', (e) => log(`${e.columnId} width ${e.width}px (${e.source})`)),
    api.on('columnPinned', (e) => log(`${e.columnId} pinned: ${e.pinned ?? 'none'} (${e.source})`)),
    api.on('columnVisibilityChanged', (e) => log(`${e.columnId} ${e.hidden ? 'hidden' : 'shown'} (${e.source})`)),
    api.on('sortChanged', (e) => log(`Sort: ${e.sortModel.map((s) => `${s.columnId} ${s.direction}`).join(', ') || 'none'}`)),
    api.on('columnStateReset', (e) => log(`Reset (${e.source})`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  lock: (api, value) => api.setOptions({ columnsResizable: value !== 'locked' }),
};