이름 붙인 컬럼 종류로 묶어 쓰기Reuse column types by name
columnTypes에 정의 묶음에 이름을 붙이고 컬럼의 type에 적어서 여러 컬럼에 같은 모양을 줘요. 이름 목록은 왼쪽부터 덮고, 컬럼이 직접 적은 값이 마지막에 이겨요.Name a bundle of column settings in columnTypes and reference it from a column type. A list applies left to right and the column own values win last.
코드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 id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);const names = ['연필', '공책', '지우개', '자', '가위', '풀'];
// columnTypes는 이름 붙인 정의 묶음이에요. 컬럼의 type에 이름(또는 이름 목록)을 적으면 그 묶음이 적용돼요.
// 같은 속성은 columnDefaults < 묶음(목록은 왼쪽부터) < 컬럼 자신의 정의 순으로 덮어요.
// emptyAs: 'null'이면 메모를 지웠을 때 빈 글자 대신 null이 저장돼요.
export const options = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `${v.toLocaleString()}원` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: '품목', width: 120 },
{ id: 'price', title: '단가', type: ['money', 'editableNumber'] },
{ id: 'stock', title: '재고', type: 'editableNumber', kind: 'number', align: 'end', width: 90 },
{ id: 'note', title: '메모', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 500 + i * 250,
stock: 20 + i * 7,
note: i % 2 === 0 ? '입고 예정' : null,
})),
rowKey: 'id',
};<!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 id="grid" style="height: 260px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['연필', '공책', '지우개', '자', '가위', '풀'];
// columnTypes는 이름 붙인 정의 묶음이에요. 컬럼의 type에 이름(또는 이름 목록)을 적으면 그 묶음이 적용돼요.
// 같은 속성은 columnDefaults < 묶음(목록은 왼쪽부터) < 컬럼 자신의 정의 순으로 덮어요.
// emptyAs: 'null'이면 메모를 지웠을 때 빈 글자 대신 null이 저장돼요.
const options = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `${v.toLocaleString()}원` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: '품목', width: 120 },
{ id: 'price', title: '단가', type: ['money', 'editableNumber'] },
{ id: 'stock', title: '재고', type: 'editableNumber', kind: 'number', align: 'end', width: 90 },
{ id: 'note', title: '메모', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 500 + i * 250,
stock: 20 + i * 7,
note: i % 2 === 0 ? '입고 예정' : null,
})),
rowKey: 'id',
};
options.ariaLabel = "이름 붙인 컬럼 종류로 묶어 쓰기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid } from '@maxgrid/react';
import { options, type Row } from './example';
export function ExampleGrid() {
return (
<>
<Grid style={{ height: 260 }} options={options} />
</>
);
}import type { GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['연필', '공책', '지우개', '자', '가위', '풀'];
// columnTypes는 이름 붙인 정의 묶음이에요. 컬럼의 type에 이름(또는 이름 목록)을 적으면 그 묶음이 적용돼요.
// 같은 속성은 columnDefaults < 묶음(목록은 왼쪽부터) < 컬럼 자신의 정의 순으로 덮어요.
// emptyAs: 'null'이면 메모를 지웠을 때 빈 글자 대신 null이 저장돼요.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `${v.toLocaleString()}원` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: '품목', width: 120 },
{ id: 'price', title: '단가', type: ['money', 'editableNumber'] },
{ id: 'stock', title: '재고', type: 'editableNumber', kind: 'number', align: 'end', width: 90 },
{ id: 'note', title: '메모', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 500 + i * 250,
stock: 20 + i * 7,
note: i % 2 === 0 ? '입고 예정' : null,
})),
rowKey: 'id',
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { Grid } from '@maxgrid/vue';
import { options, type Row } from './example';
</script>
<template>
<Grid style="height: 260px" :options="options" />
</template>import type { GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['연필', '공책', '지우개', '자', '가위', '풀'];
// columnTypes는 이름 붙인 정의 묶음이에요. 컬럼의 type에 이름(또는 이름 목록)을 적으면 그 묶음이 적용돼요.
// 같은 속성은 columnDefaults < 묶음(목록은 왼쪽부터) < 컬럼 자신의 정의 순으로 덮어요.
// emptyAs: 'null'이면 메모를 지웠을 때 빈 글자 대신 null이 저장돼요.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `${v.toLocaleString()}원` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: '품목', width: 120 },
{ id: 'price', title: '단가', type: ['money', 'editableNumber'] },
{ id: 'stock', title: '재고', type: 'editableNumber', kind: 'number', align: 'end', width: 90 },
{ id: 'note', title: '메모', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 500 + i * 250,
stock: 20 + i * 7,
note: i % 2 === 0 ? '입고 예정' : null,
})),
rowKey: 'id',
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent } from '@maxgrid/angular';
import { options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" />
`,
})
export class ExampleGridComponent {
readonly options = options;
}import type { GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['연필', '공책', '지우개', '자', '가위', '풀'];
// columnTypes는 이름 붙인 정의 묶음이에요. 컬럼의 type에 이름(또는 이름 목록)을 적으면 그 묶음이 적용돼요.
// 같은 속성은 columnDefaults < 묶음(목록은 왼쪽부터) < 컬럼 자신의 정의 순으로 덮어요.
// emptyAs: 'null'이면 메모를 지웠을 때 빈 글자 대신 null이 저장돼요.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `${v.toLocaleString()}원` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: '품목', width: 120 },
{ id: 'price', title: '단가', type: ['money', 'editableNumber'] },
{ id: 'stock', title: '재고', type: 'editableNumber', kind: 'number', align: 'end', width: 90 },
{ id: 'note', title: '메모', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 500 + i * 250,
stock: 20 + i * 7,
note: i % 2 === 0 ? '입고 예정' : null,
})),
rowKey: 'id',
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);const names = ['Pencil', 'Notebook', 'Eraser', 'Ruler', 'Scissors', 'Glue'];
// columnTypes are named bundles of definitions. Put a name (or a list of names) in a column's type to apply the bundle.
// For the same property, later wins: columnDefaults < bundle (lists from the left) < the column's own definition.
// With emptyAs: 'null', clearing a note stores null instead of an empty string.
export const options = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `$${v.toLocaleString('en-US')}` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: 'Item', width: 120 },
{ id: 'price', title: 'Unit price', type: ['money', 'editableNumber'] },
{
id: 'stock',
title: 'Stock',
type: 'editableNumber',
kind: 'number',
align: 'end',
width: 90,
},
{ id: 'note', title: 'Note', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 5 + i * 3,
stock: 20 + i * 7,
note: i % 2 === 0 ? 'Restock due' : null,
})),
rowKey: 'id',
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Reuse column types by name</title>
</head>
<body>
<div id="grid" style="height: 260px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['Pencil', 'Notebook', 'Eraser', 'Ruler', 'Scissors', 'Glue'];
// columnTypes are named bundles of definitions. Put a name (or a list of names) in a column's type to apply the bundle.
// For the same property, later wins: columnDefaults < bundle (lists from the left) < the column's own definition.
// With emptyAs: 'null', clearing a note stores null instead of an empty string.
const options = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `$${v.toLocaleString('en-US')}` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: 'Item', width: 120 },
{ id: 'price', title: 'Unit price', type: ['money', 'editableNumber'] },
{
id: 'stock',
title: 'Stock',
type: 'editableNumber',
kind: 'number',
align: 'end',
width: 90,
},
{ id: 'note', title: 'Note', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 5 + i * 3,
stock: 20 + i * 7,
note: i % 2 === 0 ? 'Restock due' : null,
})),
rowKey: 'id',
};
options.ariaLabel = "Reuse column types by name";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid } from '@maxgrid/react';
import { options, type Row } from './example';
export function ExampleGrid() {
return (
<>
<Grid style={{ height: 260 }} options={options} />
</>
);
}import type { GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['Pencil', 'Notebook', 'Eraser', 'Ruler', 'Scissors', 'Glue'];
// columnTypes are named bundles of definitions. Put a name (or a list of names) in a column's type to apply the bundle.
// For the same property, later wins: columnDefaults < bundle (lists from the left) < the column's own definition.
// With emptyAs: 'null', clearing a note stores null instead of an empty string.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `$${v.toLocaleString('en-US')}` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: 'Item', width: 120 },
{ id: 'price', title: 'Unit price', type: ['money', 'editableNumber'] },
{
id: 'stock',
title: 'Stock',
type: 'editableNumber',
kind: 'number',
align: 'end',
width: 90,
},
{ id: 'note', title: 'Note', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 5 + i * 3,
stock: 20 + i * 7,
note: i % 2 === 0 ? 'Restock due' : null,
})),
rowKey: 'id',
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { Grid } from '@maxgrid/vue';
import { options, type Row } from './example';
</script>
<template>
<Grid style="height: 260px" :options="options" />
</template>import type { GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['Pencil', 'Notebook', 'Eraser', 'Ruler', 'Scissors', 'Glue'];
// columnTypes are named bundles of definitions. Put a name (or a list of names) in a column's type to apply the bundle.
// For the same property, later wins: columnDefaults < bundle (lists from the left) < the column's own definition.
// With emptyAs: 'null', clearing a note stores null instead of an empty string.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `$${v.toLocaleString('en-US')}` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: 'Item', width: 120 },
{ id: 'price', title: 'Unit price', type: ['money', 'editableNumber'] },
{
id: 'stock',
title: 'Stock',
type: 'editableNumber',
kind: 'number',
align: 'end',
width: 90,
},
{ id: 'note', title: 'Note', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 5 + i * 3,
stock: 20 + i * 7,
note: i % 2 === 0 ? 'Restock due' : null,
})),
rowKey: 'id',
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent } from '@maxgrid/angular';
import { options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" />
`,
})
export class ExampleGridComponent {
readonly options = options;
}import type { GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
name: string;
price: number;
stock: number;
note: string | null;
}
const names = ['Pencil', 'Notebook', 'Eraser', 'Ruler', 'Scissors', 'Glue'];
// columnTypes are named bundles of definitions. Put a name (or a list of names) in a column's type to apply the bundle.
// For the same property, later wins: columnDefaults < bundle (lists from the left) < the column's own definition.
// With emptyAs: 'null', clearing a note stores null instead of an empty string.
export const options: GridOptions<Row> = {
columnTypes: {
money: {
kind: 'number',
align: 'end',
width: 110,
formatValue: (v) => (typeof v === 'number' ? `$${v.toLocaleString('en-US')}` : ''),
},
editableNumber: { editable: true, validation: { min: 0 } },
},
columns: [
{ id: 'name', title: 'Item', width: 120 },
{ id: 'price', title: 'Unit price', type: ['money', 'editableNumber'] },
{
id: 'stock',
title: 'Stock',
type: 'editableNumber',
kind: 'number',
align: 'end',
width: 90,
},
{ id: 'note', title: 'Note', editable: true, emptyAs: 'null', width: 200 },
],
rows: names.map((name, i) => ({
id: i + 1,
name,
price: 5 + i * 3,
stock: 20 + i * 7,
note: i % 2 === 0 ? 'Restock due' : null,
})),
rowKey: 'id',
};