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

고정 컬럼을 한 번에 정하기Set the pinned columns at once

pinColumns는 왼쪽·오른쪽 고정 컬럼 전체를 한 번에 정해요. 적은 순서가 영역 안 순서이고, 이름이 없는 컬럼은 고정이 풀려요. showAllColumns는 숨긴 컬럼을 한꺼번에 다시 보여요.pinColumns sets the whole pinned set in one call. The given order is the order inside each zone, and unnamed columns are unpinned. showAllColumns brings every hidden column back.

입문Beginner
직접 써 보기Live preview고정 컬럼을 한 번에 정하기Set the pinned columns at once

코드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="both">양쪽 고정</button>
    <button type="button" id="none">모두 풀기</button>
    <button type="button" id="hide">이름·팀 숨기기</button>
    <button type="button" id="all">숨긴 것 모두 보이기</button>
  </div>
  <div id="grid" style="height: 220px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
example.js
const COLUMNS = [
  { id: 'id', title: '사번', width: 80, align: 'end' },
  { id: 'name', title: '이름', width: 110 },
  { id: 'team', title: '팀', width: 110 },
  { id: 'city', title: '근무지', width: 100 },
  { id: 'salary', title: '연봉(만원)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
  { id: 1001, name: '김민준', team: '개발팀', city: '서울', salary: 6200 },
  { id: 1002, name: '이서연', team: '디자인팀', city: '부산', salary: 4800 },
  { id: 1003, name: '박지호', team: '영업팀', city: '대구', salary: 7100 },
  { id: 1004, name: '최유나', team: '인사팀', city: '서울', salary: 3900 },
];
let say = () => { };
export const options = {
  columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
  rows: ROWS,
  rowKey: 'id',
};
export function setup(_api, log) {
  say = log;
  return () => { };
}
export const actions = {
  both: (api) => {
    api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
    say({
      ko: '왼쪽 사번·이름, 오른쪽 연봉을 고정했어요',
      en: 'Pinned id and name left, salary right',
    });
  },
  none: (api) => {
    api.pinColumns({});
    say({ ko: '고정을 모두 풀었어요', en: 'Unpinned everything' });
  },
  hide: (api) => {
    api.setColumnVisible('name', false);
    api.setColumnVisible('team', false);
  },
  all: (api) => api.showAllColumns(),
};

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="both">Pin both sides</button>
    <button type="button" id="none">Unpin all</button>
    <button type="button" id="hide">Hide Name and Team</button>
    <button type="button" id="all">Show all</button>
  </div>
  <div id="grid" style="height: 220px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('none').addEventListener('click', () => actions.none(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
example.js
const COLUMNS = [
  { id: 'id', title: 'Emp ID', width: 90, align: 'end' },
  { id: 'name', title: 'Name', width: 110 },
  { id: 'team', title: 'Team', width: 110 },
  { id: 'city', title: 'Office', width: 100 },
  { id: 'salary', title: 'Salary ($)', kind: 'number', width: 120, align: 'end' },
];
const ROWS = [
  { id: 1001, name: 'Liam Carter', team: 'Dev', city: 'Seattle', salary: 62000 },
  { id: 1002, name: 'Emma Stone', team: 'Design', city: 'Boston', salary: 48000 },
  { id: 1003, name: 'Noah Hayes', team: 'Sales', city: 'Denver', salary: 71000 },
  { id: 1004, name: 'Olivia Reed', team: 'HR', city: 'Seattle', salary: 39000 },
];
let say = () => { };
export const options = {
  columns: COLUMNS.map((c) => ({ ...c, width: 220 })),
  rows: ROWS,
  rowKey: 'id',
};
export function setup(_api, log) {
  say = log;
  return () => { };
}
export const actions = {
  both: (api) => {
    api.pinColumns({ start: ['id', 'name'], end: ['salary'] });
    say('Pinned id and name left, salary right');
  },
  none: (api) => {
    api.pinColumns({});
    say('Unpinned everything');
  },
  hide: (api) => {
    api.setColumnVisible('name', false);
    api.setColumnVisible('team', false);
  },
  all: (api) => api.showAllColumns(),
};