행 수에 맞춰 자라는 그리드 높이Grid height that follows the row count
autoGridHeight: { maxRows: 8 }이면 그리드 높이가 머리글 + 줄 수에 맞춰지고, 8줄이 넘으면 그 높이에서 스크롤해요. 컨테이너가 높이를 정하지 않아도 돼요.With autoGridHeight: { maxRows: 8 } the grid is as tall as the header plus its rows, and scrolls past 8 rows. The container does not need a height.
코드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="few">3줄</button>
<button type="button" id="some">6줄</button>
<button type="button" id="many">30줄</button>
</div>
<div id="grid" style="height: 360px"></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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(api));const make = (count) => Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `사원 ${i + 1}`,
team: ['개발', '디자인', '영업'][i % 3],
}));
export const options = {
columns: [
{ id: 'name', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
few: (api) => {
api.setRows(make(3));
say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
},
some: (api) => {
api.setRows(make(6));
say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
},
many: (api) => {
api.setRows(make(30));
say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
},
};<!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="few">3줄</button>
<button type="button" id="some">6줄</button>
<button type="button" id="many">30줄</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const make = (count) => Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `사원 ${i + 1}`,
team: ['개발', '디자인', '영업'][i % 3],
}));
const options = {
columns: [
{ id: 'name', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
few: (api) => {
api.setRows(make(3));
say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
},
some: (api) => {
api.setRows(make(6));
say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
},
many: (api) => {
api.setRows(make(30));
say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
},
};
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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(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.few(api)}
>3줄</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.some(api)}
>6줄</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.many(api)}
>30줄</button>
</div>
<Grid style={{ height: 360 }} 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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `사원 ${i + 1}`,
team: ['개발', '디자인', '영업'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
},
};버튼을 누르면 이 예제의 코드가 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.few(api)">3줄</button>
<button type="button" :disabled="!api" @click="api && actions.some(api)">6줄</button>
<button type="button" :disabled="!api" @click="api && actions.many(api)">30줄</button>
</div>
<Grid style="height: 360px" :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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `사원 ${i + 1}`,
team: ['개발', '디자인', '영업'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
},
};버튼을 누르면 이 예제의 코드가 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.few(api)"
>3줄</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.some(api)"
>6줄</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.many(api)"
>30줄</button>
</div>
<mx-grid style="height: 360px" [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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `사원 ${i + 1}`,
team: ['개발', '디자인', '영업'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 140 },
{ id: 'team', title: '팀', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say({ ko: '3줄: 그리드가 줄어들어요', en: '3 rows: the grid shrinks' });
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say({ ko: '6줄: 줄 수만큼 높아져요', en: '6 rows: as tall as the rows' });
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say({ ko: '30줄: 8줄 높이에서 멈추고 스크롤해요', en: '30 rows: stops at 8 rows and scrolls' });
},
};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="few">3 rows</button>
<button type="button" id="some">6 rows</button>
<button type="button" id="many">30 rows</button>
</div>
<div id="grid" style="height: 360px"></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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(api));const make = (count) => Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Employee ${i + 1}`,
team: ['Dev', 'Design', 'Sales'][i % 3],
}));
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
export const actions = {
few: (api) => {
api.setRows(make(3));
say('3 rows: the grid shrinks');
},
some: (api) => {
api.setRows(make(6));
say('6 rows: as tall as the rows');
},
many: (api) => {
api.setRows(make(30));
say('30 rows: stops at 8 rows and scrolls');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Grid height that follows the row count</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="few">3 rows</button>
<button type="button" id="some">6 rows</button>
<button type="button" id="many">30 rows</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const make = (count) => Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Employee ${i + 1}`,
team: ['Dev', 'Design', 'Sales'][i % 3],
}));
const options = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const actions = {
few: (api) => {
api.setRows(make(3));
say('3 rows: the grid shrinks');
},
some: (api) => {
api.setRows(make(6));
say('6 rows: as tall as the rows');
},
many: (api) => {
api.setRows(make(30));
say('30 rows: stops at 8 rows and scrolls');
},
};
options.ariaLabel = "Grid height that follows the row count";
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('few').addEventListener('click', () => actions.few(api));
document.getElementById('some').addEventListener('click', () => actions.some(api));
document.getElementById('many').addEventListener('click', () => actions.many(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.few(api)}
>3 rows</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.some(api)}
>6 rows</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.many(api)}
>30 rows</button>
</div>
<Grid style={{ height: 360 }} 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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Employee ${i + 1}`,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say('3 rows: the grid shrinks');
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say('6 rows: as tall as the rows');
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say('30 rows: stops at 8 rows and scrolls');
},
};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.few(api)">3 rows</button>
<button type="button" :disabled="!api" @click="api && actions.some(api)">6 rows</button>
<button type="button" :disabled="!api" @click="api && actions.many(api)">30 rows</button>
</div>
<Grid style="height: 360px" :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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Employee ${i + 1}`,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say('3 rows: the grid shrinks');
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say('6 rows: as tall as the rows');
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say('30 rows: stops at 8 rows and scrolls');
},
};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.few(api)"
>3 rows</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.some(api)"
>6 rows</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.many(api)"
>30 rows</button>
</div>
<mx-grid style="height: 360px" [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 make = (count: number): Row[] =>
Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `Employee ${i + 1}`,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
}));
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 140 },
{ id: 'team', title: 'Team', width: 120 },
],
rows: make(4),
rowKey: 'id',
autoGridHeight: { maxRows: 8 },
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const actions = {
few: (api: GridApi<Row>) => {
api.setRows(make(3));
say('3 rows: the grid shrinks');
},
some: (api: GridApi<Row>) => {
api.setRows(make(6));
say('6 rows: as tall as the rows');
},
many: (api: GridApi<Row>) => {
api.setRows(make(30));
say('30 rows: stops at 8 rows and scrolls');
},
};