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

이름 붙인 컬럼 종류로 묶어 쓰기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.

입문Beginner
직접 써 보기Live preview이름 붙인 컬럼 종류로 묶어 쓰기Reuse column types by name

코드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 id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);
example.js
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',
};

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 id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options } from './example';
const api = createGrid(document.getElementById('grid'), options);
example.js
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',
};