입력칸 속성과 붙여넣기 검사 정하기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.
코드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="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>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));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');
},
};<!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="editPhone">전화 편집</button>
<button type="button" id="editQty">수량 편집</button>
<button type="button" id="pasteBig">수량에 100 붙여넣기</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: '김서연', 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'로 길이·범위 규칙을 건너뛰고 형식(숫자인지)만 검사해요. 직접 입력은 규칙을 그대로 지켜요.
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',
};
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());
}
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');
},
};
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('editPhone').addEventListener('click', () => actions.editPhone(api));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('pasteBig').addEventListener('click', () => actions.pasteBig(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.editPhone(api)}
>전화 편집</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editQty(api)}
>수량 편집</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pasteBig(api)}
>수량에 100 붙여넣기</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
// 수량 칸에 100을 붙여넣어요. 직접 입력이라면 1~20 규칙에 막히지만 붙여넣기는 형식만 보므로 들어가요.
pasteBig: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};버튼을 누르면 이 예제의 코드가 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.editPhone(api)"
>전화 편집</button>
<button type="button" :disabled="!api" @click="api && actions.editQty(api)">수량 편집</button>
<button
type="button"
:disabled="!api"
@click="api && actions.pasteBig(api)"
>수량에 100 붙여넣기</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
// 수량 칸에 100을 붙여넣어요. 직접 입력이라면 1~20 규칙에 막히지만 붙여넣기는 형식만 보므로 들어가요.
pasteBig: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};버튼을 누르면 이 예제의 코드가 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.editPhone(api)"
>전화 편집</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editQty(api)"
>수량 편집</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pasteBig(api)"
>수량에 100 붙여넣기</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => api.startEdit(1, 'qty'),
// 수량 칸에 100을 붙여넣어요. 직접 입력이라면 1~20 규칙에 막히지만 붙여넣기는 형식만 보므로 들어가요.
pasteBig: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};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="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>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));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');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Set input attributes and paste checks</title>
</head>
<body>
<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>
<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: '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.
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',
};
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());
}
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');
},
};
options.ariaLabel = "Set input attributes and paste checks";
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('editPhone').addEventListener('click', () => actions.editPhone(api));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
document.getElementById('pasteBig').addEventListener('click', () => actions.pasteBig(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.editPhone(api)}
>Edit phone</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.editQty(api)}
>Edit quantity</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pasteBig(api)}
>Paste 100 into quantity</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => 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: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};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.editPhone(api)"
>Edit phone</button>
<button type="button" :disabled="!api" @click="api && actions.editQty(api)">Edit quantity</button>
<button
type="button"
:disabled="!api"
@click="api && actions.pasteBig(api)"
>Paste 100 into quantity</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => 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: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};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.editPhone(api)"
>Edit phone</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.editQty(api)"
>Edit quantity</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pasteBig(api)"
>Paste 100 into quantity</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;
phone: string;
qty: number;
memo: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.startEdit(1, 'phone'),
editQty: (api: GridApi<Row>) => 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: GridApi<Row>) => {
api.selectCells({ rowKey: 2, columnId: 'qty' });
api.pasteCells('100');
},
};