글자 입력 규칙: 대소문자, 가리기, 형식 검사Text input rules: case, secret and pattern
editorParams의 case·secret·pattern·patternMessage로 글자 입력을 정해요. 상품 코드는 대문자로 바뀌고 형식(영문 2자와 숫자 3자)을 입력하는 동안 안내하며, 비밀번호 칸은 가려져요.editorParams case, secret, pattern and patternMessage shape text input. A product code turns upper-case and is checked against a format (2 letters and 3 digits) while typing, and a password cell is hidden.
코드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 class="toolbar">
<button type="button" id="editCode">코드 편집</button>
<button type="button" id="editPassword">비밀번호 편집</button>
</div>
<div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('editCode').addEventListener('click', () => actions.editCode(api));
document.getElementById('editPassword').addEventListener('click', () => actions.editPassword(api));const rows = [
{ id: 1, name: '무선 마우스', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: '기계식 키보드', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: '웹캠', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// 글자 입력 규칙은 editorParams에 써요. 규칙을 주지 않은 칸은 지금까지와 똑같아요.
// 코드: 대문자로 바꾸고 형식(영문 2자 + 숫자 3자)을 입력하는 동안에도 안내해요(patternMessage가 있을 때).
// 사용자: 소문자로 바꿔요. 비밀번호: 입력을 가려요(복사를 막지는 않아요).
export const options = {
columns: [
{ id: 'name', title: '상품', width: 150 },
{
id: 'code',
title: '코드',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '영문 2자와 숫자 3자(예: AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: '사용자',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: '비밀번호',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '"코드"를 더블클릭하고 ab12를 써 보세요. 대문자로 바뀌고 형식 안내가 떠요.',
en: 'Double-click "Code" and type ab12. It turns upper-case and the format hint appears.',
});
const offs = [
api.on('editCommitted', (e) => log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`)),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api) => api.startEdit(1, 'code'),
editPassword: (api) => api.startEdit(1, 'password'),
};<!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 class="toolbar">
<button type="button" id="editCode">코드 편집</button>
<button type="button" id="editPassword">비밀번호 편집</button>
</div>
<div id="grid" style="height: 250px"></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: '무선 마우스', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: '기계식 키보드', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: '웹캠', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// 글자 입력 규칙은 editorParams에 써요. 규칙을 주지 않은 칸은 지금까지와 똑같아요.
// 코드: 대문자로 바꾸고 형식(영문 2자 + 숫자 3자)을 입력하는 동안에도 안내해요(patternMessage가 있을 때).
// 사용자: 소문자로 바꿔요. 비밀번호: 입력을 가려요(복사를 막지는 않아요).
const options = {
columns: [
{ id: 'name', title: '상품', width: 150 },
{
id: 'code',
title: '코드',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '영문 2자와 숫자 3자(예: AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: '사용자',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: '비밀번호',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '"코드"를 더블클릭하고 ab12를 써 보세요. 대문자로 바뀌고 형식 안내가 떠요.',
en: 'Double-click "Code" and type ab12. It turns upper-case and the format hint appears.',
});
const offs = [
api.on('editCommitted', (e) => log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`)),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
editCode: (api) => api.startEdit(1, 'code'),
editPassword: (api) => api.startEdit(1, 'password'),
};
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);
});
document.getElementById('editCode').addEventListener('click', () => actions.editCode(api));
document.getElementById('editPassword').addEventListener('click', () => actions.editPassword(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.editCode(api)}
>코드 편집</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editPassword(api)}
>비밀번호 편집</button>
</div>
<Grid style={{ height: 250 }} 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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: '무선 마우스', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: '기계식 키보드', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: '웹캠', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// 글자 입력 규칙은 editorParams에 써요. 규칙을 주지 않은 칸은 지금까지와 똑같아요.
// 코드: 대문자로 바꾸고 형식(영문 2자 + 숫자 3자)을 입력하는 동안에도 안내해요(patternMessage가 있을 때).
// 사용자: 소문자로 바꿔요. 비밀번호: 입력을 가려요(복사를 막지는 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '상품', width: 150 },
{
id: 'code',
title: '코드',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '영문 2자와 숫자 3자(예: AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: '사용자',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: '비밀번호',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"코드"를 더블클릭하고 ab12를 써 보세요. 대문자로 바뀌고 형식 안내가 떠요.',
en: 'Double-click "Code" and type ab12. It turns upper-case and the format hint appears.',
});
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, 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>
<div class="toolbar">
<button
type="button"
:disabled="!api"
@click="api && actions.editCode(api)"
>코드 편집</button>
<button
type="button"
:disabled="!api"
@click="api && actions.editPassword(api)"
>비밀번호 편집</button>
</div>
<Grid style="height: 250px" :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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: '무선 마우스', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: '기계식 키보드', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: '웹캠', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// 글자 입력 규칙은 editorParams에 써요. 규칙을 주지 않은 칸은 지금까지와 똑같아요.
// 코드: 대문자로 바꾸고 형식(영문 2자 + 숫자 3자)을 입력하는 동안에도 안내해요(patternMessage가 있을 때).
// 사용자: 소문자로 바꿔요. 비밀번호: 입력을 가려요(복사를 막지는 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '상품', width: 150 },
{
id: 'code',
title: '코드',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '영문 2자와 숫자 3자(예: AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: '사용자',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: '비밀번호',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"코드"를 더블클릭하고 ab12를 써 보세요. 대문자로 바뀌고 형식 안내가 떠요.',
en: 'Double-click "Code" and type ab12. It turns upper-case and the format hint appears.',
});
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.editCode(api)"
>코드 편집</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editPassword(api)"
>비밀번호 편집</button>
</div>
<mx-grid style="height: 250px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: '무선 마우스', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: '기계식 키보드', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: '웹캠', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// 글자 입력 규칙은 editorParams에 써요. 규칙을 주지 않은 칸은 지금까지와 똑같아요.
// 코드: 대문자로 바꾸고 형식(영문 2자 + 숫자 3자)을 입력하는 동안에도 안내해요(patternMessage가 있을 때).
// 사용자: 소문자로 바꿔요. 비밀번호: 입력을 가려요(복사를 막지는 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '상품', width: 150 },
{
id: 'code',
title: '코드',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '영문 2자와 숫자 3자(예: AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: '사용자',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: '비밀번호',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"코드"를 더블클릭하고 ab12를 써 보세요. 대문자로 바뀌고 형식 안내가 떠요.',
en: 'Double-click "Code" and type ab12. It turns upper-case and the format hint appears.',
});
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="editCode">Edit code</button>
<button type="button" id="editPassword">Edit password</button>
</div>
<div id="grid" style="height: 250px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('editCode').addEventListener('click', () => actions.editCode(api));
document.getElementById('editPassword').addEventListener('click', () => actions.editPassword(api));const rows = [
{ id: 1, name: 'Wireless mouse', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: 'Mechanical keyboard', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: 'Webcam', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// Text input rules go in editorParams. A cell with no rules behaves as before.
// Code: converted to upper case, and the format (2 letters + 3 digits) is shown while typing (when patternMessage is set).
// User: converted to lower case. Password: the input is masked (copying is not blocked).
export const options = {
columns: [
{ id: 'name', title: 'Product', width: 170 },
{
id: 'code',
title: 'Code',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '2 letters and 3 digits (e.g. AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: 'User',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: 'Password',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Double-click "Code" and type ab12. It turns upper-case and the format hint appears.');
const offs = [
api.on('editCommitted', (e) => log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`)),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api) => api.startEdit(1, 'code'),
editPassword: (api) => api.startEdit(1, 'password'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Text input rules: case, secret and pattern</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editCode">Edit code</button>
<button type="button" id="editPassword">Edit password</button>
</div>
<div id="grid" style="height: 250px"></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: 'Wireless mouse', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: 'Mechanical keyboard', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: 'Webcam', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// Text input rules go in editorParams. A cell with no rules behaves as before.
// Code: converted to upper case, and the format (2 letters + 3 digits) is shown while typing (when patternMessage is set).
// User: converted to lower case. Password: the input is masked (copying is not blocked).
const options = {
columns: [
{ id: 'name', title: 'Product', width: 170 },
{
id: 'code',
title: 'Code',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '2 letters and 3 digits (e.g. AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: 'User',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: 'Password',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Double-click "Code" and type ab12. It turns upper-case and the format hint appears.');
const offs = [
api.on('editCommitted', (e) => log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`)),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
editCode: (api) => api.startEdit(1, 'code'),
editPassword: (api) => api.startEdit(1, 'password'),
};
options.ariaLabel = "Text input rules: case, secret and pattern";
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);
});
document.getElementById('editCode').addEventListener('click', () => actions.editCode(api));
document.getElementById('editPassword').addEventListener('click', () => actions.editPassword(api));
</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 { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.editCode(api)}
>Edit code</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editPassword(api)}
>Edit password</button>
</div>
<Grid style={{ height: 250 }} 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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: 'Wireless mouse', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: 'Mechanical keyboard', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: 'Webcam', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// Text input rules go in editorParams. A cell with no rules behaves as before.
// Code: converted to upper case, and the format (2 letters + 3 digits) is shown while typing (when patternMessage is set).
// User: converted to lower case. Password: the input is masked (copying is not blocked).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Product', width: 170 },
{
id: 'code',
title: 'Code',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '2 letters and 3 digits (e.g. AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: 'User',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: 'Password',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click "Code" and type ab12. It turns upper-case and the format hint appears.');
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};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 { actions, 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>
<div class="toolbar">
<button
type="button"
:disabled="!api"
@click="api && actions.editCode(api)"
>Edit code</button>
<button
type="button"
:disabled="!api"
@click="api && actions.editPassword(api)"
>Edit password</button>
</div>
<Grid style="height: 250px" :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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: 'Wireless mouse', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: 'Mechanical keyboard', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: 'Webcam', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// Text input rules go in editorParams. A cell with no rules behaves as before.
// Code: converted to upper case, and the format (2 letters + 3 digits) is shown while typing (when patternMessage is set).
// User: converted to lower case. Password: the input is masked (copying is not blocked).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Product', width: 170 },
{
id: 'code',
title: 'Code',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '2 letters and 3 digits (e.g. AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: 'User',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: 'Password',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click "Code" and type ab12. It turns upper-case and the format hint appears.');
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};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 { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.editCode(api)"
>Edit code</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editPassword(api)"
>Edit password</button>
</div>
<mx-grid style="height: 250px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
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;
code: string;
user: string;
password: string;
}
const rows: Row[] = [
{ id: 1, name: 'Wireless mouse', code: 'AB123', user: 'minji', password: 'hunter2' },
{ id: 2, name: 'Mechanical keyboard', code: 'KB204', user: 'junho', password: 'letmein' },
{ id: 3, name: 'Webcam', code: 'WC001', user: 'seoyeon', password: 'correct-horse' },
];
// Text input rules go in editorParams. A cell with no rules behaves as before.
// Code: converted to upper case, and the format (2 letters + 3 digits) is shown while typing (when patternMessage is set).
// User: converted to lower case. Password: the input is masked (copying is not blocked).
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Product', width: 170 },
{
id: 'code',
title: 'Code',
width: 110,
editable: true,
editorParams: {
case: 'upper',
pattern: '[A-Z]{2}\\d{3}',
patternMessage: '2 letters and 3 digits (e.g. AB123)',
maxLength: 5,
},
},
{
id: 'user',
title: 'User',
width: 110,
editable: true,
editorParams: { case: 'lower' },
},
{
id: 'password',
title: 'Password',
width: 130,
editable: true,
editorParams: { secret: true },
formatValue: (value) => '•'.repeat(String(value ?? '').length),
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log('Double-click "Code" and type ab12. It turns upper-case and the format hint appears.');
const offs = [
api.on('editCommitted', (e) =>
log(e.columnId === 'password' ? `${e.columnId}: ••••` : `${e.columnId}: ${String(e.value)}`),
),
api.on('validationFailed', (e) => log(`${e.columnId}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editCode: (api: GridApi<Row>) => api.startEdit(1, 'code'),
editPassword: (api: GridApi<Row>) => api.startEdit(1, 'password'),
};