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

전화번호·사업자 번호 마스크 입력Mask input for phone and business numbers

cellEditor 'mask'는 정해진 모양(pattern)에 맞춰 입력하게 해요. 숫자만 받고 -는 저절로 들어가요. keepMask로 저장 값을 '010-1234-5678' 또는 '01012345678'로 고르고, 끝까지 채우지 않으면 확정이 막혀요.cellEditor 'mask' fits typing into a fixed pattern. Only digits are accepted and the dashes appear by themselves. keepMask chooses whether the stored value is '010-1234-5678' or '01012345678', and committing before every position is filled is refused.

입문Beginner
직접 써 보기Live preview전화번호·사업자 번호 마스크 입력Mask input for phone and business numbers

코드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: 200px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
const rows = [
  {
    id: 1,
    name: '김서연',
    phone: '010-1234-5678',
    biz: '123-45-67890',
    plain: '01012345678',
    code: '',
  },
  { id: 2, name: '이준호', phone: '', biz: '', plain: '', code: '' },
  {
    id: 3,
    name: '박민지',
    phone: '010-9999-0000',
    biz: '220-81-62517',
    plain: '01099990000',
    code: '',
  },
];
// pattern: '#' 숫자, 'A' 글자, '*' 글자·숫자, '\\'는 다음 글자 그대로, 나머지는 고정 글자예요.
// keepMask(기본 true): 저장 값이 마스크 글자예요. false면 숫자만 저장해요. autoCommit: 마지막 칸을 채우면 바로 확정해요.
// 끝까지 채우지 않고 확정하면 코어 검증이 막아요(maskIncomplete).
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 100 },
    {
      id: 'phone',
      title: '전화',
      width: 150,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-####-####' },
    },
    {
      id: 'biz',
      title: '사업자 번호',
      width: 140,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-##-#####' },
    },
    {
      id: 'plain',
      title: '번호(숫자만 저장)',
      width: 160,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-####-####', keepMask: false },
    },
    {
      id: 'code',
      title: '코드(자동 확정)',
      width: 140,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: 'AA-####', autoCommit: true, placeholder: 'AB-1234' },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: '"전화"나 "사업자 번호" 칸을 두 번 누르고 숫자를 치세요. 끝까지 채우지 않고 Enter를 누르면 막혀요.',
    en: 'Double-click a "전화" (phone) or "사업자 번호" (business no.) cell and type digits. Enter before every position is filled is refused.',
  });
  const offs = [
    api.on('editCommitted', (e) => log({
      ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
      en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
    })),
    api.on('validationFailed', (e) => log(e.message)),
  ];
  return () => offs.forEach((off) => off());
}

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: 200px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
const rows = [
  {
    id: 1,
    name: 'Liam Carter',
    phone: '010-1234-5678',
    biz: '123-45-67890',
    plain: '01012345678',
    code: '',
  },
  { id: 2, name: 'Emma Stone', phone: '', biz: '', plain: '', code: '' },
  {
    id: 3,
    name: 'Noah Kim',
    phone: '010-9999-0000',
    biz: '220-81-62517',
    plain: '01099990000',
    code: '',
  },
];
// pattern: '#' digit, 'A' letter, '*' letter or digit, '\\' keeps the next character as is, anything else is a fixed character.
// keepMask (default true): the stored value is the masked text. false stores digits only. autoCommit: commits as soon as the last position is filled.
// Committing before every position is filled is blocked by the core validation (maskIncomplete).
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 120 },
    {
      id: 'phone',
      title: 'Phone',
      width: 150,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-####-####' },
    },
    {
      id: 'biz',
      title: 'Business no.',
      width: 140,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-##-#####' },
    },
    {
      id: 'plain',
      title: 'Number (digits only stored)',
      width: 200,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: '###-####-####', keepMask: false },
    },
    {
      id: 'code',
      title: 'Code (auto commit)',
      width: 160,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: 'AA-####', autoCommit: true, placeholder: 'AB-1234' },
    },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log('Double-click a "Phone" or "Business no." cell and type digits. Enter before every position is filled is refused.');
  const offs = [
    api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`)),
    api.on('validationFailed', (e) => log(e.message)),
  ];
  return () => offs.forEach((off) => off());
}