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

헤더 아래 칸에서 바로 걸러 보기Filter right under the header

컬럼마다 필터 칸이 있어서 값 목록에서 체크하거나, 숫자 식(>=50000)을 입력하면 바로 걸러져요. 여러 컬럼에 걸면 모두 만족하는 행만 남고, 비어 있는 값만 골라 볼 수도 있어요.Every column has a filter cell: tick values from a list or type a number expression such as >=50. Filters on several columns combine, and you can pick only empty values.

입문Beginner
직접 써 보기Live preview헤더 아래 칸에서 바로 걸러 보기Filter right under the header

코드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">
    <button type="button" id="twoNames">김민준·이서연만</button>
    <button type="button" id="nameAndRegion">이서연·박지호이면서 서울</button>
    <button type="button" id="emptyRegion">지역이 빈 행만</button>
    <button type="button" id="sortByPrice">가격 높은 순 정렬</button>
    <button type="button" id="clear">필터·정렬 지우기</button>
  </div>
  <div id="grid" style="height: 640px"></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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const customers = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈'];
const regions = ['서울', '부산', '대구', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// filterRow: true면 헤더 아래에 필터 칸이 생겨요. 칸 종류는 컬럼 종류를 따라가요.
//  - kind: 'select' → 값 목록(체크박스), kind: 'number' → 숫자 식, 그 밖에는 글자 입력
// 값이 비어 있는 행은 목록에 "(비어 있음)"으로 나와서 비어 있는 것만 골라 볼 수도 있어요.
export const options = {
  filterRow: true,
  columns: [
    { id: 'customer', title: '고객명', kind: 'select', width: 130 },
    { id: 'region', title: '지역', kind: 'select', width: 110 },
    { id: 'product', title: '상품', kind: 'select', width: 170 },
    { id: 'quantity', title: '수량', kind: 'number', width: 100, align: 'end' },
    {
      id: 'price',
      title: '가격(원)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('ko-KR'),
      filter: { placeholder: L('예: >=50000', 'e.g. >=50000') },
    },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    // 일부러 비워 둔 칸: 3번째마다 고객명, 5번째마다 지역
    customer: i % 7 === 6 ? null : customers[i % 7],
    region: i % 5 === 4 ? null : regions[(i * 3) % 4],
    product: products[(i * 2) % 5],
    quantity: 1 + ((i * 7) % 15),
    price: 29000 + ((i * 53000) % 480000),
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => log({
    ko: filterModel === null || filterModel.items.length === 0
      ? '필터 없음: 모든 행이 보여요'
      : `필터 ${filterModel.items.length}개 적용 → 보이는 행 ${api.getVisibleRowCount()}개`,
    en: filterModel === null || filterModel.items.length === 0
      ? 'No filter: all rows are visible'
      : `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`,
  }));
  return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
  // 코드에서 필터 걸기: 고객명이 김민준 또는 이서연인 행만
  twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['김민준', '이서연'] }]),
  // 두 컬럼을 함께(AND): 이서연이면서 지역이 서울
  nameAndRegion: (api) => show(api, [
    { columnId: 'customer', operator: 'in', value: ['이서연', '박지호'] },
    { columnId: 'region', operator: 'in', value: ['서울'] },
  ]),
  // 값이 비어 있는 행만
  emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
  // 정렬과 필터는 함께 쓸 수 있어요: 가격 높은 순으로 보면서 필터
  sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
  clear: (api) => {
    api.setFilterModel(null);
    api.setSortModel([]);
  },
};

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">
    <button type="button" id="twoNames">Two customers only</button>
    <button type="button" id="nameAndRegion">Two names and Seoul</button>
    <button type="button" id="emptyRegion">Empty region only</button>
    <button type="button" id="sortByPrice">Sort by price</button>
    <button type="button" id="clear">Clear filter and sort</button>
  </div>
  <div id="grid" style="height: 640px"></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('twoNames').addEventListener('click', () => actions.twoNames(api));
document.getElementById('nameAndRegion').addEventListener('click', () => actions.nameAndRegion(api));
document.getElementById('emptyRegion').addEventListener('click', () => actions.emptyRegion(api));
document.getElementById('sortByPrice').addEventListener('click', () => actions.sortByPrice(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const customers = [
  'Liam Carter',
  'Emma Stone',
  'Noah Kim',
  'Olivia Park',
  'Ethan Brooks',
  'Sophia Lee',
  'Mason Reed',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle'];
const products = [
  'Wireless Earbuds',
  'Smart Watch',
  'Laptop Stand',
  'Power Bank',
  'Bluetooth Speaker',
];
// With filterRow: true, a filter cell appears under the header. The cell type follows the column kind.
//  - kind: 'select' -> value list (checkboxes), kind: 'number' -> number expression, otherwise text input
// Rows with empty values show up as "(Empty)" in the list, so you can pick only the empty ones.
export const options = {
  filterRow: true,
  columns: [
    { id: 'customer', title: 'Customer', kind: 'select', width: 140 },
    { id: 'region', title: 'Region', kind: 'select', width: 120 },
    { id: 'product', title: 'Product', kind: 'select', width: 170 },
    { id: 'quantity', title: 'Qty', kind: 'number', width: 100, align: 'end' },
    {
      id: 'price',
      title: 'Price ($)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
      filter: { placeholder: 'e.g. >=50' },
    },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    // Deliberately empty cells: customer on every 7th row, region on every 5th
    customer: i % 7 === 6 ? null : customers[i % 7],
    region: i % 5 === 4 ? null : regions[(i * 3) % 4],
    product: products[(i * 2) % 5],
    quantity: 1 + ((i * 7) % 15),
    price: 29 + ((i * 53) % 480),
  })),
  rowKey: 'id',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => log(filterModel === null || filterModel.items.length === 0
    ? 'No filter: all rows are visible'
    : `${filterModel.items.length} filters applied → ${api.getVisibleRowCount()} rows visible`));
  return () => off();
}
const show = (api, items) => api.setFilterModel(items.length ? { match: 'all', items } : null);
export const actions = {
  // Apply a filter from code: only rows whose customer is Liam Carter or Emma Stone
  twoNames: (api) => show(api, [{ columnId: 'customer', operator: 'in', value: ['Liam Carter', 'Emma Stone'] }]),
  // Two columns together (AND): Emma Stone or Noah Kim, and region New York
  nameAndRegion: (api) => show(api, [
    { columnId: 'customer', operator: 'in', value: ['Emma Stone', 'Noah Kim'] },
    { columnId: 'region', operator: 'in', value: ['New York'] },
  ]),
  // Only rows with an empty value
  emptyRegion: (api) => show(api, [{ columnId: 'region', operator: 'isEmpty' }]),
  // Sorting and filtering can be combined: filter while viewing by price, highest first
  sortByPrice: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
  clear: (api) => {
    api.setFilterModel(null);
    api.setSortModel([]);
  },
};