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

배율이 걸린 컨테이너 안의 그리드A grid inside a scaled container

부모에 transform: scale(0.75)가 걸려 있어도 scale 옵션에 같은 값을 주면 컬럼 폭 끌기와 토스트 위치가 맞아요. 값을 1로 되돌리면 끄는 만큼 폭이 따라오지 않는 것을 볼 수 있어요.Even when the parent has transform: scale(0.75), giving the scale option the same value keeps column-resize drags and toast placement right. Setting it back to 1 shows the width no longer follows the pointer.

심화Advanced
직접 써 보기Live preview배율이 걸린 컨테이너 안의 그리드A grid inside a scaled container

코드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="match">scale 0.75 (맞춤)</button>
    <button type="button" id="ignore">scale 1 (무시)</button>
    <button type="button" id="toast">이름 칸에 토스트</button>
  </div>
  <div id="grid" style="height: 340px"></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('match').addEventListener('click', () => actions.match(api));
document.getElementById('ignore').addEventListener('click', () => actions.ignore(api));
document.getElementById('toast').addEventListener('click', () => actions.toast(api));
example.js
const TEAMS = ['개발', '디자인', '영업'];
const FACTOR = 0.75;
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 140 },
    { id: 'team', title: '팀', width: 120, headerTooltip: '팀 설명' },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    name: `사원 ${i + 1}`,
    team: TEAMS[i % 3],
  })),
  rowKey: 'id',
  scale: FACTOR,
  columnMenu: true,
};
let say = () => { };
// 예제 틀의 그리드 상자를 배율로 줄여 "배율이 걸린 조상"을 만든다.
export function setup(api, log) {
  say = log;
  const holder = api.getGridElement().parentElement;
  if (holder !== null) {
    holder.style.transform = `scale(${FACTOR})`;
    holder.style.transformOrigin = 'top left';
    holder.style.width = `${100 / FACTOR}%`;
  }
  const off = api.on('columnResized', (e) => say({
    ko: `${e.columnId} 폭 ${Math.round(e.width)}px`,
    en: `${e.columnId} width ${Math.round(e.width)}px`,
  }));
  return () => {
    off();
    if (holder !== null)
      holder.style.cssText = '';
  };
}
export const actions = {
  match: (api) => {
    api.setScale(FACTOR);
    say({ ko: `scale ${api.getScale()}`, en: `scale ${api.getScale()}` });
  },
  ignore: (api) => {
    api.setScale(1);
    say({
      ko: `scale ${api.getScale()}: 끈 거리와 폭이 어긋나요`,
      en: `scale ${api.getScale()}: widths drift from the pointer`,
    });
  },
  toast: (api) => api.showCellToast(1, 'name', '칸 아래에 떠요'),
};

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="match">scale 0.75 (matched)</button>
    <button type="button" id="ignore">scale 1 (ignored)</button>
    <button type="button" id="toast">Toast on Name</button>
  </div>
  <div id="grid" style="height: 340px"></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('match').addEventListener('click', () => actions.match(api));
document.getElementById('ignore').addEventListener('click', () => actions.ignore(api));
document.getElementById('toast').addEventListener('click', () => actions.toast(api));
example.js
const TEAMS = ['Dev', 'Design', 'Sales'];
const FACTOR = 0.75;
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 140 },
    { id: 'team', title: 'Team', width: 120, headerTooltip: 'Team description' },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    name: `Employee ${i + 1}`,
    team: TEAMS[i % 3],
  })),
  rowKey: 'id',
  scale: FACTOR,
  columnMenu: true,
};
let say = () => { };
// Shrink the example frame's grid box with a scale to make an "ancestor with a scale applied".
export function setup(api, log) {
  say = log;
  const holder = api.getGridElement().parentElement;
  if (holder !== null) {
    holder.style.transform = `scale(${FACTOR})`;
    holder.style.transformOrigin = 'top left';
    holder.style.width = `${100 / FACTOR}%`;
  }
  const off = api.on('columnResized', (e) => say(`${e.columnId} width ${Math.round(e.width)}px`));
  return () => {
    off();
    if (holder !== null)
      holder.style.cssText = '';
  };
}
export const actions = {
  match: (api) => {
    api.setScale(FACTOR);
    say(`scale ${api.getScale()}`);
  },
  ignore: (api) => {
    api.setScale(1);
    say(`scale ${api.getScale()}: widths drift from the pointer`);
  },
  toast: (api) => api.showCellToast(1, 'name', 'Floats below the cell'),
};