셀을 고칠 때 내가 만든 컴포넌트 쓰기Use your own component as the cell editor
셀을 두 번 누르면 뜨는 입력창을 프레임워크의 컴포넌트로 바꿀 수 있어요. 여기서는 상태 칸에 선택 목록 컴포넌트를 붙이고, 고르는 즉시 편집을 끝내요. Enter·Esc·Tab은 표가 처리해서 컴포넌트는 값만 알려 주면 돼요. 위 화면은 같은 모양을 내장 선택 목록으로 보여 줘요.The input that opens on double-click can be replaced by a framework component. Here the status column gets a select component that ends the edit as soon as you pick. The grid handles Enter, Esc and Tab, so the component only reports the value. The preview shows the same look with the built-in select.
실행 화면은 JavaScript 버전이에요. 아래 탭의 React·Vue·Angular 코드는 같은 예제를 각 프레임워크로 직접 쓴 코드예요.The preview runs the JavaScript version. The React, Vue, Angular tabs below hold the same example written for each framework.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);export const STATUSES = ['대기', '진행', '완료'];
export const rows = [
{ id: 1, title: '견적서 보내기', status: '진행' },
{ id: 2, title: '계약서 검토', status: '대기' },
{ id: 3, title: '샘플 발송', status: '완료' },
{ id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
export const baseColumns = [
{ id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
export const options = {
columns: baseColumns.map((column) => column.id === 'status'
? {
...column,
kind: 'select',
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column),
rows,
rowKey: 'id',
};
export function setup(api, log) {
return api.on('editCommitted', (e) => log({
ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
}));
}<!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 id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const STATUSES = ['대기', '진행', '완료'];
const rows = [
{ id: 1, title: '견적서 보내기', status: '진행' },
{ id: 2, title: '계약서 검토', status: '대기' },
{ id: 3, title: '샘플 발송', status: '완료' },
{ id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
const baseColumns = [
{ id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
const options = {
columns: baseColumns.map((column) => column.id === 'status'
? {
...column,
kind: 'select',
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column),
rows,
rowKey: 'id',
};
function setup(api, log) {
return api.on('editCommitted', (e) => log({
ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
}));
}
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);
});
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, reactEditor, type CellEditorProps, type GridOptions } from '@maxgrid/react';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. 입력이 바뀔 때마다 onChange로 값을 알리고, 선택 목록은 고르는 즉시 commit()으로 끝내요.
// Enter, Esc, Tab은 표가 알아서 처리해요.
function StatusEditor({ value, error, onChange, commit }: CellEditorProps<Row>) {
return (
<select
defaultValue={String(value ?? '')}
aria-invalid={error !== null}
style={{ width: '100%', height: '100%', font: 'inherit' }}
onChange={(event) => {
onChange(event.target.value);
commit();
}}
>
{STATUSES.map((status) => (
<option key={status}>{status}</option>
))}
</select>
);
}
const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status' ? { ...column, cellEditor: reactEditor(StatusEditor) } : column,
),
rows,
rowKey: 'id',
};
export function ExampleGrid() {
return (
<div style={{ height: 220 }}>
<Grid<Row> options={options} />
</div>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['대기', '진행', '완료'];
export const rows: Row[] = [
{ id: 1, title: '견적서 보내기', status: '진행' },
{ id: 2, title: '계약서 검토', status: '대기' },
{ id: 3, title: '샘플 발송', status: '완료' },
{ id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log({
ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
}),
);
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { Grid, vueEditor, type GridOptions } from '@maxgrid/vue';
import { defineComponent, h, type PropType } from 'vue';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. 표는 마지막 modelValue를 읽고, Enter·Esc·Tab은 표가 처리해요.
// 선택 목록은 값을 알린 뒤 'commit'을 내보내 바로 끝내요.
const StatusEditor = defineComponent({
props: {
modelValue: { type: String, default: '' },
error: { type: String as PropType<string | null>, default: null },
},
emits: ['update:modelValue', 'commit', 'cancel'],
setup(props, { emit }) {
return () =>
h(
'select',
{
value: props.modelValue,
'aria-invalid': props.error !== null,
style: { width: '100%', height: '100%', font: 'inherit' },
onChange: (event: Event) => {
emit('update:modelValue', (event.target as HTMLSelectElement).value);
emit('commit');
},
},
STATUSES.map((status) => h('option', { value: status }, status)),
);
},
});
const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status' ? { ...column, cellEditor: vueEditor<Row>(StatusEditor) } : column,
),
rows,
rowKey: 'id',
};
</script>
<template>
<Grid style="height: 220px" :options="options" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['대기', '진행', '완료'];
export const rows: Row[] = [
{ id: 1, title: '견적서 보내기', status: '진행' },
{ id: 2, title: '계약서 검토', status: '대기' },
{ id: 3, title: '샘플 발송', status: '완료' },
{ id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log({
ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
}),
);
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, Input, type OnInit } from '@angular/core';
import {
GridComponent,
angularEditor,
type GridCellEditor,
type GridOptions,
} from '@maxgrid/angular';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. GridCellEditor의 getValue()로 현재 값을 알려 주고, 입력 이름이 value, commit, cancel이면
// 표가 알아서 채워 줘요. 선택 목록은 고르는 즉시 commit()으로 끝내요. Enter·Esc·Tab은 표가 처리해요.
@Component({
selector: 'app-status-editor',
standalone: true,
template: `
<select
style="width: 100%; height: 100%; font: inherit"
[attr.aria-invalid]="invalid"
(change)="pick($event)"
>
@for (status of statuses; track status) {
<option [value]="status" [selected]="status === current">{{ status }}</option>
}
</select>
`,
})
export class StatusEditorComponent implements GridCellEditor, OnInit {
@Input() value: unknown = '';
@Input() commit: () => void = () => {};
readonly statuses = STATUSES;
invalid = false;
current = '';
ngOnInit(): void {
this.current = String(this.value ?? '');
}
pick(event: Event): void {
this.current = (event.target as HTMLSelectElement).value;
this.commit();
}
getValue(): unknown {
return this.current;
}
setError(message: string | null): void {
this.invalid = message !== null;
}
}
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `<mx-grid style="height: 220px" [options]="options" />`,
})
export class ExampleGridComponent {
readonly options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? { ...column, cellEditor: angularEditor<Row>(StatusEditorComponent) }
: column,
),
rows,
rowKey: 'id',
};
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['대기', '진행', '완료'];
export const rows: Row[] = [
{ id: 1, title: '견적서 보내기', status: '진행' },
{ id: 2, title: '계약서 검토', status: '대기' },
{ id: 3, title: '샘플 발송', status: '완료' },
{ id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log({
ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
}),
);
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);export const STATUSES = ['Pending', 'Active', 'Done'];
export const rows = [
{ id: 1, title: 'Send the quote', status: 'Active' },
{ id: 2, title: 'Review the contract', status: 'Pending' },
{ id: 3, title: 'Ship samples', status: 'Done' },
{ id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
export const baseColumns = [
{ id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
export const options = {
columns: baseColumns.map((column) => column.id === 'status'
? {
...column,
kind: 'select',
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column),
rows,
rowKey: 'id',
};
export function setup(api, log) {
return api.on('editCommitted', (e) => log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`));
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Use your own component as the cell editor</title>
</head>
<body>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const STATUSES = ['Pending', 'Active', 'Done'];
const rows = [
{ id: 1, title: 'Send the quote', status: 'Active' },
{ id: 2, title: 'Review the contract', status: 'Pending' },
{ id: 3, title: 'Ship samples', status: 'Done' },
{ id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
const baseColumns = [
{ id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
const options = {
columns: baseColumns.map((column) => column.id === 'status'
? {
...column,
kind: 'select',
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column),
rows,
rowKey: 'id',
};
function setup(api, log) {
return api.on('editCommitted', (e) => log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`));
}
options.ariaLabel = "Use your own component as the cell editor";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, reactEditor, type CellEditorProps, type GridOptions } from '@maxgrid/react';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. 입력이 바뀔 때마다 onChange로 값을 알리고, 선택 목록은 고르는 즉시 commit()으로 끝내요.
// Enter, Esc, Tab은 표가 알아서 처리해요.
function StatusEditor({ value, error, onChange, commit }: CellEditorProps<Row>) {
return (
<select
defaultValue={String(value ?? '')}
aria-invalid={error !== null}
style={{ width: '100%', height: '100%', font: 'inherit' }}
onChange={(event) => {
onChange(event.target.value);
commit();
}}
>
{STATUSES.map((status) => (
<option key={status}>{status}</option>
))}
</select>
);
}
const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status' ? { ...column, cellEditor: reactEditor(StatusEditor) } : column,
),
rows,
rowKey: 'id',
};
export function ExampleGrid() {
return (
<div style={{ height: 220 }}>
<Grid<Row> options={options} />
</div>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['Pending', 'Active', 'Done'];
export const rows: Row[] = [
{ id: 1, title: 'Send the quote', status: 'Active' },
{ id: 2, title: 'Review the contract', status: 'Pending' },
{ id: 3, title: 'Ship samples', status: 'Done' },
{ id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`),
);
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { Grid, vueEditor, type GridOptions } from '@maxgrid/vue';
import { defineComponent, h, type PropType } from 'vue';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. 표는 마지막 modelValue를 읽고, Enter·Esc·Tab은 표가 처리해요.
// 선택 목록은 값을 알린 뒤 'commit'을 내보내 바로 끝내요.
const StatusEditor = defineComponent({
props: {
modelValue: { type: String, default: '' },
error: { type: String as PropType<string | null>, default: null },
},
emits: ['update:modelValue', 'commit', 'cancel'],
setup(props, { emit }) {
return () =>
h(
'select',
{
value: props.modelValue,
'aria-invalid': props.error !== null,
style: { width: '100%', height: '100%', font: 'inherit' },
onChange: (event: Event) => {
emit('update:modelValue', (event.target as HTMLSelectElement).value);
emit('commit');
},
},
STATUSES.map((status) => h('option', { value: status }, status)),
);
},
});
const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status' ? { ...column, cellEditor: vueEditor<Row>(StatusEditor) } : column,
),
rows,
rowKey: 'id',
};
</script>
<template>
<Grid style="height: 220px" :options="options" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['Pending', 'Active', 'Done'];
export const rows: Row[] = [
{ id: 1, title: 'Send the quote', status: 'Active' },
{ id: 2, title: 'Review the contract', status: 'Pending' },
{ id: 3, title: 'Ship samples', status: 'Done' },
{ id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`),
);
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, Input, type OnInit } from '@angular/core';
import {
GridComponent,
angularEditor,
type GridCellEditor,
type GridOptions,
} from '@maxgrid/angular';
import { STATUSES, baseColumns, rows, type Row } from './example';
// 셀 에디터 컴포넌트예요. GridCellEditor의 getValue()로 현재 값을 알려 주고, 입력 이름이 value, commit, cancel이면
// 표가 알아서 채워 줘요. 선택 목록은 고르는 즉시 commit()으로 끝내요. Enter·Esc·Tab은 표가 처리해요.
@Component({
selector: 'app-status-editor',
standalone: true,
template: `
<select
style="width: 100%; height: 100%; font: inherit"
[attr.aria-invalid]="invalid"
(change)="pick($event)"
>
@for (status of statuses; track status) {
<option [value]="status" [selected]="status === current">{{ status }}</option>
}
</select>
`,
})
export class StatusEditorComponent implements GridCellEditor, OnInit {
@Input() value: unknown = '';
@Input() commit: () => void = () => {};
readonly statuses = STATUSES;
invalid = false;
current = '';
ngOnInit(): void {
this.current = String(this.value ?? '');
}
pick(event: Event): void {
this.current = (event.target as HTMLSelectElement).value;
this.commit();
}
getValue(): unknown {
return this.current;
}
setError(message: string | null): void {
this.invalid = message !== null;
}
}
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `<mx-grid style="height: 220px" [options]="options" />`,
})
export class ExampleGridComponent {
readonly options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? { ...column, cellEditor: angularEditor<Row>(StatusEditorComponent) }
: column,
),
rows,
rowKey: 'id',
};
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
title: string;
status: string;
}
export const STATUSES = ['Pending', 'Active', 'Done'];
export const rows: Row[] = [
{ id: 1, title: 'Send the quote', status: 'Active' },
{ id: 2, title: 'Review the contract', status: 'Pending' },
{ id: 3, title: 'Ship samples', status: 'Done' },
{ id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
export const baseColumns: ColumnDef<Row>[] = [
{ id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
{ id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
export const options: GridOptions<Row> = {
columns: baseColumns.map((column) =>
column.id === 'status'
? {
...column,
kind: 'select' as const,
editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
}
: column,
),
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (e) =>
log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`),
);
}