전화번호·사업자 번호 마스크 입력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.
코드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: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);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());
}<!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: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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).
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',
};
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());
}
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);
});
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 200 }} 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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { 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>
<Grid style="height: 200px" :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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}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: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);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());
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mask input for phone and business numbers</title>
</head>
<body>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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).
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',
};
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());
}
options.ariaLabel = "Mask input for phone and business numbers";
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);
});
</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 { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 200 }} 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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}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 { 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>
<Grid style="height: 200px" :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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}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 { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
phone: string;
biz: string;
plain: string;
code: string;
}
const rows: Row[] = [
{
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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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());
}