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

배율을 자동으로 재기Measure the scale automatically

scale: 'auto'는 그리드가 스스로 화면 폭과 배치 폭의 비를 재요. 부모 배율이 자주 바뀌는 화면에서는 값을 알려 줄 필요가 없어요. getScale()로 지금 잰 값을 볼 수 있어요.scale: 'auto' makes the grid measure the ratio of screen width to layout width itself, so a screen whose parent factor keeps changing needs no value. getScale() returns the measured factor.

심화Advanced
직접 써 보기Live preview배율을 자동으로 재기Measure the scale automatically

코드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="z50">부모 50%</button>
    <button type="button" id="z75">부모 75%</button>
    <button type="button" id="z100">부모 100%</button>
    <button type="button" id="now">지금 배율</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('z50').addEventListener('click', () => actions.z50(api));
document.getElementById('z75').addEventListener('click', () => actions.z75(api));
document.getElementById('z100').addEventListener('click', () => actions.z100(api));
document.getElementById('now').addEventListener('click', () => actions.now(api));
example.js
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 140 },
    { id: 'team', title: '팀', width: 120 },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    name: `사원 ${i + 1}`,
    team: ['개발', '디자인', '영업'][i % 3],
  })),
  rowKey: 'id',
  scale: 'auto',
};
let say = () => { };
let holder = null;
export function setup(api, log) {
  say = log;
  holder = api.getGridElement().parentElement;
  return () => {
    if (holder !== null)
      holder.style.cssText = '';
  };
}
function zoom(api, factor) {
  if (holder === null)
    return;
  holder.style.transform = `scale(${factor})`;
  holder.style.transformOrigin = 'top left';
  holder.style.width = `${100 / factor}%`;
  say({ ko: `부모 배율 ${factor}`, en: `Parent factor ${factor}` });
  void api;
}
export const actions = {
  z50: (api) => zoom(api, 0.5),
  z75: (api) => zoom(api, 0.75),
  z100: (api) => zoom(api, 1),
  now: (api) => {
    const value = Math.round(api.getScale() * 100) / 100;
    say({ ko: `잰 배율 ${value}`, en: `Measured scale ${value}` });
  },
};

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="z50">Parent 50%</button>
    <button type="button" id="z75">Parent 75%</button>
    <button type="button" id="z100">Parent 100%</button>
    <button type="button" id="now">Current scale</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('z50').addEventListener('click', () => actions.z50(api));
document.getElementById('z75').addEventListener('click', () => actions.z75(api));
document.getElementById('z100').addEventListener('click', () => actions.z100(api));
document.getElementById('now').addEventListener('click', () => actions.now(api));
example.js
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 140 },
    { id: 'team', title: 'Team', width: 120 },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    name: `Employee ${i + 1}`,
    team: ['Dev', 'Design', 'Sales'][i % 3],
  })),
  rowKey: 'id',
  scale: 'auto',
};
let say = () => { };
let holder = null;
export function setup(api, log) {
  say = log;
  holder = api.getGridElement().parentElement;
  return () => {
    if (holder !== null)
      holder.style.cssText = '';
  };
}
function zoom(api, factor) {
  if (holder === null)
    return;
  holder.style.transform = `scale(${factor})`;
  holder.style.transformOrigin = 'top left';
  holder.style.width = `${100 / factor}%`;
  say(`Parent factor ${factor}`);
  void api;
}
export const actions = {
  z50: (api) => zoom(api, 0.5),
  z75: (api) => zoom(api, 0.75),
  z100: (api) => zoom(api, 1),
  now: (api) => {
    const value = Math.round(api.getScale() * 100) / 100;
    say(`Measured scale ${value}`);
  },
};