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

필터가 보는 값 바꾸기Change the value the filter sees

filterValue로 필터와 값 목록이 월 같은 다른 값을 보게 하고, valueKey로 객체 값을 id로 묶어요. 표시와 정렬은 그대로 getValue예요.filterValue makes the filter and the value list see another value, such as the month, and valueKey groups object values by id. Display and sort keep using getValue.

활용Intermediate
직접 써 보기Live preview필터가 보는 값 바꾸기Change the value the filter sees

코드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="feb">2월만</button>
    <button type="button" id="kim">김 담당만</button>
    <button type="button" id="clear">필터 지우기</button>
  </div>
  <div id="grid" style="height: 300px"></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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const kim = { id: 1, label: '김 팀장' };
const lee = { id: 2, label: '이 대리' };
const rows = [
  { id: 1, name: '김서연', hired: new Date(2026, 0, 12), owner: { ...kim } },
  { id: 2, name: '이준호', hired: new Date(2026, 1, 3), owner: { ...lee } },
  { id: 3, name: '박민지', hired: new Date(2026, 1, 20), owner: { ...kim } },
  { id: 4, name: '최하늘', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue는 필터와 값 목록이 보는 값이에요(표시와 정렬은 getValue 그대로). valueKey는 객체 값을 같은 값으로 묶는 열쇠예요.
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 110 },
    {
      id: 'hired',
      title: '입사 월',
      kind: 'date',
      width: 130,
      filter: { type: 'set' },
      filterValue: ({ value }) => `${value.getMonth() + 1}월`,
    },
    {
      id: 'owner',
      title: '담당',
      width: 130,
      filter: { type: 'set' },
      valueKey: (value) => `u${value.id}`,
      formatValue: (value) => value.label,
    },
  ],
  rows,
  rowKey: 'id',
  filterMenu: true,
  filterRow: false,
};
let say = () => undefined;
export function setup(grid, log) {
  say = log;
  return grid.on('filterChanged', () => log({
    ko: `보이는 행 ${grid.getVisibleRowCount()}개`,
    en: `${grid.getVisibleRowCount()} rows visible`,
  }));
}
export const actions = {
  feb: (grid) => grid.setFilterModel({
    match: 'all',
    items: [{ columnId: 'hired', operator: 'in', value: ['2월'] }],
  }),
  kim: (grid) => {
    grid.setFilterModel({
      match: 'all',
      items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
    });
    say({ ko: '담당 열쇠 u1로 걸었어요.', en: 'Filtered by the owner key u1.' });
  },
  clear: (grid) => grid.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="feb">Only February</button>
    <button type="button" id="kim">Only Kim</button>
    <button type="button" id="clear">Clear filter</button>
  </div>
  <div id="grid" style="height: 300px"></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('feb').addEventListener('click', () => actions.feb(api));
document.getElementById('kim').addEventListener('click', () => actions.kim(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const kim = { id: 1, label: 'Kim (Lead)' };
const lee = { id: 2, label: 'Lee (Associate)' };
const rows = [
  { id: 1, name: 'Emma Stone', hired: new Date(2026, 0, 12), owner: { ...kim } },
  { id: 2, name: 'Noah Kim', hired: new Date(2026, 1, 3), owner: { ...lee } },
  { id: 3, name: 'Olivia Park', hired: new Date(2026, 1, 20), owner: { ...kim } },
  { id: 4, name: 'Ethan Brooks', hired: new Date(2026, 2, 8), owner: { ...lee } },
];
// filterValue is the value the filter and value list see (display and sorting still use getValue). valueKey is the key that groups object values into the same value.
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 130 },
    {
      id: 'hired',
      title: 'Hired month',
      kind: 'date',
      width: 160,
      filter: { type: 'set' },
      filterValue: ({ value }) => MONTHS[value.getMonth()],
    },
    {
      id: 'owner',
      title: 'Owner',
      width: 150,
      filter: { type: 'set' },
      valueKey: (value) => `u${value.id}`,
      formatValue: (value) => value.label,
    },
  ],
  rows,
  rowKey: 'id',
  filterMenu: true,
  filterRow: false,
};
let say = () => undefined;
export function setup(grid, log) {
  say = log;
  return grid.on('filterChanged', () => log(`${grid.getVisibleRowCount()} rows visible`));
}
export const actions = {
  feb: (grid) => grid.setFilterModel({
    match: 'all',
    items: [{ columnId: 'hired', operator: 'in', value: ['Feb'] }],
  }),
  kim: (grid) => {
    grid.setFilterModel({
      match: 'all',
      items: [{ columnId: 'owner', operator: 'in', value: ['u1'] }],
    });
    say('Filtered by the owner key u1.');
  },
  clear: (grid) => grid.setFilterModel(null),
};