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

상태 목록에서 고르고 빈 메모 찾기Pick a status and find empty notes

정해진 값 중에서 고르는 필터와 '비어 있음 / 값 있음' 필터를 함께 쓸 수 있어요. 두 조건은 둘 다 만족하는 행만 남겨요.Combine a pick-from-list filter with an empty or filled check. Both conditions must hold for a row to stay.

입문Beginner
직접 써 보기Live preview상태 목록에서 고르고 빈 메모 찾기Pick a status and find empty notes

코드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="status">
      <option value="all" selected>전체</option>
      <option value="running">진행</option>
      <option value="done">완료</option>
      <option value="hold">보류</option>
    </select>
    <select aria-label="메모" id="memo">
      <option value="any" selected>상관없음</option>
      <option value="empty">비어 있음</option>
      <option value="filled">값 있음</option>
    </select>
  </div>
  <div id="grid" style="height: 560px"></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('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('memo').addEventListener('change', (event) => actions.memo(api, event.target.value));
example.js
const tasks = [
  '견적서 발송',
  '계약서 검토',
  '세금계산서 발행',
  '샘플 배송',
  '시연 일정 조율',
  '교육 자료 정리',
  '고객 불만 접수',
  '재고 확인',
];
const statuses = ['진행', '완료', '보류'];
const memos = ['고객 회신 대기', null, '내일 오전 처리', null, '담당자 휴가', null];
export const options = {
  columns: [
    { id: 'task', title: '업무', width: 170 },
    { id: 'status', title: '상태', width: 90 },
    {
      id: 'memo',
      title: '메모',
      width: 190,
      formatValue: (value) => (value == null || value === '' ? '' : String(value)),
    },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    task: tasks[i % 8],
    status: statuses[(i * 5) % 3],
    memo: memos[i % 6] ?? null,
  })),
  rowKey: 'id',
};
// 상태는 정해진 값 중에서 고르고('in'), 메모는 비어 있는지만 본다('isEmpty' / 'isNotEmpty').
// 두 조건은 함께 걸려요(둘 다 만족하는 행만 남아요).
const pick = { status: 'all', memo: 'any' };
function apply(api) {
  const items = [];
  if (pick.status !== 'all')
    items.push({ columnId: 'status', operator: 'in', value: [pick.status] });
  if (pick.memo === 'empty')
    items.push({ columnId: 'memo', operator: 'isEmpty' });
  if (pick.memo === 'filled')
    items.push({ columnId: 'memo', operator: 'isNotEmpty' });
  api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api, log) {
  pick.status = 'all';
  pick.memo = 'any';
  const off = api.on('filterChanged', () => log({
    ko: `보이는 행 ${api.getVisibleRowCount()} / 전체 ${api.getRowCount()}`,
    en: `Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`,
  }));
  return () => off();
}
// 조작 칸의 값은 언어와 상관없는 키라서, 키를 표의 값으로 바꿔 써요.
const STATUS_BY_KEY = { running: '진행', done: '완료', hold: '보류' };
export const actions = {
  status: (api, value) => {
    pick.status = value && value !== 'all' ? (STATUS_BY_KEY[value] ?? 'all') : 'all';
    apply(api);
  },
  memo: (api, value) => {
    pick.memo = value ?? 'any';
    apply(api);
  },
};

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="Status" id="status">
      <option value="all" selected>All</option>
      <option value="running">In progress</option>
      <option value="done">Done</option>
      <option value="hold">On hold</option>
    </select>
    <select aria-label="Note" id="memo">
      <option value="any" selected>Any</option>
      <option value="empty">Empty</option>
      <option value="filled">Filled</option>
    </select>
  </div>
  <div id="grid" style="height: 560px"></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('status').addEventListener('change', (event) => actions.status(api, event.target.value));
document.getElementById('memo').addEventListener('change', (event) => actions.memo(api, event.target.value));
example.js
const tasks = [
  'Send quote',
  'Review contract',
  'Issue invoice',
  'Ship sample',
  'Schedule demo',
  'Organize training material',
  'Log customer complaint',
  'Check inventory',
];
const statuses = ['In progress', 'Done', 'On hold'];
const memos = [
  'Waiting for customer reply',
  null,
  'Handle tomorrow morning',
  null,
  'Owner on vacation',
  null,
];
export const options = {
  columns: [
    { id: 'task', title: 'Task', width: 200 },
    { id: 'status', title: 'Status', width: 110 },
    {
      id: 'memo',
      title: 'Notes',
      width: 210,
      formatValue: (value) => (value == null || value === '' ? '' : String(value)),
    },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    task: tasks[i % 8],
    status: statuses[(i * 5) % 3],
    memo: memos[i % 6] ?? null,
  })),
  rowKey: 'id',
};
// Status is chosen from fixed values ('in'), and notes are only checked for being empty ('isEmpty' / 'isNotEmpty').
// Both conditions apply together (only rows that satisfy both stay).
const pick = { status: 'all', memo: 'any' };
function apply(api) {
  const items = [];
  if (pick.status !== 'all')
    items.push({ columnId: 'status', operator: 'in', value: [pick.status] });
  if (pick.memo === 'empty')
    items.push({ columnId: 'memo', operator: 'isEmpty' });
  if (pick.memo === 'filled')
    items.push({ columnId: 'memo', operator: 'isNotEmpty' });
  api.setFilterModel(items.length ? { match: 'all', items } : null);
}
export function setup(api, log) {
  pick.status = 'all';
  pick.memo = 'any';
  const off = api.on('filterChanged', () => log(`Visible rows ${api.getVisibleRowCount()} / total ${api.getRowCount()}`));
  return () => off();
}
// The control values are language-neutral keys; map them to the values in the table.
const STATUS_BY_KEY = {
  running: 'In progress',
  done: 'Done',
  hold: 'On hold',
};
export const actions = {
  status: (api, value) => {
    pick.status = value && value !== 'all' ? (STATUS_BY_KEY[value] ?? 'all') : 'all';
    apply(api);
  },
  memo: (api, value) => {
    pick.memo = value ?? 'any';
    apply(api);
  },
};