본문으로 건너뛰기Skip to content
예제 첫화면Examples home

찾는 방식과 자동 선택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.

활용Intermediate
직접 써 보기Live preview찾는 방식과 자동 선택Match modes and auto-pick

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
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());
}

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
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());
}