입력할 때마다 오는 editInput 이벤트The editInput event on every keystroke
editInput은 편집기의 입력칸 글자가 바뀔 때마다 rowKey·columnId·value와 함께 와요. value는 해석·검증 전 글자라서 글자 수 표시나 실시간 검색에 알맞아요.editInput arrives whenever the editor's text changes, with rowKey, columnId and value. The value is the text before parsing and validation, which suits a character counter or live search.
코드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="editTitle">제목 편집</button>
</div>
<div id="grid" style="height: 300px"></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('editTitle').addEventListener('click', () => actions.editTitle(api));const en = document.documentElement.dataset.lang === 'en';
export const options = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
{
id: 'memo',
title: en ? 'Memo' : '메모',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: en ? 'Code' : '코드',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
{
id: 2,
title: en ? 'Second' : '두 번째',
memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
code: '',
},
],
rowKey: 'id',
ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
export function setup(api, log) {
count = 0;
log({
ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
});
const offs = [
api.on('editInput', (e) => {
count += 1;
log({
ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
});
}),
api.on('editCommitted', (e) => log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api) => api.startEdit(1, 'title'),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>입력할 때마다 오는 editInput 이벤트</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editTitle">제목 편집</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const en = document.documentElement.dataset.lang === 'en';
const options = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
{
id: 'memo',
title: en ? 'Memo' : '메모',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: en ? 'Code' : '코드',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
{
id: 2,
title: en ? 'Second' : '두 번째',
memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
code: '',
},
],
rowKey: 'id',
ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
function setup(api, log) {
count = 0;
log({
ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
});
const offs = [
api.on('editInput', (e) => {
count += 1;
log({
ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
});
}),
api.on('editCommitted', (e) => log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
editTitle: (api) => api.startEdit(1, 'title'),
};
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('editTitle').addEventListener('click', () => actions.editTitle(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.editTitle(api)}
>제목 편집</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
{
id: 'memo',
title: en ? 'Memo' : '메모',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: en ? 'Code' : '코드',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
{
id: 2,
title: en ? 'Second' : '두 번째',
memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
code: '',
},
],
rowKey: 'id',
ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
count = 0;
log({
ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
});
const offs = [
api.on('editInput', (e) => {
count += 1;
log({
ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
});
}),
api.on('editCommitted', (e) =>
log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};버튼을 누르면 이 예제의 코드가 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.editTitle(api)"
>제목 편집</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
{
id: 'memo',
title: en ? 'Memo' : '메모',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: en ? 'Code' : '코드',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
{
id: 2,
title: en ? 'Second' : '두 번째',
memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
code: '',
},
],
rowKey: 'id',
ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
count = 0;
log({
ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
});
const offs = [
api.on('editInput', (e) => {
count += 1;
log({
ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
});
}),
api.on('editCommitted', (e) =>
log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};버튼을 누르면 이 예제의 코드가 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.editTitle(api)"
>제목 편집</button>
</div>
<mx-grid style="height: 300px" [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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
{
id: 'memo',
title: en ? 'Memo' : '메모',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: en ? 'Code' : '코드',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
{
id: 2,
title: en ? 'Second' : '두 번째',
memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
code: '',
},
],
rowKey: 'id',
ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
count = 0;
log({
ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
});
const offs = [
api.on('editInput', (e) => {
count += 1;
log({
ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
});
}),
api.on('editCommitted', (e) =>
log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};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="editTitle">Edit title</button>
</div>
<div id="grid" style="height: 300px"></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('editTitle').addEventListener('click', () => actions.editTitle(api));export const options = {
columns: [
{ id: 'title', title: 'Title', width: 150, editable: true },
{
id: 'memo',
title: 'Memo',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: 'Code',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: 'First', memo: '', code: 'AB-1234' },
{ id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
],
rowKey: 'id',
ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
export function setup(api, log) {
count = 0;
log('Double-click a title cell and type. editInput arrives on every keystroke.');
const offs = [
api.on('editInput', (e) => {
count += 1;
log(`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`);
}),
api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api) => api.startEdit(1, 'title'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The editInput event on every keystroke</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editTitle">Edit title</button>
</div>
<div id="grid" style="height: 300px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const options = {
columns: [
{ id: 'title', title: 'Title', width: 150, editable: true },
{
id: 'memo',
title: 'Memo',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: 'Code',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: 'First', memo: '', code: 'AB-1234' },
{ id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
],
rowKey: 'id',
ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
function setup(api, log) {
count = 0;
log('Double-click a title cell and type. editInput arrives on every keystroke.');
const offs = [
api.on('editInput', (e) => {
count += 1;
log(`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`);
}),
api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
editTitle: (api) => api.startEdit(1, 'title'),
};
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('editTitle').addEventListener('click', () => actions.editTitle(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.editTitle(api)}
>Edit title</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 150, editable: true },
{
id: 'memo',
title: 'Memo',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: 'Code',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: 'First', memo: '', code: 'AB-1234' },
{ id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
],
rowKey: 'id',
ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
export function setup(api: GridApi<Row>, log: (message: string) => void) {
count = 0;
log('Double-click a title cell and type. editInput arrives on every keystroke.');
const offs = [
api.on('editInput', (e) => {
count += 1;
log(
`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
);
}),
api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};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.editTitle(api)"
>Edit title</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 150, editable: true },
{
id: 'memo',
title: 'Memo',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: 'Code',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: 'First', memo: '', code: 'AB-1234' },
{ id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
],
rowKey: 'id',
ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
export function setup(api: GridApi<Row>, log: (message: string) => void) {
count = 0;
log('Double-click a title cell and type. editInput arrives on every keystroke.');
const offs = [
api.on('editInput', (e) => {
count += 1;
log(
`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
);
}),
api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};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.editTitle(api)"
>Edit title</button>
</div>
<mx-grid style="height: 300px" [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;
export interface Row {
id: number;
title: string;
memo: string;
code: string;
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 150, editable: true },
{
id: 'memo',
title: 'Memo',
width: 220,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
{
id: 'code',
title: 'Code',
width: 130,
editable: true,
cellEditor: 'mask',
editorParams: { pattern: 'AA-####' },
},
],
rows: [
{ id: 1, title: 'First', memo: '', code: 'AB-1234' },
{ id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
],
rowKey: 'id',
ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
export function setup(api: GridApi<Row>, log: (message: string) => void) {
count = 0;
log('Double-click a title cell and type. editInput arrives on every keystroke.');
const offs = [
api.on('editInput', (e) => {
count += 1;
log(
`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
);
}),
api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editTitle: (api: GridApi<Row>) => api.startEdit(1, 'title'),
};