그리드 크기 바꾸기Change the grid size
그리드는 담고 있는 상자의 크기를 그대로 따라가요. 상자의 너비와 높이만 바꾸면 컬럼 폭과 보이는 행 수가 스스로 다시 맞춰져요. 크기를 알려 주는 별도의 호출은 필요 없어요.The grid follows the size of the box that holds it. Change the box's width and height and the column widths and visible rows adjust by themselves. No resize call is needed.
코드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">
<select aria-label="그리드 크기" id="size">
<option value="small">작게 (320 × 220)</option>
<option value="medium" selected>보통 (520 × 300)</option>
<option value="full">가득 채우기 (가로 100% × 420)</option>
</select>
</div>
<div id="grid" style="height: 420px"></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('size').addEventListener('change', (event) => actions.size(api, event.target.value));const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const cities = ['서울', '부산', '대구', '인천', '광주', '대전'];
const products = ['무선 이어폰', '노트북 14형', '스마트워치', '태블릿 11형', '보조배터리'];
export const options = {
columns: [
{ id: 'name', title: '이름', width: 90 },
{ id: 'city', title: '지역', width: 80 },
{ id: 'product', title: '상품', width: 140 },
{ id: 'quantity', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29000 + ((i * 7919) % 40) * 10000,
})),
rowKey: 'id',
columnFit: 'fill', // 컬럼이 남는 폭을 나눠 가져요. 폭이 줄면 가로 스크롤이 생겨요.
};
// 그리드에는 resize() 같은 호출이 없어요. 그리드는 담고 있는 상자(컨테이너)의 크기를 따라가요.
// 그래서 크기를 바꾸려면 컨테이너의 width·height만 바꾸면 되고, 그리드가 스스로 다시 맞춰요.
const SIZES = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say = () => { };
function container() {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name) {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box)
return;
box.style.maxWidth = '100%'; // 화면이 좁으면 고정 폭도 화면 폭까지만 늘어나요.
box.style.width = size[0];
box.style.height = size[1];
say({
ko: `컨테이너를 ${size[0]} × ${size[1]}로 바꿨어요.`,
en: `Container resized to ${size[0]} × ${size[1]}.`,
});
}
export function setup(_api, log) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api, value) => resizeTo(value ?? 'medium'),
};<!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">
<select aria-label="그리드 크기" id="size">
<option value="small">작게 (320 × 220)</option>
<option value="medium" selected>보통 (520 × 300)</option>
<option value="full">가득 채우기 (가로 100% × 420)</option>
</select>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const cities = ['서울', '부산', '대구', '인천', '광주', '대전'];
const products = ['무선 이어폰', '노트북 14형', '스마트워치', '태블릿 11형', '보조배터리'];
const options = {
columns: [
{ id: 'name', title: '이름', width: 90 },
{ id: 'city', title: '지역', width: 80 },
{ id: 'product', title: '상품', width: 140 },
{ id: 'quantity', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29000 + ((i * 7919) % 40) * 10000,
})),
rowKey: 'id',
columnFit: 'fill', // 컬럼이 남는 폭을 나눠 가져요. 폭이 줄면 가로 스크롤이 생겨요.
};
// 그리드에는 resize() 같은 호출이 없어요. 그리드는 담고 있는 상자(컨테이너)의 크기를 따라가요.
// 그래서 크기를 바꾸려면 컨테이너의 width·height만 바꾸면 되고, 그리드가 스스로 다시 맞춰요.
const SIZES = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say = () => { };
function container() {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name) {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box)
return;
box.style.maxWidth = '100%'; // 화면이 좁으면 고정 폭도 화면 폭까지만 늘어나요.
box.style.width = size[0];
box.style.height = size[1];
say({
ko: `컨테이너를 ${size[0]} × ${size[1]}로 바꿨어요.`,
en: `Container resized to ${size[0]} × ${size[1]}.`,
});
}
function setup(_api, log) {
say = log;
resizeTo('medium');
}
const actions = {
size: (_api, value) => resizeTo(value ?? 'medium'),
};
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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
</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">
<select
aria-label="그리드 크기"
disabled={!api}
onChange={(event) => api && actions.size(api, event.target.value)}
>
<option value="small">작게 (320 × 220)</option>
<option value="medium">보통 (520 × 300)</option>
<option value="full">가득 채우기 (가로 100% × 420)</option>
</select>
</div>
<Grid style={{ height: 420 }} 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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const cities = ['서울', '부산', '대구', '인천', '광주', '대전'];
const products = ['무선 이어폰', '노트북 14형', '스마트워치', '태블릿 11형', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 90 },
{ id: 'city', title: '지역', width: 80 },
{ id: 'product', title: '상품', width: 140 },
{ id: 'quantity', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29000 + ((i * 7919) % 40) * 10000,
})),
rowKey: 'id',
columnFit: 'fill', // 컬럼이 남는 폭을 나눠 가져요. 폭이 줄면 가로 스크롤이 생겨요.
};
// 그리드에는 resize() 같은 호출이 없어요. 그리드는 담고 있는 상자(컨테이너)의 크기를 따라가요.
// 그래서 크기를 바꾸려면 컨테이너의 width·height만 바꾸면 되고, 그리드가 스스로 다시 맞춰요.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // 화면이 좁으면 고정 폭도 화면 폭까지만 늘어나요.
box.style.width = size[0];
box.style.height = size[1];
say({
ko: `컨테이너를 ${size[0]} × ${size[1]}로 바꿨어요.`,
en: `Container resized to ${size[0]} × ${size[1]}.`,
});
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="그리드 크기"
:disabled="!api"
@change="api && actions.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="small">작게 (320 × 220)</option>
<option value="medium" selected>보통 (520 × 300)</option>
<option value="full">가득 채우기 (가로 100% × 420)</option>
</select>
</div>
<Grid style="height: 420px" :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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const cities = ['서울', '부산', '대구', '인천', '광주', '대전'];
const products = ['무선 이어폰', '노트북 14형', '스마트워치', '태블릿 11형', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 90 },
{ id: 'city', title: '지역', width: 80 },
{ id: 'product', title: '상품', width: 140 },
{ id: 'quantity', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29000 + ((i * 7919) % 40) * 10000,
})),
rowKey: 'id',
columnFit: 'fill', // 컬럼이 남는 폭을 나눠 가져요. 폭이 줄면 가로 스크롤이 생겨요.
};
// 그리드에는 resize() 같은 호출이 없어요. 그리드는 담고 있는 상자(컨테이너)의 크기를 따라가요.
// 그래서 크기를 바꾸려면 컨테이너의 width·height만 바꾸면 되고, 그리드가 스스로 다시 맞춰요.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // 화면이 좁으면 고정 폭도 화면 폭까지만 늘어나요.
box.style.width = size[0];
box.style.height = size[1];
say({
ko: `컨테이너를 ${size[0]} × ${size[1]}로 바꿨어요.`,
en: `Container resized to ${size[0]} × ${size[1]}.`,
});
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="그리드 크기"
[disabled]="!api"
(change)="api && actions.size(api, $any($event.target).value)"
>
<option value="small">작게 (320 × 220)</option>
<option value="medium" selected>보통 (520 × 300)</option>
<option value="full">가득 채우기 (가로 100% × 420)</option>
</select>
</div>
<mx-grid style="height: 420px" [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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const cities = ['서울', '부산', '대구', '인천', '광주', '대전'];
const products = ['무선 이어폰', '노트북 14형', '스마트워치', '태블릿 11형', '보조배터리'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 90 },
{ id: 'city', title: '지역', width: 80 },
{ id: 'product', title: '상품', width: 140 },
{ id: 'quantity', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '가격',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `${Number(v).toLocaleString('ko-KR')}원`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29000 + ((i * 7919) % 40) * 10000,
})),
rowKey: 'id',
columnFit: 'fill', // 컬럼이 남는 폭을 나눠 가져요. 폭이 줄면 가로 스크롤이 생겨요.
};
// 그리드에는 resize() 같은 호출이 없어요. 그리드는 담고 있는 상자(컨테이너)의 크기를 따라가요.
// 그래서 크기를 바꾸려면 컨테이너의 width·height만 바꾸면 되고, 그리드가 스스로 다시 맞춰요.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // 화면이 좁으면 고정 폭도 화면 폭까지만 늘어나요.
box.style.width = size[0];
box.style.height = size[1];
say({
ko: `컨테이너를 ${size[0]} × ${size[1]}로 바꿨어요.`,
en: `Container resized to ${size[0]} × ${size[1]}.`,
});
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Grid size" id="size">
<option value="small">Small (320 × 220)</option>
<option value="medium" selected>Medium (520 × 300)</option>
<option value="full">Fill (100% × 420)</option>
</select>
</div>
<div id="grid" style="height: 420px"></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('size').addEventListener('change', (event) => actions.size(api, event.target.value));const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const cities = ['Seoul', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon'];
const products = ['Wireless Earbuds', 'Laptop 14"', 'Smartwatch', 'Tablet 11"', 'Power Bank'];
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{ id: 'city', title: 'City', width: 80 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29 + ((i * 7919) % 40) * 10,
})),
rowKey: 'id',
columnFit: 'fill', // Columns share the leftover width. When the width shrinks, a horizontal scrollbar appears.
};
// The grid has no resize() call. It follows the size of the box (container) that holds it.
// So to change the size, just change the container's width and height, and the grid refits by itself.
const SIZES = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say = () => { };
function container() {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name) {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box)
return;
box.style.maxWidth = '100%'; // On a narrow screen, a fixed width grows only up to the screen width.
box.style.width = size[0];
box.style.height = size[1];
say(`Container resized to ${size[0]} × ${size[1]}.`);
}
export function setup(_api, log) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api, value) => resizeTo(value ?? 'medium'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the grid size</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Grid size" id="size">
<option value="small">Small (320 × 220)</option>
<option value="medium" selected>Medium (520 × 300)</option>
<option value="full">Fill (100% × 420)</option>
</select>
</div>
<div id="grid" style="height: 420px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const cities = ['Seoul', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon'];
const products = ['Wireless Earbuds', 'Laptop 14"', 'Smartwatch', 'Tablet 11"', 'Power Bank'];
const options = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{ id: 'city', title: 'City', width: 80 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29 + ((i * 7919) % 40) * 10,
})),
rowKey: 'id',
columnFit: 'fill', // Columns share the leftover width. When the width shrinks, a horizontal scrollbar appears.
};
// The grid has no resize() call. It follows the size of the box (container) that holds it.
// So to change the size, just change the container's width and height, and the grid refits by itself.
const SIZES = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say = () => { };
function container() {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name) {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box)
return;
box.style.maxWidth = '100%'; // On a narrow screen, a fixed width grows only up to the screen width.
box.style.width = size[0];
box.style.height = size[1];
say(`Container resized to ${size[0]} × ${size[1]}.`);
}
function setup(_api, log) {
say = log;
resizeTo('medium');
}
const actions = {
size: (_api, value) => resizeTo(value ?? 'medium'),
};
options.ariaLabel = "Change the grid size";
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('size').addEventListener('change', (event) => actions.size(api, event.target.value));
</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">
<select
aria-label="Grid size"
disabled={!api}
onChange={(event) => api && actions.size(api, event.target.value)}
>
<option value="small">Small (320 × 220)</option>
<option value="medium">Medium (520 × 300)</option>
<option value="full">Fill (100% × 420)</option>
</select>
</div>
<Grid style={{ height: 420 }} 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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const cities = ['Seoul', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon'];
const products = ['Wireless Earbuds', 'Laptop 14"', 'Smartwatch', 'Tablet 11"', 'Power Bank'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{ id: 'city', title: 'City', width: 80 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29 + ((i * 7919) % 40) * 10,
})),
rowKey: 'id',
columnFit: 'fill', // Columns share the leftover width. When the width shrinks, a horizontal scrollbar appears.
};
// The grid has no resize() call. It follows the size of the box (container) that holds it.
// So to change the size, just change the container's width and height, and the grid refits by itself.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // On a narrow screen, a fixed width grows only up to the screen width.
box.style.width = size[0];
box.style.height = size[1];
say(`Container resized to ${size[0]} × ${size[1]}.`);
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};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">
<select
aria-label="Grid size"
:disabled="!api"
@change="api && actions.size(api, ($event.target as HTMLSelectElement).value)"
>
<option value="small">Small (320 × 220)</option>
<option value="medium" selected>Medium (520 × 300)</option>
<option value="full">Fill (100% × 420)</option>
</select>
</div>
<Grid style="height: 420px" :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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const cities = ['Seoul', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon'];
const products = ['Wireless Earbuds', 'Laptop 14"', 'Smartwatch', 'Tablet 11"', 'Power Bank'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{ id: 'city', title: 'City', width: 80 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29 + ((i * 7919) % 40) * 10,
})),
rowKey: 'id',
columnFit: 'fill', // Columns share the leftover width. When the width shrinks, a horizontal scrollbar appears.
};
// The grid has no resize() call. It follows the size of the box (container) that holds it.
// So to change the size, just change the container's width and height, and the grid refits by itself.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // On a narrow screen, a fixed width grows only up to the screen width.
box.style.width = size[0];
box.style.height = size[1];
say(`Container resized to ${size[0]} × ${size[1]}.`);
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};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">
<select
aria-label="Grid size"
[disabled]="!api"
(change)="api && actions.size(api, $any($event.target).value)"
>
<option value="small">Small (320 × 220)</option>
<option value="medium" selected>Medium (520 × 300)</option>
<option value="full">Fill (100% × 420)</option>
</select>
</div>
<mx-grid style="height: 420px" [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;
city: string;
product: string;
quantity: number;
price: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Brooks',
'Olivia Reed',
'Ethan Hayes',
'Ava Morgan',
'Mason Clark',
'Sophia Bell',
];
const cities = ['Seoul', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon'];
const products = ['Wireless Earbuds', 'Laptop 14"', 'Smartwatch', 'Tablet 11"', 'Power Bank'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 120 },
{ id: 'city', title: 'City', width: 80 },
{ id: 'product', title: 'Product', width: 150 },
{ id: 'quantity', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price',
kind: 'number',
width: 110,
align: 'end',
formatValue: (v) => `$${Number(v).toLocaleString('en-US')}`,
},
],
rows: Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
name: names[(i * 3) % names.length],
city: cities[(i * 5) % cities.length],
product: products[(i * 2 + (i >> 2)) % products.length],
quantity: 1 + ((i * 7) % 9),
price: 29 + ((i * 7919) % 40) * 10,
})),
rowKey: 'id',
columnFit: 'fill', // Columns share the leftover width. When the width shrinks, a horizontal scrollbar appears.
};
// The grid has no resize() call. It follows the size of the box (container) that holds it.
// So to change the size, just change the container's width and height, and the grid refits by itself.
const SIZES: Record<string, [string, string]> = {
small: ['320px', '220px'],
medium: ['520px', '300px'],
full: ['100%', '420px'],
};
let say: (message: LogText) => void = () => {};
function container(): HTMLElement | null {
return document.querySelector('.mxg')?.parentElement ?? null;
}
function resizeTo(name: string): void {
const box = container();
const size = SIZES[name] ?? SIZES.medium;
if (!box) return;
box.style.maxWidth = '100%'; // On a narrow screen, a fixed width grows only up to the screen width.
box.style.width = size[0];
box.style.height = size[1];
say(`Container resized to ${size[0]} × ${size[1]}.`);
}
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
resizeTo('medium');
}
export const actions = {
size: (_api: GridApi<Row>, value?: string) => resizeTo(value ?? 'medium'),
};