필터
텍스트·숫자·날짜·값 목록 필터: 포함하지 않음, 다음 중 하나, 패턴, 정규식, 초성 검색, 이번 달 같은 상대 날짜, 달력, 필터 행, 빠른 검색.
실행 예제필터
텍스트·숫자·날짜·값 목록 필터와 빠른 검색으로 원하는 행만 골라냅니다.
이 데모의 코드
import { createGrid } from '@freegridjs/core';
import { demoColumns, makeRows } from '../data';
import { button, search, separator, text, tr, type DemoContext } from '../ui';
export default function mount(ctx: DemoContext) {
const { lang } = ctx;
const grid = createGrid(ctx.host, { columns: demoColumns(lang), data: makeRows(20_000), locale: lang, filterRow: true });
const count = text(ctx, '');
const update = () => (count.textContent = tr(lang, {
en: `${grid.getDisplayedRowCount().toLocaleString()} of 20,000 rows`,
ko: `20,000행 중 ${grid.getDisplayedRowCount().toLocaleString()}행`,
}));
grid.on('filterChange', e => {
ctx.log(`filterChange → ${JSON.stringify(e.filters)}`);
update();
});
search(ctx, tr(lang, { en: 'Quick search, e.g. kim -japan', ko: '빠른 검색 예: kim -japan' }), q => {
grid.setQuickFilter(q);
update();
});
separator(ctx);
button(ctx, tr(lang, { en: 'Q1 ≥ 80,000', ko: '1분기 ≥ 80,000' }), () => grid.setFilter('q1', { type: 'number', op: 'gte', value: 80000 }));
button(ctx, tr(lang, { en: 'Joined in 2024', ko: '2024년 가입' }), () =>
grid.setFilter('joined', { type: 'date', op: 'between', value: '2024-01-01', valueTo: '2024-12-31' }));
button(ctx, tr(lang, { en: 'Japan or Korea', ko: '일본 또는 한국' }), () =>
grid.setFilter('country', { type: 'set', values: ['Japan', 'South Korea'] }));
button(ctx, tr(lang, { en: 'Joined in the last 2 years', ko: '최근 2년 가입' }), () =>
grid.setFilter('joined', { type: 'date', op: 'lastDays', days: 730 }));
button(ctx, tr(lang, { en: 'Name not containing "an"', ko: '이름에 "an" 없음' }), () =>
grid.setFilter('name', { type: 'text', op: 'notContains', value: 'an' }));
button(ctx, tr(lang, { en: 'Email *[email protected]', ko: '이메일 *[email protected]' }), () =>
grid.setFilter('email', { type: 'text', op: 'like', value: '*[email protected]' }));
button(ctx, tr(lang, { en: 'Clear filters', ko: '필터 모두 해제' }), () => {
for (const id of Object.keys(grid.getFilterModel())) grid.setFilter(id, null);
});
update();
return grid;
}컬럼의 ⋮ 메뉴에 타입별 필터가 있습니다. 텍스트(포함, 포함하지 않음, 같음, 시작/끝 문자, 다음 중 하나, 패턴 일치, 정규식, 빈 값…), 숫자(=, ≠, <, ≤, >, ≥, 범위, 빈 값), 날짜(같음, 이전, 이후, 범위, 이번 달·최근 7일 같은 상대 날짜), 값 목록(컬럼 값을 검색해 체크) 필터입니다. 텍스트는 대소문자를 구분하지 않습니다. 필터가 걸린 컬럼에는 채워진 필터 아이콘이 표시됩니다.
grid.setFilter('name', { type: 'text', op: 'contains', value: 'kim' });
grid.setFilter('total', { type: 'number', op: 'between', value: 1000, valueTo: 5000 });
grid.setFilter('joined', { type: 'date', op: 'after', value: '2025-01-01' });
grid.setFilter('country', { type: 'set', values: ['Japan', 'South Korea'] });
grid.setFilter('name', null); // clear one
grid.setQuickFilter('kim seoul'); // every word must match some visible column
grid.on('filterChange', e => console.log(e.filters));컬럼 메뉴에서는 "10 이상 그리고 100 이하"처럼 조건을 두 개까지 걸어 "그리고/또는"으로 묶을 수 있습니다. 코드에서는 combined 모델로 씁니다. 필터가 바뀔 때마다 filterChange가 오고, 그 전에 오는 beforeFilter에서 취소할 수도 있습니다(예: 서버에서 걸러야 할 때). 여러 컬럼에 걸친 조건은 고급 필터를 보세요.
// two conditions on one column, joined with and / or
grid.setFilter('qty', { type: 'combined', operator: 'and',
conditions: [{ type: 'number', op: 'gte', value: 10 }, { type: 'number', op: 'lte', value: 100 }] });
grid.getFilterModel(); // { qty: { type: 'combined', … } }
grid.on('beforeFilter', e => { if (e.colId === 'secret') e.cancel(); });다양한 검색 방법
컬럼 메뉴 말고도 텍스트 연산, 상대 날짜, 필터 행에 입력하는 조건, 편집기에 맞춘 목록, 한글 초성, 빠른 검색으로 행을 찾을 수 있습니다. 각각 페이지가 따로 있습니다.
필터 행
filterRow: true를 켜면 헤더 바로 아래에 컬럼마다 입력칸이 생기고, 입력하는 대로 걸러집니다(0.2초 뒤 적용, Enter는 즉시 적용, Esc는 지우기). 컬럼 타입에 맞춰 아래처럼 씁니다. 알아볼 수 없는 값은 칸이 빨갛게 표시되고 필터는 그대로 둡니다.
| 컬럼 | 입력 예 | 뜻 |
|---|---|---|
| 텍스트 | kim · ㄱㅎ | "kim"이 들어간 값 (대소문자 무시), 초성으로도 찾음 |
| 텍스트 더 | =서울 · !테스트 · 서울 | 부산 · 김* · /^A\d+$/ | 정확히 같음, 포함하지 않음, 둘 중 하나, 패턴(* ?), 정규식 |
| 숫자 | 15 · >10 · >=10 · <5 · <=5 · <>3 | 같음, 초과, 이상, 미만, 이하, 같지 않음 (1,000·₩도 읽음) |
| 숫자 범위 | 10~20 · 10..20 | 10 이상 20 이하 |
| 날짜 | 2026-03-05 · >2026-01-01 · <2026-12-31 | 그날, 이후, 이전 (2026.3.5처럼 점이나 빗금도 됨) |
| 날짜 범위 | 2026-01-01~2026-03-31 | 두 날짜 사이 (양 끝 포함) |
| 날짜 달력 | 칸 안의 달력 버튼 | 오늘·이번 주·이번 달·최근 7일 같은 상대 날짜, 또는 두 번 눌러 기간 선택. 칸에는 이번 달처럼 고른 이름이 보임 |
| 값 목록·참/거짓 | 선택 상자 | filter: 'set', boolean 컬럼, 옵션 편집기(select·라디오·여러 값 선택·스위치) 컬럼은 값 중 하나를 옵션 이름으로 고름 |
필터 행과 컬럼 메뉴, setFilter()는 같은 필터를 씁니다. 한쪽에서 바꾸면 다른 쪽에도 그대로 보입니다. 컬럼 메뉴에서 목록 값을 여러 개 고르면 필터 행 목록에는 (2개 선택됨)처럼 표시됩니다. 입력칸이 필요 없는 컬럼은 filter: false로 빼세요. 실시간 업데이트로 행이 바뀌어도 입력 중인 내용은 유지됩니다.
const grid = createGrid(el, {
columns: [
{ field: 'name', header: 'Name' }, // text: contains
{ field: 'qty', header: 'Qty', type: 'number' }, // >10, <=5, 10~20
{ field: 'joined', header: 'Joined', type: 'date' }, // >2026-01-01, 2026-01-01~2026-03-31
{ field: 'status', header: 'Status', filter: 'set' }, // a list of the column's values
{ field: 'memo', header: 'Memo', filter: false }, // no box
],
data,
filterRow: true,
});
// the boxes and the column menu share one filter: setting one updates the other
grid.setFilter('qty', { type: 'number', op: 'between', value: 10, valueTo: 20 }); // the box shows 10~20이 페이지에 대한 질문
어떤 필터가 있나요?
컬럼 메뉴의 텍스트·숫자·날짜·값 목록 필터(컬럼마다 조건 두 개까지), 헤더 아래 필터 행, 빠른 검색이 있습니다.