슬롯을 직접 정하는 마스크와 applyMaskCustom slots and applyMask
slot으로 슬롯 코드를 더하면 16진수 색 코드 같은 모양도 만들 수 있어요. overwrite는 글자를 끼워 넣지 않고 덮어쓰고, placeholderChar로 빈 칸 글자를 바꿔요. applyMask와 stripMask는 편집기 밖에서도 같은 규칙으로 쓸 수 있어요.A slot code added with slot makes shapes such as a hex color code possible. overwrite replaces characters instead of inserting, and placeholderChar changes the blank mark. applyMask and stripMask apply the same rules outside the editor.
코드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, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: 슬롯 코드를 더해요. 값은 글자 하나에 맞는 정규식 원문이에요(H = 16진수 한 자리).
// overwrite: 글자를 끼워 넣지 않고 캐럿 자리를 바꿔요. placeholderChar: 입력하는 동안 빈 칸을 보여 주는 글자예요.
export const options = {
columns: [
{
id: 'color',
title: '색(16진수)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: '시리얼(덮어쓰기)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: '숫자(저장)', width: 130 },
{
id: 'shown',
title: '표시',
width: 150,
// 저장된 숫자만 applyMask로 전화 모양으로 보여 줘요.
getValue: (row) => row.raw,
formatValue: (value) => MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '"색"과 "시리얼" 칸을 두 번 눌러 보세요. "표시"는 applyMask로 만든 글자예요.',
en: 'Double-click a "색" (color) or "시리얼" (serial) cell. "표시" (shown) is text made by applyMask.',
});
const off = api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
}));
return () => off();
}<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>슬롯을 직접 정하는 마스크와 applyMask</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, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: 슬롯 코드를 더해요. 값은 글자 하나에 맞는 정규식 원문이에요(H = 16진수 한 자리).
// overwrite: 글자를 끼워 넣지 않고 캐럿 자리를 바꿔요. placeholderChar: 입력하는 동안 빈 칸을 보여 주는 글자예요.
const options = {
columns: [
{
id: 'color',
title: '색(16진수)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: '시리얼(덮어쓰기)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: '숫자(저장)', width: 130 },
{
id: 'shown',
title: '표시',
width: 150,
// 저장된 숫자만 applyMask로 전화 모양으로 보여 줘요.
getValue: (row) => row.raw,
formatValue: (value) => MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '"색"과 "시리얼" 칸을 두 번 눌러 보세요. "표시"는 applyMask로 만든 글자예요.',
en: 'Double-click a "색" (color) or "시리얼" (serial) cell. "표시" (shown) is text made by applyMask.',
});
const off = api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
}));
return () => off();
}
options.ariaLabel = "슬롯을 직접 정하는 마스크와 applyMask";
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';
// 예제 틀이 전역 번들 `MaxGrid`를 불러 둬요. applyMask·stripMask는 거기서 꺼내 써요(npm에서는 import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: 슬롯 코드를 더해요. 값은 글자 하나에 맞는 정규식 원문이에요(H = 16진수 한 자리).
// overwrite: 글자를 끼워 넣지 않고 캐럿 자리를 바꿔요. placeholderChar: 입력하는 동안 빈 칸을 보여 주는 글자예요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: '색(16진수)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: '시리얼(덮어쓰기)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: '숫자(저장)', width: 130 },
{
id: 'shown',
title: '표시',
width: 150,
// 저장된 숫자만 applyMask로 전화 모양으로 보여 줘요.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"색"과 "시리얼" 칸을 두 번 눌러 보세요. "표시"는 applyMask로 만든 글자예요.',
en: 'Double-click a "색" (color) or "시리얼" (serial) cell. "표시" (shown) is text made by applyMask.',
});
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
}),
);
return () => 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';
// 예제 틀이 전역 번들 `MaxGrid`를 불러 둬요. applyMask·stripMask는 거기서 꺼내 써요(npm에서는 import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: 슬롯 코드를 더해요. 값은 글자 하나에 맞는 정규식 원문이에요(H = 16진수 한 자리).
// overwrite: 글자를 끼워 넣지 않고 캐럿 자리를 바꿔요. placeholderChar: 입력하는 동안 빈 칸을 보여 주는 글자예요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: '색(16진수)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: '시리얼(덮어쓰기)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: '숫자(저장)', width: 130 },
{
id: 'shown',
title: '표시',
width: 150,
// 저장된 숫자만 applyMask로 전화 모양으로 보여 줘요.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"색"과 "시리얼" 칸을 두 번 눌러 보세요. "표시"는 applyMask로 만든 글자예요.',
en: 'Double-click a "색" (color) or "시리얼" (serial) cell. "표시" (shown) is text made by applyMask.',
});
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
}),
);
return () => 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';
// 예제 틀이 전역 번들 `MaxGrid`를 불러 둬요. applyMask·stripMask는 거기서 꺼내 써요(npm에서는 import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: 슬롯 코드를 더해요. 값은 글자 하나에 맞는 정규식 원문이에요(H = 16진수 한 자리).
// overwrite: 글자를 끼워 넣지 않고 캐럿 자리를 바꿔요. placeholderChar: 입력하는 동안 빈 칸을 보여 주는 글자예요.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: '색(16진수)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: '시리얼(덮어쓰기)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: '숫자(저장)', width: 130 },
{
id: 'shown',
title: '표시',
width: 150,
// 저장된 숫자만 applyMask로 전화 모양으로 보여 줘요.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"색"과 "시리얼" 칸을 두 번 눌러 보세요. "표시"는 applyMask로 만든 글자예요.',
en: 'Double-click a "색" (color) or "시리얼" (serial) cell. "표시" (shown) is text made by applyMask.',
});
const off = api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
en: `Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`,
}),
);
return () => 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, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: adds a slot code. The value is the source of a regular expression that matches one character (H = one hex digit).
// overwrite: replaces the character at the caret instead of inserting. placeholderChar: the character that marks blanks while typing.
export const options = {
columns: [
{
id: 'color',
title: 'Color (hex)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: 'Serial (overwrite)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: 'Digits (stored)', width: 130 },
{
id: 'shown',
title: 'Shown',
width: 150,
// Shows only the stored digits in a phone shape with applyMask.
getValue: (row) => row.raw,
formatValue: (value) => MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Double-click a "Color" or "Serial" cell. "Shown" is text made by applyMask.');
const off = api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`));
return () => off();
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Custom slots and applyMask</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, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: adds a slot code. The value is the source of a regular expression that matches one character (H = one hex digit).
// overwrite: replaces the character at the caret instead of inserting. placeholderChar: the character that marks blanks while typing.
const options = {
columns: [
{
id: 'color',
title: 'Color (hex)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: 'Serial (overwrite)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: 'Digits (stored)', width: 130 },
{
id: 'shown',
title: 'Shown',
width: 150,
// Shows only the stored digits in a phone shape with applyMask.
getValue: (row) => row.raw,
formatValue: (value) => MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Double-click a "Color" or "Serial" cell. "Shown" is text made by applyMask.');
const off = api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`));
return () => off();
}
options.ariaLabel = "Custom slots and applyMask";
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';
// The example frame loads the global bundle `MaxGrid`. applyMask and stripMask are taken from it (with npm: import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: adds a slot code. The value is the source of a regular expression that matches one character (H = one hex digit).
// overwrite: replaces the character at the caret instead of inserting. placeholderChar: the character that marks blanks while typing.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: 'Color (hex)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: 'Serial (overwrite)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: 'Digits (stored)', width: 130 },
{
id: 'shown',
title: 'Shown',
width: 150,
// Shows only the stored digits in a phone shape with applyMask.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a "Color" or "Serial" cell. "Shown" is text made by applyMask.');
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`),
);
return () => 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';
// The example frame loads the global bundle `MaxGrid`. applyMask and stripMask are taken from it (with npm: import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: adds a slot code. The value is the source of a regular expression that matches one character (H = one hex digit).
// overwrite: replaces the character at the caret instead of inserting. placeholderChar: the character that marks blanks while typing.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: 'Color (hex)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: 'Serial (overwrite)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: 'Digits (stored)', width: 130 },
{
id: 'shown',
title: 'Shown',
width: 150,
// Shows only the stored digits in a phone shape with applyMask.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a "Color" or "Serial" cell. "Shown" is text made by applyMask.');
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`),
);
return () => 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';
// The example frame loads the global bundle `MaxGrid`. applyMask and stripMask are taken from it (with npm: import { applyMask } from 'maxgrid').
declare const MaxGrid: {
applyMask(raw: string, pattern: string): string;
stripMask(masked: string, pattern: string): string;
};
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
color: string;
serial: string;
raw: string;
}
const rows: Row[] = [
{ id: 1, color: 'ff-80-00', serial: 'AB12-CD34', raw: '01012345678' },
{ id: 2, color: '', serial: '', raw: '0212345678' },
];
// slot: adds a slot code. The value is the source of a regular expression that matches one character (H = one hex digit).
// overwrite: replaces the character at the caret instead of inserting. placeholderChar: the character that marks blanks while typing.
export const options: GridOptions<Row> = {
columns: [
{
id: 'color',
title: 'Color (hex)',
width: 150,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'HH-HH-HH', slot: { H: '[0-9a-fA-F]' } },
},
{
id: 'serial',
title: 'Serial (overwrite)',
width: 170,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: '**\\*-**\\*', overwrite: true, placeholderChar: '·' },
},
{ id: 'raw', title: 'Digits (stored)', width: 130 },
{
id: 'shown',
title: 'Shown',
width: 150,
// Shows only the stored digits in a phone shape with applyMask.
getValue: (row: Row) => row.raw,
formatValue: (value: unknown) =>
MaxGrid.applyMask(MaxGrid.stripMask(String(value ?? ''), '###########'), '###-####-####'),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click a "Color" or "Serial" cell. "Shown" is text made by applyMask.');
const off = api.on('editCommitted', (e) =>
log(`Row ${e.rowKey}: ${e.columnId} = "${String(e.newValue)}"`),
);
return () => off();
}