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

헤더 아래 입력 칸에 치면 바로 걸러져요Type in the cells under the header to filter live

헤더 바로 아래에 컬럼마다 입력 칸이 생겨서, 글자를 치는 즉시 목록이 줄어들어요. 이름은 글자, 팀은 값 목록, 연봉은 범위(5000..6000), 입사일은 날짜 식, 재택은 예/아니오 선택이에요.A row of inputs under the header filters as you type: text for names, a value list for teams, ranges such as 50000..60000 for salary, date expressions for hire dates and yes/no for remote.

입문Beginner
직접 써 보기Live preview헤더 아래 입력 칸에 치면 바로 걸러져요Type in the cells under the header to filter live

코드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="row">
      <option value="on" selected>보이기</option>
      <option value="off">숨기기</option>
    </select>
    <button type="button" id="fill">코드로 걸기: 개발팀·연봉 5000 이상</button>
  </div>
  <div id="grid" style="height: 540px"></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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
// filterRow: true면 헤더 바로 아래에 입력 칸이 한 줄 생겨요. 글자를 입력하는 즉시 걸러져요.
// 칸 종류는 컬럼 종류를 따라가요: 글자, 값 목록, 숫자 식, 날짜 식, 예/아니오.
export const options = {
  filterRow: true,
  showRowNumbers: true,
  columns: [
    {
      id: 'name',
      title: '이름',
      width: 120,
      filter: { placeholder: L('이름 일부', 'part of the name') },
    },
    { id: 'team', title: '팀', kind: 'select', width: 130 },
    {
      id: 'salary',
      title: '연봉(만원)',
      kind: 'number',
      width: 130,
      align: 'end',
      filter: { placeholder: L('예: 5000..6000', 'e.g. 5000..6000') },
    },
    {
      id: 'hired',
      title: '입사일',
      kind: 'date',
      width: 150,
      filter: { placeholder: L('예: >=2022-01-01', 'e.g. >=2022-01-01') },
    },
    { id: 'remote', title: '재택', kind: 'boolean', width: 100 },
  ],
  rows: Array.from({ length: 14 }, (_, i) => ({
    id: i + 1,
    name: names[i % 8],
    team: teams[(i * 3) % 4],
    salary: 3800 + ((i * 530) % 4200),
    hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
    remote: i % 3 === 0,
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => log({
    ko: !filterModel || filterModel.items.length === 0
      ? '필터 없음'
      : `조건 ${filterModel.items.length}개 → 보이는 행 ${api.getVisibleRowCount()}개`,
    en: !filterModel || filterModel.items.length === 0
      ? 'No filter'
      : `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`,
  }));
  return () => off();
}
export const actions = {
  // 필터 칸을 켜고 끄는 것은 옵션 하나예요. 끄면 걸려 있던 필터도 함께 지워요.
  row: (api, value) => {
    if (value === 'off')
      api.setFilterModel(null);
    api.setOptions({ filterRow: value !== 'off' });
  },
  // 코드로 걸면 칸에도 그대로 채워져요.
  fill: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'team', operator: 'in', value: ['개발팀'] },
      { columnId: 'salary', operator: 'gte', value: 5000 },
    ],
  }),
};

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="Filter row" id="row">
      <option value="on" selected>Show</option>
      <option value="off">Hide</option>
    </select>
    <button type="button" id="fill">Set in code: Dev, salary >= 50000</button>
  </div>
  <div id="grid" style="height: 540px"></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('row').addEventListener('change', (event) => actions.row(api, event.target.value));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));
example.js
const names = [
  'Liam Carter',
  'Emma Stone',
  'Noah Kim',
  'Olivia Park',
  'Ethan Brooks',
  'Sophia Lee',
  'Mason Reed',
  'Ava Morgan',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
// With filterRow: true, a row of inputs appears right under the header. Rows are filtered as you type.
// The cell type follows the column kind: text, value list, number expression, date expression, yes/no.
export const options = {
  filterRow: true,
  showRowNumbers: true,
  columns: [
    {
      id: 'name',
      title: 'Name',
      width: 140,
      filter: { placeholder: 'part of the name' },
    },
    { id: 'team', title: 'Team', kind: 'select', width: 130 },
    {
      id: 'salary',
      title: 'Salary ($)',
      kind: 'number',
      width: 140,
      align: 'end',
      filter: { placeholder: 'e.g. 50000..60000' },
    },
    {
      id: 'hired',
      title: 'Hired',
      kind: 'date',
      width: 150,
      filter: { placeholder: 'e.g. >=2022-01-01' },
    },
    { id: 'remote', title: 'Remote', kind: 'boolean', width: 100 },
  ],
  rows: Array.from({ length: 14 }, (_, i) => ({
    id: i + 1,
    name: names[i % 8],
    team: teams[(i * 3) % 4],
    salary: 38000 + ((i * 5300) % 42000),
    hired: new Date(2019 + (i % 6), (i * 5) % 12, 3 + ((i * 7) % 24)),
    remote: i % 3 === 0,
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => log(!filterModel || filterModel.items.length === 0
    ? 'No filter'
    : `${filterModel.items.length} conditions → ${api.getVisibleRowCount()} rows visible`));
  return () => off();
}
export const actions = {
  // Turning the filter cells on or off is one option. Turning them off also clears active filters.
  row: (api, value) => {
    if (value === 'off')
      api.setFilterModel(null);
    api.setOptions({ filterRow: value !== 'off' });
  },
  // Applying from code fills the cells as well.
  fill: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'team', operator: 'in', value: ['Dev'] },
      { columnId: 'salary', operator: 'gte', value: 50000 },
    ],
  }),
};