찾는 방식과 자동 선택Match modes and auto-pick
combobox의 match는 항목 글자의 앞부분(startsWith)이나 어디든(contains)에서 찾고, pickSingleMatch는 맞는 항목이 하나일 때 Enter로 자동 선택해요. renderItem은 항목 글자를 바꾸고, maxHeight·itemAlign은 목록 모양을, commitOnPick은 고르자마자 확정할지를 정해요.The combobox match option searches the start of the item text (startsWith) or anywhere (contains), and pickSingleMatch auto-picks on Enter when exactly one item matches. renderItem changes the item text, maxHeight and itemAlign shape the list, and commitOnPick decides whether picking commits at once.
코드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);const CODES = [
{ value: 'A-100', label: 'A-100 노트북' },
{ value: 'A-200', label: 'A-200 모니터' },
{ value: 'B-100', label: 'B-100 키보드' },
{ value: 'B-210', label: 'B-210 마우스' },
{ value: 'C-300', label: 'C-300 허브' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows = [
{ id: 1, item: '개발용', code: '', fruit: '' },
{ id: 2, item: '사무용', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith'는 항목 글자의 앞부분만, 기본 'contains'는 어디든 찾아요.
// pickSingleMatch: Enter를 눌렀을 때 맞는 항목이 하나면 자동으로 골라요.
// renderItem: 항목에 보일 글자를 바꿔요(글자로만 쓰고 HTML로 해석하지 않아요).
export const options = {
columns: [
{ id: 'item', title: '용도', width: 100 },
{
id: 'code',
title: '자재(앞부분 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: '과일(어디든 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log({
ko: '"자재"는 앞부분만 맞춰요: "b-"를 치고 Enter. "과일"은 항목을 고른 뒤 Enter를 한 번 더 눌러야 확정돼요.',
en: 'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
});
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>
const CODES = [
{ value: 'A-100', label: 'A-100 노트북' },
{ value: 'A-200', label: 'A-200 모니터' },
{ value: 'B-100', label: 'B-100 키보드' },
{ value: 'B-210', label: 'B-210 마우스' },
{ value: 'C-300', label: 'C-300 허브' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows = [
{ id: 1, item: '개발용', code: '', fruit: '' },
{ id: 2, item: '사무용', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith'는 항목 글자의 앞부분만, 기본 'contains'는 어디든 찾아요.
// pickSingleMatch: Enter를 눌렀을 때 맞는 항목이 하나면 자동으로 골라요.
// renderItem: 항목에 보일 글자를 바꿔요(글자로만 쓰고 HTML로 해석하지 않아요).
const options = {
columns: [
{ id: 'item', title: '용도', width: 100 },
{
id: 'code',
title: '자재(앞부분 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: '과일(어디든 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log({
ko: '"자재"는 앞부분만 맞춰요: "b-"를 치고 Enter. "과일"은 항목을 고른 뒤 Enter를 한 번 더 눌러야 확정돼요.',
en: 'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
});
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 노트북' },
{ value: 'A-200', label: 'A-200 모니터' },
{ value: 'B-100', label: 'B-100 키보드' },
{ value: 'B-210', label: 'B-210 마우스' },
{ value: 'C-300', label: 'C-300 허브' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: '개발용', code: '', fruit: '' },
{ id: 2, item: '사무용', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith'는 항목 글자의 앞부분만, 기본 'contains'는 어디든 찾아요.
// pickSingleMatch: Enter를 눌렀을 때 맞는 항목이 하나면 자동으로 골라요.
// renderItem: 항목에 보일 글자를 바꿔요(글자로만 쓰고 HTML로 해석하지 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '용도', width: 100 },
{
id: 'code',
title: '자재(앞부분 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: '과일(어디든 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"자재"는 앞부분만 맞춰요: "b-"를 치고 Enter. "과일"은 항목을 고른 뒤 Enter를 한 번 더 눌러야 확정돼요.',
en: 'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
});
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 노트북' },
{ value: 'A-200', label: 'A-200 모니터' },
{ value: 'B-100', label: 'B-100 키보드' },
{ value: 'B-210', label: 'B-210 마우스' },
{ value: 'C-300', label: 'C-300 허브' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: '개발용', code: '', fruit: '' },
{ id: 2, item: '사무용', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith'는 항목 글자의 앞부분만, 기본 'contains'는 어디든 찾아요.
// pickSingleMatch: Enter를 눌렀을 때 맞는 항목이 하나면 자동으로 골라요.
// renderItem: 항목에 보일 글자를 바꿔요(글자로만 쓰고 HTML로 해석하지 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '용도', width: 100 },
{
id: 'code',
title: '자재(앞부분 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: '과일(어디든 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"자재"는 앞부분만 맞춰요: "b-"를 치고 Enter. "과일"은 항목을 고른 뒤 Enter를 한 번 더 눌러야 확정돼요.',
en: 'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
});
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 노트북' },
{ value: 'A-200', label: 'A-200 모니터' },
{ value: 'B-100', label: 'B-100 키보드' },
{ value: 'B-210', label: 'B-210 마우스' },
{ value: 'C-300', label: 'C-300 허브' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: '개발용', code: '', fruit: '' },
{ id: 2, item: '사무용', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith'는 항목 글자의 앞부분만, 기본 'contains'는 어디든 찾아요.
// pickSingleMatch: Enter를 눌렀을 때 맞는 항목이 하나면 자동으로 골라요.
// renderItem: 항목에 보일 글자를 바꿔요(글자로만 쓰고 HTML로 해석하지 않아요).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '용도', width: 100 },
{
id: 'code',
title: '자재(앞부분 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: '과일(어디든 일치)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"자재"는 앞부분만 맞춰요: "b-"를 치고 Enter. "과일"은 항목을 고른 뒤 Enter를 한 번 더 눌러야 확정돼요.',
en: 'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
});
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);const CODES = [
{ value: 'A-100', label: 'A-100 Laptop' },
{ value: 'A-200', label: 'A-200 Monitor' },
{ value: 'B-100', label: 'B-100 Keyboard' },
{ value: 'B-210', label: 'B-210 Mouse' },
{ value: 'C-300', label: 'C-300 Hub' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows = [
{ id: 1, item: 'Dev use', code: '', fruit: '' },
{ id: 2, item: 'Office use', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith' searches only the start of the item text, the default 'contains' searches anywhere.
// pickSingleMatch: when Enter is pressed and exactly one item matches, it is picked automatically.
// renderItem: changes the text shown for an item (used as text only, never parsed as HTML).
export const options = {
columns: [
{ id: 'item', title: 'Use', width: 110 },
{
id: 'code',
title: 'Material (starts with)',
width: 210,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: 'Fruit (contains)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api, log) {
log('Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.');
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>Match modes and auto-pick</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>
const CODES = [
{ value: 'A-100', label: 'A-100 Laptop' },
{ value: 'A-200', label: 'A-200 Monitor' },
{ value: 'B-100', label: 'B-100 Keyboard' },
{ value: 'B-210', label: 'B-210 Mouse' },
{ value: 'C-300', label: 'C-300 Hub' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows = [
{ id: 1, item: 'Dev use', code: '', fruit: '' },
{ id: 2, item: 'Office use', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith' searches only the start of the item text, the default 'contains' searches anywhere.
// pickSingleMatch: when Enter is pressed and exactly one item matches, it is picked automatically.
// renderItem: changes the text shown for an item (used as text only, never parsed as HTML).
const options = {
columns: [
{ id: 'item', title: 'Use', width: 110 },
{
id: 'code',
title: 'Material (starts with)',
width: 210,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: 'Fruit (contains)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
function setup(api, log) {
log('Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.');
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}
options.ariaLabel = "Match modes and auto-pick";
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 Laptop' },
{ value: 'A-200', label: 'A-200 Monitor' },
{ value: 'B-100', label: 'B-100 Keyboard' },
{ value: 'B-210', label: 'B-210 Mouse' },
{ value: 'C-300', label: 'C-300 Hub' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: 'Dev use', code: '', fruit: '' },
{ id: 2, item: 'Office use', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith' searches only the start of the item text, the default 'contains' searches anywhere.
// pickSingleMatch: when Enter is pressed and exactly one item matches, it is picked automatically.
// renderItem: changes the text shown for an item (used as text only, never parsed as HTML).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Use', width: 110 },
{
id: 'code',
title: 'Material (starts with)',
width: 210,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: 'Fruit (contains)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
);
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 Laptop' },
{ value: 'A-200', label: 'A-200 Monitor' },
{ value: 'B-100', label: 'B-100 Keyboard' },
{ value: 'B-210', label: 'B-210 Mouse' },
{ value: 'C-300', label: 'C-300 Hub' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: 'Dev use', code: '', fruit: '' },
{ id: 2, item: 'Office use', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith' searches only the start of the item text, the default 'contains' searches anywhere.
// pickSingleMatch: when Enter is pressed and exactly one item matches, it is picked automatically.
// renderItem: changes the text shown for an item (used as text only, never parsed as HTML).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Use', width: 110 },
{
id: 'code',
title: 'Material (starts with)',
width: 210,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: 'Fruit (contains)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
);
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;
item: string;
code: string;
fruit: string;
}
const CODES = [
{ value: 'A-100', label: 'A-100 Laptop' },
{ value: 'A-200', label: 'A-200 Monitor' },
{ value: 'B-100', label: 'B-100 Keyboard' },
{ value: 'B-210', label: 'B-210 Mouse' },
{ value: 'C-300', label: 'C-300 Hub' },
];
const FRUITS = ['Apple', 'Apricot', 'Banana', 'Blueberry', 'Cherry'].map((v) => ({ value: v }));
const rows: Row[] = [
{ id: 1, item: 'Dev use', code: '', fruit: '' },
{ id: 2, item: 'Office use', code: 'B-100', fruit: 'Apple' },
];
// match: 'startsWith' searches only the start of the item text, the default 'contains' searches anywhere.
// pickSingleMatch: when Enter is pressed and exactly one item matches, it is picked automatically.
// renderItem: changes the text shown for an item (used as text only, never parsed as HTML).
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Use', width: 110 },
{
id: 'code',
title: 'Material (starts with)',
width: 210,
editable: true,
cellEditor: 'combobox',
editorOptions: CODES,
editorParams: {
match: 'startsWith',
pickSingleMatch: true,
renderItem: (option, ctx) => `${option.label ?? ''}${ctx.query === '' ? '' : ' ←'}`,
},
},
{
id: 'fruit',
title: 'Fruit (contains)',
width: 200,
editable: true,
cellEditor: 'combobox',
editorOptions: FRUITS,
editorParams: { match: 'contains', maxHeight: 120, itemAlign: 'center', commitOnPick: false },
},
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Material matches the start only: type "b-" and press Enter. For Fruit, picking only fills the input; press Enter again to commit.',
);
const offs = [
api.on('editCommitted', (e) => log(`Row ${e.rowKey}: ${e.columnId} = ${String(e.newValue)}`)),
];
return () => offs.forEach((off) => off());
}