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

컬럼 숨김·이동·고정 잠그기Lock hiding, moving and pinning

locked로 컬럼마다 숨김(visible)·이동(position)·고정(pin)을 막아요. 메뉴 항목은 사라지지 않고 흐려지고, API는 invalid-option을 던지고, 저장한 상태를 복원해도 잠긴 속성은 지금 그대로예요.locked blocks hiding (visible), moving (position) and pinning (pin) per column. Menu items are dimmed instead of removed, the API throws invalid-option, and restoring a saved state keeps locked properties as they are.

활용Intermediate
직접 써 보기Live preview컬럼 숨김·이동·고정 잠그기Lock hiding, moving and pinning

코드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="hide">이름 숨겨 보기</button>
    <button type="button" id="move">이름 옮겨 보기</button>
    <button type="button" id="pin">사번 고정해 보기</button>
    <button type="button" id="restore">저장본 복원</button>
  </div>
  <div id="grid" style="height: 260px"></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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));
example.js
const ROWS = [
  { id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200, bonus: 620 },
  { id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800, bonus: 480 },
  { id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100, bonus: 710 },
  { id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900, bonus: 390 },
];
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
const attempt = (run, ok) => {
  try {
    run();
    say(ok);
  }
  catch (error) {
    say({
      ko: `막혔어요: ${error.message}`,
      en: `Refused: ${error.message}`,
    });
  }
};
const COLUMNS = [
  { id: 'id', title: '사번', width: 90, align: 'end', locked: true },
  { id: 'name', title: '이름', width: 120, locked: { position: true, visible: true } },
  { id: 'team', title: '팀', width: 120 },
  { id: 'city', title: '근무지', width: 110 },
  { id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
export const options = {
  columns: COLUMNS,
  rows: ROWS,
  rowKey: 'id',
  columnMenu: true,
};
export const actions = {
  hide: (api) => attempt(() => api.setColumnVisible('name', false), { ko: '이름을 숨겼어요', en: 'Hid Name' }),
  move: (api) => attempt(() => api.moveColumn('name', 4), { ko: '이름을 옮겼어요', en: 'Moved Name' }),
  pin: (api) => attempt(() => api.pinColumn('id', 'start'), { ko: '사번을 고정했어요', en: 'Pinned Id' }),
  restore: (api) => {
    api.setColumnState([
      { id: 'team', width: 140, hidden: false, pinned: null },
      { id: 'city', width: 100, hidden: false, pinned: null },
      { id: 'salary', width: 130, hidden: false, pinned: null },
      { id: 'name', width: 150, hidden: true, pinned: null },
      { id: 'id', width: 90, hidden: true, pinned: 'end' },
    ]);
    say({
      ko: '저장본을 적용했어요. 이름·사번의 숨김·위치·고정은 그대로고 폭만 바뀌었어요',
      en: 'Applied the saved state. Name and Id keep hidden, position and pin; only widths changed',
    });
  },
};

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="hide">Try hiding Name</button>
    <button type="button" id="move">Try moving Name</button>
    <button type="button" id="pin">Try pinning Emp ID</button>
    <button type="button" id="restore">Restore saved state</button>
  </div>
  <div id="grid" style="height: 260px"></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('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('move').addEventListener('click', () => actions.move(api));
document.getElementById('pin').addEventListener('click', () => actions.pin(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));
example.js
const ROWS = [
  { id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000, bonus: 6200 },
  { id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000, bonus: 4800 },
  { id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000, bonus: 7100 },
  { id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000, bonus: 3900 },
];
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
const attempt = (run, ok) => {
  try {
    run();
    say(ok);
  }
  catch (error) {
    say(`Refused: ${error.message}`);
  }
};
const COLUMNS = [
  { id: 'id', title: 'Emp ID', width: 90, align: 'end', locked: true },
  { id: 'name', title: 'Name', width: 120, locked: { position: true, visible: true } },
  { id: 'team', title: 'Team', width: 120 },
  { id: 'city', title: 'Office', width: 110 },
  { id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
export const options = {
  columns: COLUMNS,
  rows: ROWS,
  rowKey: 'id',
  columnMenu: true,
};
export const actions = {
  hide: (api) => attempt(() => api.setColumnVisible('name', false), 'Hid Name'),
  move: (api) => attempt(() => api.moveColumn('name', 4), 'Moved Name'),
  pin: (api) => attempt(() => api.pinColumn('id', 'start'), 'Pinned Id'),
  restore: (api) => {
    api.setColumnState([
      { id: 'team', width: 140, hidden: false, pinned: null },
      { id: 'city', width: 100, hidden: false, pinned: null },
      { id: 'salary', width: 130, hidden: false, pinned: null },
      { id: 'name', width: 150, hidden: true, pinned: null },
      { id: 'id', width: 90, hidden: true, pinned: 'end' },
    ]);
    say('Applied the saved state. Name and Id keep hidden, position and pin; only widths changed');
  },
};