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

조건 두 개를 '그리고'·'또는'으로 묶기Combine two conditions with AND or OR

헤더의 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'(둘 다)나 '또는'(하나라도)으로 묶어요. 예를 들어 상품 이름에 '무선'이 있으면서 '이어폰'도 있는 것, 숫자는 '5만 원 이하 또는 20만 원 이상'처럼 양 끝도 고를 수 있어요.In the header funnel popup, put up to two conditions on a column and join them with AND or OR: product names with both words, or prices of $50 or less OR $200 or more.

활용Intermediate
직접 써 보기Live preview조건 두 개를 '그리고'·'또는'으로 묶기Combine two conditions with AND or OR

코드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="both">상품: 무선 그리고 이어폰</button>
    <button type="button" id="either">상품: 무선 또는 이어폰</button>
    <button type="button" id="priceEnds">가격: 5만 원 이하 또는 20만 원 이상</button>
    <button type="button" id="clear">필터 지우기</button>
  </div>
  <div id="grid" style="height: 440px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const customers = ['한빛물류', '푸른하늘식품', '북극성무역', '다온상사', '새벽농원', '모아패션'];
const products = [
  '무선 이어폰',
  '무선 키보드',
  '무선 충전기',
  '유선 이어폰',
  '블루투스 스피커',
  '노트북 거치대',
];
// filterMenu: true면 헤더 깔때기 팝업에서 한 컬럼에 조건을 두 개까지 걸고 '그리고'/'또는'으로 묶을 수 있어요.
// 이 묶음은 필터 모델의 columnMatch로 저장돼서, 다른 컬럼의 조건에는 영향을 주지 않아요.
export const options = {
  filterMenu: true,
  columns: [
    { id: 'customer', title: '고객사', width: 140 },
    { id: 'product', title: '상품', width: 170 },
    { id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
    {
      id: 'price',
      title: '가격(원)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('ko-KR'),
    },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    customer: customers[i % 6],
    product: products[(i * 5) % 6],
    quantity: 1 + ((i * 7) % 12),
    price: 19000 + ((i * 47000) % 260000),
  })),
  rowKey: 'id',
};
// 기록 창에 컬럼 id나 영문 연산자 이름이 나오지 않게 한글로 바꿔 줘요.
const TITLE = {
  customer: '고객사',
  product: '상품',
  quantity: '수량',
  price: '가격',
};
const OP_EN = {
  contains: 'contains',
  notContains: 'does not contain',
  equals: 'equals',
  notEquals: 'does not equal',
  startsWith: 'starts with',
  endsWith: 'ends with',
  gt: 'greater than',
  gte: 'at least',
  lt: 'less than',
  lte: 'at most',
  between: 'between',
  in: 'one of',
  isEmpty: 'is empty',
  isNotEmpty: 'is not empty',
};
const OP = {
  contains: '포함',
  notContains: '포함하지 않음',
  equals: '같음',
  notEquals: '같지 않음',
  startsWith: '시작',
  endsWith: '끝',
  gt: '초과',
  gte: '이상',
  lt: '미만',
  lte: '이하',
  between: '사이',
  in: '선택값',
  isEmpty: '비어 있음',
  isNotEmpty: '비어 있지 않음',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => {
    // 컬럼마다 입력한 값까지 적어요. 예: 상품: '무선' 포함 그리고 '이어폰' 포함
    const byColumn = new Map();
    for (const i of filterModel?.items ?? []) {
      const value = typeof i.value === 'number' ? i.value.toLocaleString('ko-KR') : `'${String(i.value)}'`;
      const text = [
        `${value} ${OP[i.operator] ?? i.operator}`,
        `${value} ${OP_EN[i.operator] ?? i.operator}`,
      ];
      byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
    }
    const parts = [...byColumn].map(([id, texts]) => {
      const any = filterModel?.columnMatch?.[id] === 'any';
      return {
        ko: `${TITLE[id] ?? id}: ${texts.map((t) => t[0]).join(any ? ' 또는 ' : ' 그리고 ')}`,
        en: `${TITLE[id] ?? id}: ${texts.map((t) => t[1]).join(any ? ' or ' : ' and ')}`,
      };
    });
    const rows = api.getVisibleRowCount();
    log(parts.length === 0
      ? { ko: `필터 없음 · ${rows}행`, en: `No filter · ${rows} rows` }
      : {
        ko: `${parts.map((p) => p.ko).join(' / ')} → ${rows}행`,
        en: `${parts.map((p) => p.en).join(' / ')} → ${rows} rows`,
      });
  });
  return () => off();
}
export const actions = {
  // 코드로도 같은 모양을 걸 수 있어요. 걸고 나서 '상품' 헤더의 깔때기를 열어 보면 팝업에 그대로 채워져 있어요.
  both: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'product', operator: 'contains', value: '무선' },
      { columnId: 'product', operator: 'contains', value: '이어폰' },
    ],
    columnMatch: { product: 'all' },
  }),
  either: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'product', operator: 'contains', value: '무선' },
      { columnId: 'product', operator: 'contains', value: '이어폰' },
    ],
    columnMatch: { product: 'any' },
  }),
  // 숫자도 같은 방식: 5만 원 이하 또는 20만 원 이상
  priceEnds: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'price', operator: 'lte', value: 50000 },
      { columnId: 'price', operator: 'gte', value: 200000 },
    ],
    columnMatch: { price: 'any' },
  }),
  clear: (api) => api.setFilterModel(null),
};

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="both">Product: Wireless AND Earbuds</button>
    <button type="button" id="either">Product: Wireless OR Earbuds</button>
    <button type="button" id="priceEnds">Price: ≤$50 or ≥$200</button>
    <button type="button" id="clear">Clear filter</button>
  </div>
  <div id="grid" style="height: 440px"></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('both').addEventListener('click', () => actions.both(api));
document.getElementById('either').addEventListener('click', () => actions.either(api));
document.getElementById('priceEnds').addEventListener('click', () => actions.priceEnds(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const customers = [
  'Harbor Logistics',
  'Bluesky Foods',
  'Polaris Trading',
  'Evergreen Supply',
  'Dawn Farms',
  'Mode Fashion',
];
const products = [
  'Wireless Earbuds',
  'Wireless Keyboard',
  'Wireless Charger',
  'Wired Earbuds',
  'Bluetooth Speaker',
  'Laptop Stand',
];
// With filterMenu: true, the header funnel popup lets you put up to two conditions on one column and join them with AND / OR.
// The join is stored as columnMatch in the filter model and does not affect the conditions of other columns.
export const options = {
  filterMenu: true,
  columns: [
    { id: 'customer', title: 'Customer', width: 160 },
    { id: 'product', title: 'Product', width: 170 },
    { id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
    {
      id: 'price',
      title: 'Price ($)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => `$${Number(value).toLocaleString('en-US')}`,
    },
  ],
  rows: Array.from({ length: 12 }, (_, i) => ({
    id: i + 1,
    customer: customers[i % 6],
    product: products[(i * 5) % 6],
    quantity: 1 + ((i * 7) % 12),
    price: 19 + ((i * 47) % 260),
  })),
  rowKey: 'id',
};
// Show readable column titles and operator names in the log instead of column ids.
const TITLE = {
  customer: 'Customer',
  product: 'Product',
  quantity: 'Qty',
  price: 'Price',
};
const OP = {
  contains: 'contains',
  notContains: 'does not contain',
  equals: 'equals',
  notEquals: 'does not equal',
  startsWith: 'starts with',
  endsWith: 'ends with',
  gt: 'greater than',
  gte: 'at least',
  lt: 'less than',
  lte: 'at most',
  between: 'between',
  in: 'one of',
  isEmpty: 'is empty',
  isNotEmpty: 'is not empty',
};
export function setup(api, log) {
  const off = api.on('filterChanged', ({ filterModel }) => {
    // Include the value entered for each column. Example: Product: 'Wireless' contains and 'Earbuds' contains
    const byColumn = new Map();
    for (const i of filterModel?.items ?? []) {
      const value = typeof i.value === 'number' ? i.value.toLocaleString('en-US') : `'${String(i.value)}'`;
      const text = `${value} ${OP[i.operator] ?? i.operator}`;
      byColumn.set(i.columnId, [...(byColumn.get(i.columnId) ?? []), text]);
    }
    const parts = [...byColumn].map(([id, texts]) => {
      const any = filterModel?.columnMatch?.[id] === 'any';
      return `${TITLE[id] ?? id}: ${texts.join(any ? ' or ' : ' and ')}`;
    });
    const rows = api.getVisibleRowCount();
    log(parts.length === 0 ? `No filter · ${rows} rows` : `${parts.join(' / ')} → ${rows} rows`);
  });
  return () => off();
}
export const actions = {
  // The same shape can be applied from code. After applying, open the Product funnel and the popup is filled in as is.
  both: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'product', operator: 'contains', value: 'Wireless' },
      { columnId: 'product', operator: 'contains', value: 'Earbuds' },
    ],
    columnMatch: { product: 'all' },
  }),
  either: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'product', operator: 'contains', value: 'Wireless' },
      { columnId: 'product', operator: 'contains', value: 'Earbuds' },
    ],
    columnMatch: { product: 'any' },
  }),
  // Numbers work the same way: $50 or less OR $200 or more
  priceEnds: (api) => api.setFilterModel({
    match: 'all',
    items: [
      { columnId: 'price', operator: 'lte', value: 50 },
      { columnId: 'price', operator: 'gte', value: 200 },
    ],
    columnMatch: { price: 'any' },
  }),
  clear: (api) => api.setFilterModel(null),
};