여러 줄 칸 편집: textarea 편집기Edit several lines: the textarea editor
cellEditor: 'textarea'로 긴 글을 여러 줄 입력해요. Enter는 줄바꿈, Ctrl+Enter가 확정이고, 칸에는 첫 줄만 보이거나(wrap이면 전체) 보여요.cellEditor: 'textarea' edits long text over several lines. Enter adds a line, Ctrl+Enter confirms, and the cell shows the first line only (or all lines with wrap).
코드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="editMemo">메모 편집</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('editMemo').addEventListener('click', () => actions.editMemo(api));const en = document.documentElement.dataset.lang === 'en';
const rows = [
{
id: 1,
title: en ? 'Login is slow' : '로그인이 느려요',
memo: en
? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
: '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
},
{
id: 2,
title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
notes: '',
},
{
id: 3,
title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
memo: '',
notes: en ? 'Design review' : '디자인 검토',
},
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
export const options = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 190 },
{
id: 'memo',
title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
width: 200,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
export function setup(api, log) {
log({
ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
});
const offs = [
api.on('editCommitted', (e) => log({
ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
})),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api) => api.startEdit(1, 'memo'),
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>여러 줄 칸 편집: textarea 편집기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editMemo">메모 편집</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 rows = [
{
id: 1,
title: en ? 'Login is slow' : '로그인이 느려요',
memo: en
? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
: '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
},
{
id: 2,
title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
notes: '',
},
{
id: 3,
title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
memo: '',
notes: en ? 'Design review' : '디자인 검토',
},
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
const options = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 190 },
{
id: 'memo',
title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
width: 200,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
function setup(api, log) {
log({
ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
});
const offs = [
api.on('editCommitted', (e) => log({
ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
})),
];
return () => offs.forEach((off) => off());
}
const actions = {
editMemo: (api) => api.startEdit(1, 'memo'),
};
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('editMemo').addEventListener('click', () => actions.editMemo(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.editMemo(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;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: en ? 'Login is slow' : '로그인이 느려요',
memo: en
? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
: '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
},
{
id: 2,
title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
notes: '',
},
{
id: 3,
title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
memo: '',
notes: en ? 'Design review' : '디자인 검토',
},
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 190 },
{
id: 'memo',
title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
width: 200,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};버튼을 누르면 이 예제의 코드가 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.editMemo(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;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: en ? 'Login is slow' : '로그인이 느려요',
memo: en
? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
: '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
},
{
id: 2,
title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
notes: '',
},
{
id: 3,
title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
memo: '',
notes: en ? 'Design review' : '디자인 검토',
},
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 190 },
{
id: 'memo',
title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
width: 200,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};버튼을 누르면 이 예제의 코드가 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.editMemo(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;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: en ? 'Login is slow' : '로그인이 느려요',
memo: en
? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
: '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
},
{
id: 2,
title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
notes: '',
},
{
id: 3,
title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
memo: '',
notes: en ? 'Design review' : '디자인 검토',
},
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: en ? 'Title' : '제목', width: 190 },
{
id: 'memo',
title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
width: 200,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
});
const offs = [
api.on('editCommitted', (e) =>
log({
ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
}),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};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="editMemo">Edit memo</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('editMemo').addEventListener('click', () => actions.editMemo(api));const rows = [
{
id: 1,
title: 'Login is slow',
memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
notes: 'Needs a check\nOwner: Kim',
},
{
id: 2,
title: 'A column is missing in the export',
memo: 'Only happens with a pinned column.',
notes: '',
},
{
id: 3,
title: 'Dark mode text is faint',
memo: '',
notes: 'Design review',
},
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
export const options = {
columns: [
{ id: 'title', title: 'Title', width: 190 },
{
id: 'memo',
title: 'Memo (first line only)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: 'Notes (line breaks kept)',
width: 220,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: 'Multi-line editing',
};
export function setup(api, log) {
log('Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api) => api.startEdit(1, 'memo'),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Edit several lines: the textarea editor</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="editMemo">Edit memo</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 rows = [
{
id: 1,
title: 'Login is slow',
memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
notes: 'Needs a check\nOwner: Kim',
},
{
id: 2,
title: 'A column is missing in the export',
memo: 'Only happens with a pinned column.',
notes: '',
},
{
id: 3,
title: 'Dark mode text is faint',
memo: '',
notes: 'Design review',
},
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
const options = {
columns: [
{ id: 'title', title: 'Title', width: 190 },
{
id: 'memo',
title: 'Memo (first line only)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: 'Notes (line breaks kept)',
width: 220,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: 'Multi-line editing',
};
function setup(api, log) {
log('Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
editMemo: (api) => api.startEdit(1, 'memo'),
};
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('editMemo').addEventListener('click', () => actions.editMemo(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.editMemo(api)}
>Edit memo</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
memo: string;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: 'Login is slow',
memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
notes: 'Needs a check\nOwner: Kim',
},
{
id: 2,
title: 'A column is missing in the export',
memo: 'Only happens with a pinned column.',
notes: '',
},
{
id: 3,
title: 'Dark mode text is faint',
memo: '',
notes: 'Design review',
},
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 190 },
{
id: 'memo',
title: 'Memo (first line only)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: 'Notes (line breaks kept)',
width: 220,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: 'Multi-line editing',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
);
const offs = [
api.on('editCommitted', (e) =>
log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};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.editMemo(api)"
>Edit memo</button>
</div>
<Grid style="height: 300px" :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;
title: string;
memo: string;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: 'Login is slow',
memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
notes: 'Needs a check\nOwner: Kim',
},
{
id: 2,
title: 'A column is missing in the export',
memo: 'Only happens with a pinned column.',
notes: '',
},
{
id: 3,
title: 'Dark mode text is faint',
memo: '',
notes: 'Design review',
},
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 190 },
{
id: 'memo',
title: 'Memo (first line only)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: 'Notes (line breaks kept)',
width: 220,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: 'Multi-line editing',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
);
const offs = [
api.on('editCommitted', (e) =>
log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};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.editMemo(api)"
>Edit memo</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 | { ko: string; en: string };
export interface Row {
id: number;
title: string;
memo: string;
notes: string;
}
const rows: Row[] = [
{
id: 1,
title: 'Login is slow',
memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
notes: 'Needs a check\nOwner: Kim',
},
{
id: 2,
title: 'A column is missing in the export',
memo: 'Only happens with a pinned column.',
notes: '',
},
{
id: 3,
title: 'Dark mode text is faint',
memo: '',
notes: 'Design review',
},
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
export const options: GridOptions<Row> = {
columns: [
{ id: 'title', title: 'Title', width: 190 },
{
id: 'memo',
title: 'Memo (first line only)',
width: 260,
editable: true,
cellEditor: 'textarea',
editorParams: { rows: 5, maxLength: 200, resize: true },
},
{
id: 'notes',
title: 'Notes (line breaks kept)',
width: 220,
editable: true,
wrap: true,
cellEditor: 'textarea',
editorParams: { rows: 3 },
},
],
rows,
rowKey: 'id',
rowHeight: 'auto',
ariaLabel: 'Multi-line editing',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
);
const offs = [
api.on('editCommitted', (e) =>
log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
editMemo: (api: GridApi<Row>) => api.startEdit(1, 'memo'),
};