서버에 물어 목록 채우기Fill the list by asking a server
cellEditor 'remote'는 글자를 치면 debounceMs 뒤에 source를 한 번 불러 목록을 채워요. 새 글자가 오면 이전 요청은 취소되고 늦게 온 응답은 버려요. 저장되는 값은 고른 항목의 value이고, 칸에 보일 글자는 formatValue가 정해요.cellEditor 'remote' calls source once after debounceMs to fill the list. A new key cancels the previous request and a late response is dropped. The stored value is the picked item's value, and formatValue decides what the cell shows.
코드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: 280px"></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);// 서버를 흉내 내는 고객 목록이에요. 실제로는 source 안에서 fetch로 서버에 물어요.
const CUSTOMERS = [
'김하늘',
'이도윤',
'박서연',
'최지우',
'정민준',
'강서윤',
'조현우',
'윤아린',
'장도현',
'임수아',
'한지민',
'오세훈',
'서예린',
'신준서',
'권나연',
'황민석',
'안유진',
'송지호',
'류하은',
'전태오',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** 느린 서버 흉내: 300ms 뒤에 글자가 든 고객을 돌려주고, 취소되면 멈춰요. */
function search(query, signal) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// 글자를 치면 debounceMs 뒤에 source를 한 번 불러요. 새 글자가 오면 이전 요청은 signal로 취소돼요.
export const options = {
columns: [
{ id: 'order', title: '주문', width: 110 },
{
id: 'customer',
title: '고객(서버 검색)',
width: 260,
editable: true,
cellEditor: 'remote',
// 저장 값은 고객 번호뿐이라 칸에 보일 글자는 formatValue가 정해요.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: '이름 검색',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '"고객" 칸을 두 번 누르고 "김"이나 "서"를 쳐 보세요. 잠깐 "불러오는 중…"이 보인 뒤 목록이 나와요.',
en: 'Double-click a "고객" (customer) cell and type "김" or "서". "Loading…" shows briefly and then the list appears.',
});
const offs = [
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: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 서버를 흉내 내는 고객 목록이에요. 실제로는 source 안에서 fetch로 서버에 물어요.
const CUSTOMERS = [
'김하늘',
'이도윤',
'박서연',
'최지우',
'정민준',
'강서윤',
'조현우',
'윤아린',
'장도현',
'임수아',
'한지민',
'오세훈',
'서예린',
'신준서',
'권나연',
'황민석',
'안유진',
'송지호',
'류하은',
'전태오',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** 느린 서버 흉내: 300ms 뒤에 글자가 든 고객을 돌려주고, 취소되면 멈춰요. */
function search(query, signal) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// 글자를 치면 debounceMs 뒤에 source를 한 번 불러요. 새 글자가 오면 이전 요청은 signal로 취소돼요.
const options = {
columns: [
{ id: 'order', title: '주문', width: 110 },
{
id: 'customer',
title: '고객(서버 검색)',
width: 260,
editable: true,
cellEditor: 'remote',
// 저장 값은 고객 번호뿐이라 칸에 보일 글자는 formatValue가 정해요.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: '이름 검색',
},
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '"고객" 칸을 두 번 누르고 "김"이나 "서"를 쳐 보세요. 잠깐 "불러오는 중…"이 보인 뒤 목록이 나와요.',
en: 'Double-click a "고객" (customer) cell and type "김" or "서". "Loading…" shows briefly and then the list appears.',
});
const offs = [
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: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
order: string;
customer: number | null;
}
// 서버를 흉내 내는 고객 목록이에요. 실제로는 source 안에서 fetch로 서버에 물어요.
const CUSTOMERS = [
'김하늘',
'이도윤',
'박서연',
'최지우',
'정민준',
'강서윤',
'조현우',
'윤아린',
'장도현',
'임수아',
'한지민',
'오세훈',
'서예린',
'신준서',
'권나연',
'황민석',
'안유진',
'송지호',
'류하은',
'전태오',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** 느린 서버 흉내: 300ms 뒤에 글자가 든 고객을 돌려주고, 취소되면 멈춰요. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// 글자를 치면 debounceMs 뒤에 source를 한 번 불러요. 새 글자가 오면 이전 요청은 signal로 취소돼요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 110 },
{
id: 'customer',
title: '고객(서버 검색)',
width: 260,
editable: true,
cellEditor: 'remote',
// 저장 값은 고객 번호뿐이라 칸에 보일 글자는 formatValue가 정해요.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: '이름 검색',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"고객" 칸을 두 번 누르고 "김"이나 "서"를 쳐 보세요. 잠깐 "불러오는 중…"이 보인 뒤 목록이 나와요.',
en: 'Double-click a "고객" (customer) cell and type "김" or "서". "Loading…" shows briefly and then the list appears.',
});
const offs = [
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: 280px" :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;
order: string;
customer: number | null;
}
// 서버를 흉내 내는 고객 목록이에요. 실제로는 source 안에서 fetch로 서버에 물어요.
const CUSTOMERS = [
'김하늘',
'이도윤',
'박서연',
'최지우',
'정민준',
'강서윤',
'조현우',
'윤아린',
'장도현',
'임수아',
'한지민',
'오세훈',
'서예린',
'신준서',
'권나연',
'황민석',
'안유진',
'송지호',
'류하은',
'전태오',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** 느린 서버 흉내: 300ms 뒤에 글자가 든 고객을 돌려주고, 취소되면 멈춰요. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// 글자를 치면 debounceMs 뒤에 source를 한 번 불러요. 새 글자가 오면 이전 요청은 signal로 취소돼요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 110 },
{
id: 'customer',
title: '고객(서버 검색)',
width: 260,
editable: true,
cellEditor: 'remote',
// 저장 값은 고객 번호뿐이라 칸에 보일 글자는 formatValue가 정해요.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: '이름 검색',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"고객" 칸을 두 번 누르고 "김"이나 "서"를 쳐 보세요. 잠깐 "불러오는 중…"이 보인 뒤 목록이 나와요.',
en: 'Double-click a "고객" (customer) cell and type "김" or "서". "Loading…" shows briefly and then the list appears.',
});
const offs = [
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: 280px" [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;
order: string;
customer: number | null;
}
// 서버를 흉내 내는 고객 목록이에요. 실제로는 source 안에서 fetch로 서버에 물어요.
const CUSTOMERS = [
'김하늘',
'이도윤',
'박서연',
'최지우',
'정민준',
'강서윤',
'조현우',
'윤아린',
'장도현',
'임수아',
'한지민',
'오세훈',
'서예린',
'신준서',
'권나연',
'황민석',
'안유진',
'송지호',
'류하은',
'전태오',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** 느린 서버 흉내: 300ms 뒤에 글자가 든 고객을 돌려주고, 취소되면 멈춰요. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote'는 editors 묶음이 필요해요(전체 번들에는 들어 있어요).
// 글자를 치면 debounceMs 뒤에 source를 한 번 불러요. 새 글자가 오면 이전 요청은 signal로 취소돼요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 110 },
{
id: 'customer',
title: '고객(서버 검색)',
width: 260,
editable: true,
cellEditor: 'remote',
// 저장 값은 고객 번호뿐이라 칸에 보일 글자는 formatValue가 정해요.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: '이름 검색',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"고객" 칸을 두 번 누르고 "김"이나 "서"를 쳐 보세요. 잠깐 "불러오는 중…"이 보인 뒤 목록이 나와요.',
en: 'Double-click a "고객" (customer) cell and type "김" or "서". "Loading…" shows briefly and then the list appears.',
});
const offs = [
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: 280px"></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);// A customer list that imitates a server. In real use, source asks the server with fetch.
const CUSTOMERS = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Ava Morgan',
'Mason Reed',
'Sophia Hayes',
'Lucas Bennett',
'Mia Foster',
'Logan Price',
'Isabella Ward',
'James Cooper',
'Charlotte Gray',
'Benjamin Ross',
'Amelia Hughes',
'Henry Parker',
'Harper Collins',
'Jack Murphy',
'Evelyn Wood',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** A slow server imitation: after 300ms it returns the customers containing the text, and it stops when cancelled. */
function search(query, signal) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote' needs the editors bundle (the full bundle includes it).
// Typing calls source once after debounceMs. When new text arrives, the previous request is cancelled through signal.
export const options = {
columns: [
{ id: 'order', title: 'Order', width: 110 },
{
id: 'customer',
title: 'Customer (server search)',
width: 280,
editable: true,
cellEditor: 'remote',
// The stored value is only the customer number, so formatValue decides the text shown in the cell.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: 'Search name',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Double-click a "Customer" cell and type "Li" or "Ma". "Loading…" shows briefly and then the list appears.');
const offs = [
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>Fill the list by asking a server</title>
</head>
<body>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// A customer list that imitates a server. In real use, source asks the server with fetch.
const CUSTOMERS = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Ava Morgan',
'Mason Reed',
'Sophia Hayes',
'Lucas Bennett',
'Mia Foster',
'Logan Price',
'Isabella Ward',
'James Cooper',
'Charlotte Gray',
'Benjamin Ross',
'Amelia Hughes',
'Henry Parker',
'Harper Collins',
'Jack Murphy',
'Evelyn Wood',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** A slow server imitation: after 300ms it returns the customers containing the text, and it stops when cancelled. */
function search(query, signal) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote' needs the editors bundle (the full bundle includes it).
// Typing calls source once after debounceMs. When new text arrives, the previous request is cancelled through signal.
const options = {
columns: [
{ id: 'order', title: 'Order', width: 110 },
{
id: 'customer',
title: 'Customer (server search)',
width: 280,
editable: true,
cellEditor: 'remote',
// The stored value is only the customer number, so formatValue decides the text shown in the cell.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: 'Search name',
},
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Double-click a "Customer" cell and type "Li" or "Ma". "Loading…" shows briefly and then the list appears.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
options.ariaLabel = "Fill the list by asking a server";
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: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
order: string;
customer: number | null;
}
// A customer list that imitates a server. In real use, source asks the server with fetch.
const CUSTOMERS = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Ava Morgan',
'Mason Reed',
'Sophia Hayes',
'Lucas Bennett',
'Mia Foster',
'Logan Price',
'Isabella Ward',
'James Cooper',
'Charlotte Gray',
'Benjamin Ross',
'Amelia Hughes',
'Henry Parker',
'Harper Collins',
'Jack Murphy',
'Evelyn Wood',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** A slow server imitation: after 300ms it returns the customers containing the text, and it stops when cancelled. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote' needs the editors bundle (the full bundle includes it).
// Typing calls source once after debounceMs. When new text arrives, the previous request is cancelled through signal.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 110 },
{
id: 'customer',
title: 'Customer (server search)',
width: 280,
editable: true,
cellEditor: 'remote',
// The stored value is only the customer number, so formatValue decides the text shown in the cell.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: 'Search name',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Customer" cell and type "Li" or "Ma". "Loading…" shows briefly and then the list appears.',
);
const offs = [
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: 280px" :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;
order: string;
customer: number | null;
}
// A customer list that imitates a server. In real use, source asks the server with fetch.
const CUSTOMERS = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Ava Morgan',
'Mason Reed',
'Sophia Hayes',
'Lucas Bennett',
'Mia Foster',
'Logan Price',
'Isabella Ward',
'James Cooper',
'Charlotte Gray',
'Benjamin Ross',
'Amelia Hughes',
'Henry Parker',
'Harper Collins',
'Jack Murphy',
'Evelyn Wood',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** A slow server imitation: after 300ms it returns the customers containing the text, and it stops when cancelled. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote' needs the editors bundle (the full bundle includes it).
// Typing calls source once after debounceMs. When new text arrives, the previous request is cancelled through signal.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 110 },
{
id: 'customer',
title: 'Customer (server search)',
width: 280,
editable: true,
cellEditor: 'remote',
// The stored value is only the customer number, so formatValue decides the text shown in the cell.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: 'Search name',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Customer" cell and type "Li" or "Ma". "Loading…" shows briefly and then the list appears.',
);
const offs = [
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: 280px" [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;
order: string;
customer: number | null;
}
// A customer list that imitates a server. In real use, source asks the server with fetch.
const CUSTOMERS = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Park',
'Ethan Brooks',
'Ava Morgan',
'Mason Reed',
'Sophia Hayes',
'Lucas Bennett',
'Mia Foster',
'Logan Price',
'Isabella Ward',
'James Cooper',
'Charlotte Gray',
'Benjamin Ross',
'Amelia Hughes',
'Henry Parker',
'Harper Collins',
'Jack Murphy',
'Evelyn Wood',
].map((name, i) => ({ value: i + 1, label: `${name} (C-${String(i + 1).padStart(3, '0')})` }));
const rows: Row[] = [
{ id: 1, order: 'A-1001', customer: 3 },
{ id: 2, order: 'A-1002', customer: null },
{ id: 3, order: 'A-1003', customer: 12 },
];
/** A slow server imitation: after 300ms it returns the customers containing the text, and it stops when cancelled. */
function search(query: string, signal: AbortSignal): Promise<{ value: number; label: string }[]> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => resolve(CUSTOMERS.filter((c) => c.label.includes(query))), 300);
signal.addEventListener('abort', () => {
clearTimeout(timer);
reject(new DOMException('aborted', 'AbortError'));
});
});
}
// cellEditor: 'remote' needs the editors bundle (the full bundle includes it).
// Typing calls source once after debounceMs. When new text arrives, the previous request is cancelled through signal.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 110 },
{
id: 'customer',
title: 'Customer (server search)',
width: 280,
editable: true,
cellEditor: 'remote',
// The stored value is only the customer number, so formatValue decides the text shown in the cell.
formatValue: (id) => CUSTOMERS.find((c) => c.value === id)?.label ?? '',
editorParams: {
source: (query, { signal }) => search(query, signal),
debounceMs: 250,
minChars: 1,
placeholder: 'Search name',
},
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click a "Customer" cell and type "Li" or "Ma". "Loading…" shows briefly and then the list appears.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}