실패·빈 결과·느린 응답Failures, empty results and slow responses
remote 편집기의 요청이 실패하면 목록 안에 오류 글자가 나오고 error 이벤트가 한 번 가요. 결과가 비면 noResultsText가, 기다리는 동안 loadingText가 보여요. 느린 응답 도중 새 글자를 치면 이전 요청이 취소되고 그 응답은 버려져요.When a remote editor request fails, an error text appears in the list and one error event is sent. An empty result shows noResultsText and waiting shows loadingText. Typing during a slow response cancels the old request and drops its answer.
코드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: 260px"></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);// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const rows = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// 글자에 따라 다르게 동작하는 서버 흉내예요: "err"는 실패, "slow"는 3초 뒤 응답, "none"은 빈 결과, 나머지는 정상이에요.
function makeSource(log) {
return (query, { signal }) => new Promise((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err'))
return reject(new Error('server error'));
if (query.includes('none'))
return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log({ ko: `요청 취소: "${query}"`, en: `Request aborted: "${query}"` });
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options = {
columns: [
{ id: 'code', title: '코드', width: 100 },
{
id: 'item',
title: '품목(원격)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: L('서버에 물어 보는 중…', 'Asking the server…'),
noResultsText: L('맞는 품목이 없어요', 'No matching items'),
},
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
// 로그를 남기도록 source를 다시 만들어 컬럼에 걸어요.
api.setColumns([
options.columns[0],
{
...options.columns[1],
editorParams: {
...options.columns[1].editorParams,
source: makeSource(log),
},
},
]);
log({
ko: '"품목" 칸을 두 번 누르고 "err", "none", "slow", 아무 글자를 차례로 쳐 보세요.',
en: 'Double-click an "품목" (item) cell and type "err", "none", "slow" and any other text in turn.',
});
const offs = [
api.on('error', (e) => log({
ko: `오류 이벤트(${e.code}): ${e.where}`,
en: `Error event (${e.code}): ${e.where}`,
})),
api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
})),
];
return () => offs.forEach((off) => off());
}<!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: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const rows = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// 글자에 따라 다르게 동작하는 서버 흉내예요: "err"는 실패, "slow"는 3초 뒤 응답, "none"은 빈 결과, 나머지는 정상이에요.
function makeSource(log) {
return (query, { signal }) => new Promise((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err'))
return reject(new Error('server error'));
if (query.includes('none'))
return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log({ ko: `요청 취소: "${query}"`, en: `Request aborted: "${query}"` });
reject(new DOMException('aborted', 'AbortError'));
});
});
}
const options = {
columns: [
{ id: 'code', title: '코드', width: 100 },
{
id: 'item',
title: '품목(원격)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: L('서버에 물어 보는 중…', 'Asking the server…'),
noResultsText: L('맞는 품목이 없어요', 'No matching items'),
},
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
// 로그를 남기도록 source를 다시 만들어 컬럼에 걸어요.
api.setColumns([
options.columns[0],
{
...options.columns[1],
editorParams: {
...options.columns[1].editorParams,
source: makeSource(log),
},
},
]);
log({
ko: '"품목" 칸을 두 번 누르고 "err", "none", "slow", 아무 글자를 차례로 쳐 보세요.',
en: 'Double-click an "품목" (item) cell and type "err", "none", "slow" and any other text in turn.',
});
const offs = [
api.on('error', (e) => log({
ko: `오류 이벤트(${e.code}): ${e.where}`,
en: `Error event (${e.code}): ${e.where}`,
})),
api.on('editCommitted', (e) => log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
})),
];
return () => offs.forEach((off) => off());
}
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 { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// 글자에 따라 다르게 동작하는 서버 흉내예요: "err"는 실패, "slow"는 3초 뒤 응답, "none"은 빈 결과, 나머지는 정상이에요.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log({ ko: `요청 취소: "${query}"`, en: `Request aborted: "${query}"` });
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 100 },
{
id: 'item',
title: '품목(원격)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: L('서버에 물어 보는 중…', 'Asking the server…'),
noResultsText: L('맞는 품목이 없어요', 'No matching items'),
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// 로그를 남기도록 source를 다시 만들어 컬럼에 걸어요.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log({
ko: '"품목" 칸을 두 번 누르고 "err", "none", "slow", 아무 글자를 차례로 쳐 보세요.',
en: 'Double-click an "품목" (item) cell and type "err", "none", "slow" and any other text in turn.',
});
const offs = [
api.on('error', (e) =>
log({
ko: `오류 이벤트(${e.code}): ${e.where}`,
en: `Error event (${e.code}): ${e.where}`,
}),
),
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
];
return () => offs.forEach((off) => off());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { 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>
<Grid style="height: 260px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// 글자에 따라 다르게 동작하는 서버 흉내예요: "err"는 실패, "slow"는 3초 뒤 응답, "none"은 빈 결과, 나머지는 정상이에요.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log({ ko: `요청 취소: "${query}"`, en: `Request aborted: "${query}"` });
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 100 },
{
id: 'item',
title: '품목(원격)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: L('서버에 물어 보는 중…', 'Asking the server…'),
noResultsText: L('맞는 품목이 없어요', 'No matching items'),
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// 로그를 남기도록 source를 다시 만들어 컬럼에 걸어요.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log({
ko: '"품목" 칸을 두 번 누르고 "err", "none", "slow", 아무 글자를 차례로 쳐 보세요.',
en: 'Double-click an "품목" (item) cell and type "err", "none", "slow" and any other text in turn.',
});
const offs = [
api.on('error', (e) =>
log({
ko: `오류 이벤트(${e.code}): ${e.where}`,
en: `Error event (${e.code}): ${e.where}`,
}),
),
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
];
return () => offs.forEach((off) => off());
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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';
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko: string, en: string): string =>
document.documentElement.dataset.lang === 'en' ? en : ko;
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// 글자에 따라 다르게 동작하는 서버 흉내예요: "err"는 실패, "slow"는 3초 뒤 응답, "none"은 빈 결과, 나머지는 정상이에요.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log({ ko: `요청 취소: "${query}"`, en: `Request aborted: "${query}"` });
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 100 },
{
id: 'item',
title: '품목(원격)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: L('서버에 물어 보는 중…', 'Asking the server…'),
noResultsText: L('맞는 품목이 없어요', 'No matching items'),
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// 로그를 남기도록 source를 다시 만들어 컬럼에 걸어요.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log({
ko: '"품목" 칸을 두 번 누르고 "err", "none", "slow", 아무 글자를 차례로 쳐 보세요.',
en: 'Double-click an "품목" (item) cell and type "err", "none", "slow" and any other text in turn.',
});
const offs = [
api.on('error', (e) =>
log({
ko: `오류 이벤트(${e.code}): ${e.where}`,
en: `Error event (${e.code}): ${e.where}`,
}),
),
api.on('editCommitted', (e) =>
log({
ko: `행 ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
en: `Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`,
}),
),
];
return () => offs.forEach((off) => off());
}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: 260px"></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);const rows = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// A fake server that behaves differently depending on the text: "err" fails, "slow" answers after 3 seconds, "none" returns nothing, anything else is normal.
function makeSource(log) {
return (query, { signal }) => new Promise((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err'))
return reject(new Error('server error'));
if (query.includes('none'))
return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log(`Request aborted: "${query}"`);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options = {
columns: [
{ id: 'code', title: 'Code', width: 100 },
{
id: 'item',
title: 'Item (remote)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: 'Asking the server…',
noResultsText: 'No matching items',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
// Rebuild the source so it logs, and attach it to the column.
api.setColumns([
options.columns[0],
{
...options.columns[1],
editorParams: {
...options.columns[1].editorParams,
source: makeSource(log),
},
},
]);
log('Double-click an "Item" cell and type "err", "none", "slow" and any other text in turn.');
const offs = [
api.on('error', (e) => log(`Error event (${e.code}): ${e.where}`)),
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Failures, empty results and slow responses</title>
</head>
<body>
<div id="grid" style="height: 260px"></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, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// A fake server that behaves differently depending on the text: "err" fails, "slow" answers after 3 seconds, "none" returns nothing, anything else is normal.
function makeSource(log) {
return (query, { signal }) => new Promise((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err'))
return reject(new Error('server error'));
if (query.includes('none'))
return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log(`Request aborted: "${query}"`);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
const options = {
columns: [
{ id: 'code', title: 'Code', width: 100 },
{
id: 'item',
title: 'Item (remote)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: 'Asking the server…',
noResultsText: 'No matching items',
},
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
// Rebuild the source so it logs, and attach it to the column.
api.setColumns([
options.columns[0],
{
...options.columns[1],
editorParams: {
...options.columns[1].editorParams,
source: makeSource(log),
},
},
]);
log('Double-click an "Item" cell and type "err", "none", "slow" and any other text in turn.');
const offs = [
api.on('error', (e) => log(`Error event (${e.code}): ${e.where}`)),
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
options.ariaLabel = "Failures, empty results and slow responses";
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 { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// A fake server that behaves differently depending on the text: "err" fails, "slow" answers after 3 seconds, "none" returns nothing, anything else is normal.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log(`Request aborted: "${query}"`);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 100 },
{
id: 'item',
title: 'Item (remote)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: 'Asking the server…',
noResultsText: 'No matching items',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// Rebuild the source so it logs, and attach it to the column.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log('Double-click an "Item" cell and type "err", "none", "slow" and any other text in turn.');
const offs = [
api.on('error', (e) => log(`Error event (${e.code}): ${e.where}`)),
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}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 { 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>
<Grid style="height: 260px" :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;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// A fake server that behaves differently depending on the text: "err" fails, "slow" answers after 3 seconds, "none" returns nothing, anything else is normal.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log(`Request aborted: "${query}"`);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 100 },
{
id: 'item',
title: 'Item (remote)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: 'Asking the server…',
noResultsText: 'No matching items',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// Rebuild the source so it logs, and attach it to the column.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log('Double-click an "Item" cell and type "err", "none", "slow" and any other text in turn.');
const offs = [
api.on('error', (e) => log(`Error event (${e.code}): ${e.where}`)),
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}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 { options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<mx-grid style="height: 260px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
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;
code: string;
item: string | null;
}
const rows: Row[] = [
{ id: 1, code: 'P-01', item: null },
{ id: 2, code: 'P-02', item: 'apple' },
];
// A fake server that behaves differently depending on the text: "err" fails, "slow" answers after 3 seconds, "none" returns nothing, anything else is normal.
function makeSource(log: (message: LogText) => void) {
return (query: string, { signal }: { signal: AbortSignal }) =>
new Promise<{ value: string; label: string }[]>((resolve, reject) => {
const wait = query.includes('slow') ? 3000 : 200;
const timer = setTimeout(() => {
if (query.includes('err')) return reject(new Error('server error'));
if (query.includes('none')) return resolve([]);
resolve([1, 2, 3].map((n) => ({ value: `${query}-${n}`, label: `${query} #${n}` })));
}, wait);
signal.addEventListener('abort', () => {
clearTimeout(timer);
log(`Request aborted: "${query}"`);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 100 },
{
id: 'item',
title: 'Item (remote)',
width: 260,
editable: true,
cellEditor: 'remote',
editorParams: {
source: makeSource(() => undefined),
debounceMs: 200,
loadingText: 'Asking the server…',
noResultsText: 'No matching items',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
// Rebuild the source so it logs, and attach it to the column.
api.setColumns([
options.columns[0] as never,
{
...(options.columns[1] as object),
editorParams: {
...(options.columns[1] as { editorParams: object }).editorParams,
source: makeSource(log),
},
} as never,
]);
log('Double-click an "Item" cell and type "err", "none", "slow" and any other text in turn.');
const offs = [
api.on('error', (e) => log(`Error event (${e.code}): ${e.where}`)),
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}