배율이 걸린 컨테이너 안의 그리드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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));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', '칸 아래에 떠요'),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>배율이 걸린 컨테이너 안의 그리드</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const TEAMS = ['개발', '디자인', '영업'];
const FACTOR = 0.75;
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 = () => { };
// 예제 틀의 그리드 상자를 배율로 줄여 "배율이 걸린 조상"을 만든다.
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 = '';
};
}
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', '칸 아래에 떠요'),
};
options.ariaLabel = "배율이 걸린 컨테이너 안의 그리드";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('match').addEventListener('click', () => actions.match(api));
document.getElementById('ignore').addEventListener('click', () => actions.ignore(api));
document.getElementById('toast').addEventListener('click', () => actions.toast(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.match(api)}
>scale 0.75 (맞춤)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ignore(api)}
>scale 1 (무시)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.toast(api)}
>이름 칸에 토스트</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['개발', '디자인', '영업'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// 예제 틀의 그리드 상자를 배율로 줄여 "배율이 걸린 조상"을 만든다.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say({ ko: `scale ${api.getScale()}`, en: `scale ${api.getScale()}` });
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say({
ko: `scale ${api.getScale()}: 끈 거리와 폭이 어긋나요`,
en: `scale ${api.getScale()}: widths drift from the pointer`,
});
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', '칸 아래에 떠요'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.match(api)">scale 0.75 (맞춤)</button>
<button type="button" :disabled="!api" @click="api && actions.ignore(api)">scale 1 (무시)</button>
<button type="button" :disabled="!api" @click="api && actions.toast(api)">이름 칸에 토스트</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['개발', '디자인', '영업'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// 예제 틀의 그리드 상자를 배율로 줄여 "배율이 걸린 조상"을 만든다.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say({ ko: `scale ${api.getScale()}`, en: `scale ${api.getScale()}` });
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say({
ko: `scale ${api.getScale()}: 끈 거리와 폭이 어긋나요`,
en: `scale ${api.getScale()}: widths drift from the pointer`,
});
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', '칸 아래에 떠요'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.match(api)"
>scale 0.75 (맞춤)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ignore(api)"
>scale 1 (무시)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.toast(api)"
>이름 칸에 토스트</button>
</div>
<mx-grid style="height: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['개발', '디자인', '영업'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// 예제 틀의 그리드 상자를 배율로 줄여 "배율이 걸린 조상"을 만든다.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say({ ko: `scale ${api.getScale()}`, en: `scale ${api.getScale()}` });
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say({
ko: `scale ${api.getScale()}: 끈 거리와 폭이 어긋나요`,
en: `scale ${api.getScale()}: widths drift from the pointer`,
});
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', '칸 아래에 떠요'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<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>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));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'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A grid inside a scaled container</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const TEAMS = ['Dev', 'Design', 'Sales'];
const FACTOR = 0.75;
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".
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 = '';
};
}
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'),
};
options.ariaLabel = "A grid inside a scaled container";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('match').addEventListener('click', () => actions.match(api));
document.getElementById('ignore').addEventListener('click', () => actions.ignore(api));
document.getElementById('toast').addEventListener('click', () => actions.toast(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.match(api)}
>scale 0.75 (matched)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ignore(api)}
>scale 1 (ignored)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.toast(api)}
>Toast on Name</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// Shrink the example frame's grid box with a scale to make an "ancestor with a scale applied".
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say(`scale ${api.getScale()}`);
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say(`scale ${api.getScale()}: widths drift from the pointer`);
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', 'Floats below the cell'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.match(api)">scale 0.75 (matched)</button>
<button type="button" :disabled="!api" @click="api && actions.ignore(api)">scale 1 (ignored)</button>
<button type="button" :disabled="!api" @click="api && actions.toast(api)">Toast on Name</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// Shrink the example frame's grid box with a scale to make an "ancestor with a scale applied".
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say(`scale ${api.getScale()}`);
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say(`scale ${api.getScale()}: widths drift from the pointer`);
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', 'Floats below the cell'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.match(api)"
>scale 0.75 (matched)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ignore(api)"
>scale 1 (ignored)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.toast(api)"
>Toast on Name</button>
</div>
<mx-grid style="height: 340px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
}
const TEAMS = ['Dev', 'Design', 'Sales'];
const FACTOR = 0.75;
export const options: GridOptions<Row> = {
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] as string,
})),
rowKey: 'id',
scale: FACTOR,
columnMenu: true,
};
let say: (message: LogText) => void = () => {};
// Shrink the example frame's grid box with a scale to make an "ancestor with a scale applied".
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.setScale(FACTOR);
say(`scale ${api.getScale()}`);
},
ignore: (api: GridApi<Row>) => {
api.setScale(1);
say(`scale ${api.getScale()}: widths drift from the pointer`);
},
toast: (api: GridApi<Row>) => api.showCellToast(1, 'name', 'Floats below the cell'),
};