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

이름 검색: 포함·시작·같음·끝Name search: contains, starts with, equals, ends with

글자 필터는 '포함', '시작 문자', '같음', '끝 문자', '포함하지 않음' 중에서 고를 수 있고 대소문자는 구분하지 않아요. 같은 입력도 방식에 따라 결과가 달라져요.A text filter can match contains, starts with, equals, ends with or does not contain, ignoring case. The same input gives different results per mode.

입문Beginner
직접 써 보기Live preview이름 검색: 포함·시작·같음·끝Name search: contains, starts with, equals, ends with

코드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 class="toolbar">
    <select aria-label="방식" id="operator">
      <option value="contains" selected>포함 (기본)</option>
      <option value="startsWith">시작 문자</option>
      <option value="equals">같음</option>
      <option value="endsWith">끝 문자</option>
      <option value="notContains">포함하지 않음</option>
    </select>
    <input type="text" aria-label="이름" placeholder="이름 (예: 김)" id="text" />
  </div>
  <div id="grid" style="height: 560px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(api, event.target.value));
example.js
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const mails = ['minjun', 'seoyeon', 'jiho', 'yuna', 'doyun', 'sohee', 'sehun', 'seoyun'];
const depts = ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 120 },
    { id: 'email', title: '이메일', width: 220 },
    { id: 'dept', title: '부서', width: 130 },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    name: names[i % 8],
    email: `${mails[i % 8]}${i + 1}@maxmine.com`,
    dept: depts[(i * 3) % 4],
  })),
  rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
  ? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
  : null);
export function setup(api, log) {
  state.op = 'contains';
  state.text = '';
  const off = api.on('filterChanged', () => log({
    ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
    en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
  }));
  return () => off();
}
export const actions = {
  operator: (api, value) => {
    state.op = value ?? 'contains';
    apply(api);
  },
  text: (api, value) => {
    state.text = (value ?? '').trim();
    apply(api);
  },
};

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 class="toolbar">
    <select aria-label="Mode" id="operator">
      <option value="contains" selected>Contains (default)</option>
      <option value="startsWith">Starts with</option>
      <option value="equals">Equals</option>
      <option value="endsWith">Ends with</option>
      <option value="notContains">Does not contain</option>
    </select>
    <input
      type="text"
      aria-label="Name"
      placeholder="Name (e.g. Lee)"
      id="text"
    />
  </div>
  <div id="grid" style="height: 560px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('operator').addEventListener('change', (event) => actions.operator(api, event.target.value));
document.getElementById('text').addEventListener('input', (event) => actions.text(api, event.target.value));
example.js
const names = [
  'Lee Carter',
  'Emma Stone',
  'Noah Park',
  'Olivia Brooks',
  'Ethan Reed',
  'Sophia Hayes',
  'Mason Foster',
  'Lee Morgan',
];
const mails = ['lcarter', 'estone', 'npark', 'obrooks', 'ereed', 'shayes', 'mfoster', 'lmorgan'];
const depts = ['Dev', 'Design', 'Sales', 'HR'];
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 140 },
    { id: 'email', title: 'Email', width: 220 },
    { id: 'dept', title: 'Department', width: 130 },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    name: names[i % 8],
    email: `${mails[i % 8]}${i + 1}@maxmine.com`,
    dept: depts[(i * 3) % 4],
  })),
  rowKey: 'id',
};
const state = { op: 'contains', text: '' };
const apply = (api) => api.setFilterModel(state.text
  ? { match: 'all', items: [{ columnId: 'name', operator: state.op, value: state.text }] }
  : null);
export function setup(api, log) {
  state.op = 'contains';
  state.text = '';
  const off = api.on('filterChanged', () => log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`));
  return () => off();
}
export const actions = {
  operator: (api, value) => {
    state.op = value ?? 'contains';
    apply(api);
  },
  text: (api, value) => {
    state.text = (value ?? '').trim();
    apply(api);
  },
};