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

입력칸 속성과 붙여넣기 검사 정하기Set input attributes and paste checks

컬럼의 editorParams로 편집 입력칸의 모바일 키보드, 글자 수 제한, 정렬, 안내 문구, 자동 완성을 정해요. pasteCheck를 'type-only'로 두면 붙여넣기에서는 값의 형식만 검사해요.editorParams sets the mobile keyboard, character limit, alignment, placeholder and autocomplete of the edit input. With pasteCheck 'type-only' a paste checks only the value type.

활용Intermediate
직접 써 보기Live preview입력칸 속성과 붙여넣기 검사 정하기Set input attributes and paste checks

코드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 class="toolbar">
    <button type="button" id="editPhone">전화 편집</button>
    <button type="button" id="editQty">수량 편집</button>
    <button type="button" id="pasteBig">수량에 100 붙여넣기</button>
  </div>
  <div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('editPhone').addEventListener('click', () => actions.editPhone(api));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('pasteBig').addEventListener('click', () => actions.pasteBig(api));
example.js
const rows = [
  { id: 1, name: '김서연', phone: '010-1234-5678', qty: 12, memo: '' },
  { id: 2, name: '이준호', phone: '010-9876-5432', qty: 3, memo: '문 앞에 두세요' },
  { id: 3, name: '박민지', phone: '02-555-0101', qty: 40, memo: '' },
];
// editorParams는 편집 입력칸에 붙는 속성이에요. 글자 칸은 숫자 키패드(tel)와 글자 수 제한(maxLength),
// 수량 칸은 오른쪽 정렬, 메모 칸은 안내 문구(placeholder)와 자동 완성 끄기를 써요. 주지 않은 항목은 기본 그대로예요.
// 붙여넣기는 pasteCheck 'type-only'로 길이·범위 규칙을 건너뛰고 형식(숫자인지)만 검사해요. 직접 입력은 규칙을 그대로 지켜요.
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 100, editable: true, editorParams: { maxLength: 6 } },
    {
      id: 'phone',
      title: '전화',
      width: 150,
      editable: true,
      editorParams: {
        inputMode: 'tel',
        maxLength: 13,
        placeholder: '010-0000-0000',
        autoComplete: false,
      },
    },
    {
      id: 'qty',
      title: '수량 (1~20)',
      kind: 'number',
      width: 110,
      align: 'end',
      editable: true,
      validation: { min: 1, max: 20 },
      editorParams: { align: 'end', inputMode: 'numeric', maxLength: 3 },
      pasteCheck: 'type-only',
    },
    {
      id: 'memo',
      title: '메모',
      width: 190,
      editable: true,
      editorParams: { placeholder: '요청 사항', autoComplete: 'off' },
    },
  ],
  rows,
  rowKey: 'id',
  cellSelection: 'multiple',
};
export function setup(api, log) {
  log({
    ko: '"전화" 칸을 더블클릭하면 입력칸이 열려요. 14글자째부터는 입력되지 않아요.',
    en: 'Double-click a "전화" (phone) cell. The input stops accepting characters after 13.',
  });
  const offs = [
    api.on('cellsPasted', (e) => log({
      ko: `붙여넣기: ${e.pasted}칸 반영, ${e.skipped}칸 건너뜀`,
      en: `Paste: ${e.pasted} cells written, ${e.skipped} skipped`,
    })),
    api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editPhone: (api) => api.startEdit(1, 'phone'),
  editQty: (api) => api.startEdit(1, 'qty'),
  // 수량 칸에 100을 붙여넣어요. 직접 입력이라면 1~20 규칙에 막히지만 붙여넣기는 형식만 보므로 들어가요.
  pasteBig: (api) => {
    api.selectCells({ rowKey: 2, columnId: 'qty' });
    api.pasteCells('100');
  },
};

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 class="toolbar">
    <button type="button" id="editPhone">Edit phone</button>
    <button type="button" id="editQty">Edit quantity</button>
    <button type="button" id="pasteBig">Paste 100 into quantity</button>
  </div>
  <div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('editPhone').addEventListener('click', () => actions.editPhone(api));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('pasteBig').addEventListener('click', () => actions.pasteBig(api));
example.js
const rows = [
  { id: 1, name: 'Liam Carter', phone: '555-123-4567', qty: 12, memo: '' },
  { id: 2, name: 'Emma Stone', phone: '555-987-6543', qty: 3, memo: 'Leave at the door' },
  { id: 3, name: 'Noah Kim', phone: '212-555-0101', qty: 40, memo: '' },
];
// editorParams are attributes put on the edit input. The text column uses a numeric keypad (tel) and a length limit (maxLength),
// the quantity column is right-aligned, and the memo column uses a placeholder and turns autocomplete off. Anything not given keeps its default.
// Paste uses pasteCheck 'type-only', which skips the length and range rules and only checks the format (is it a number). Typed input still follows the rules.
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 130, editable: true, editorParams: { maxLength: 14 } },
    {
      id: 'phone',
      title: 'Phone',
      width: 150,
      editable: true,
      editorParams: {
        inputMode: 'tel',
        maxLength: 12,
        placeholder: '000-000-0000',
        autoComplete: false,
      },
    },
    {
      id: 'qty',
      title: 'Qty (1-20)',
      kind: 'number',
      width: 110,
      align: 'end',
      editable: true,
      validation: { min: 1, max: 20 },
      editorParams: { align: 'end', inputMode: 'numeric', maxLength: 3 },
      pasteCheck: 'type-only',
    },
    {
      id: 'memo',
      title: 'Memo',
      width: 190,
      editable: true,
      editorParams: { placeholder: 'Requests', autoComplete: 'off' },
    },
  ],
  rows,
  rowKey: 'id',
  cellSelection: 'multiple',
};
export function setup(api, log) {
  log('Double-click a "Phone" cell. The input stops accepting characters after 12.');
  const offs = [
    api.on('cellsPasted', (e) => log(`Paste: ${e.pasted} cells written, ${e.skipped} skipped`)),
    api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editPhone: (api) => api.startEdit(1, 'phone'),
  editQty: (api) => api.startEdit(1, 'qty'),
  // Paste 100 into the quantity cell. Typed input would be blocked by the 1-20 rule, but paste only checks the format, so it goes in.
  pasteBig: (api) => {
    api.selectCells({ rowKey: 2, columnId: 'qty' });
    api.pasteCells('100');
  },
};