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

필터 없이 행 숨기기Hide rows without a filter

hideRows(keys)는 고른 행을 보기에서 빼고 showRows()로 되돌려요. 필터와 따로 움직여서 필터를 걸고 풀어도 숨김은 그대로예요. 숨긴 행은 getRows()에 남고 변경으로 세지 않아요.hideRows(keys) takes chosen rows out of the view and showRows() brings them back. It moves independently of the filter, so setting or clearing a filter does not change what is hidden. Hidden rows stay in getRows() and are not counted as changes.

입문Beginner
직접 써 보기Live preview필터 없이 행 숨기기Hide rows without a filter

코드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="hideSelected">고른 줄 숨기기</button>
    <button type="button" id="showAll">모두 보이기</button>
    <button type="button" id="filter">70점 초과만</button>
    <button type="button" id="clearFilter">필터 풀기</button>
  </div>
  <div id="grid" style="height: 420px"></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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
const names = en
  ? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper', 'Indy', 'Jordan']
  : [
    '김서연',
    '이준호',
    '박민지',
    '최도윤',
    '정하은',
    '한지우',
    '오세훈',
    '윤아름',
    '강태양',
    '서하늘',
  ];
const teams = en ? ['Dev', 'Design', 'Ops'] : ['개발', '디자인', '운영'];
export const options = {
  columns: [
    { id: 'name', title: en ? 'Name' : '이름', width: 120, sortable: true },
    { id: 'team', title: en ? 'Team' : '팀', width: 100, sortable: true },
    { id: 'score', title: en ? 'Score' : '점수', kind: 'number', width: 90, sortable: true },
  ],
  rows: names.map((name, i) => ({
    id: i + 1,
    name,
    team: teams[i % 3],
    score: 50 + ((i * 9) % 50),
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
  say = log;
  // 숨기거나 보일 때마다 실제로 바뀐 키가 한 번에 와요.
  const off = api.on('rowsHiddenChanged', (e) => say({
    ko: `${e.hidden ? '숨김' : '보임'}: ${e.keys.join(', ')}`,
    en: `${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`,
  }));
  return off;
}
export const actions = {
  // 고른 줄을 숨겨요. 필터가 아니라서 isRowHidden으로 읽고 showRows로 되돌려요.
  hideSelected: (api) => {
    const keys = api.getSelectedKeys();
    if (keys.length === 0)
      return say({ ko: '먼저 줄을 골라 보세요', en: 'Select rows first' });
    api.hideRows([...keys]);
  },
  showAll: (api) => api.showRows(),
  filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
  clearFilter: (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="hideSelected">Hide selected</button>
    <button type="button" id="showAll">Show all</button>
    <button type="button" id="filter">Score above 70</button>
    <button type="button" id="clearFilter">Clear filter</button>
  </div>
  <div id="grid" style="height: 420px"></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('hideSelected').addEventListener('click', () => actions.hideSelected(api));
document.getElementById('showAll').addEventListener('click', () => actions.showAll(api));
document.getElementById('filter').addEventListener('click', () => actions.filter(api));
document.getElementById('clearFilter').addEventListener('click', () => actions.clearFilter(api));
example.js
const names = [
  'Alex',
  'Blair',
  'Casey',
  'Drew',
  'Emery',
  'Finn',
  'Gray',
  'Harper',
  'Indy',
  'Jordan',
];
const teams = ['Dev', 'Design', 'Ops'];
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 120, sortable: true },
    { id: 'team', title: 'Team', width: 100, sortable: true },
    { id: 'score', title: 'Score', kind: 'number', width: 90, sortable: true },
  ],
  rows: names.map((name, i) => ({
    id: i + 1,
    name,
    team: teams[i % 3],
    score: 50 + ((i * 9) % 50),
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
  say = log;
  // Each time rows are hidden or shown, the keys that actually changed arrive at once.
  const off = api.on('rowsHiddenChanged', (e) => say(`${e.hidden ? 'Hidden' : 'Shown'}: ${e.keys.join(', ')}`));
  return off;
}
export const actions = {
  // Hides the selected rows. This is not a filter, so read it with isRowHidden and restore it with showRows.
  hideSelected: (api) => {
    const keys = api.getSelectedKeys();
    if (keys.length === 0)
      return say('Select rows first');
    api.hideRows([...keys]);
  },
  showAll: (api) => api.showRows(),
  filter: (api) => api.setFilterModel({ match: 'all', items: [{ columnId: 'score', operator: 'gt', value: 70 }] }),
  clearFilter: (api) => api.setFilterModel(null),
};