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

전체 선택의 범위와 칸 선택Select all scopes and cell selection

selectAllRows의 범위(visible, page, filtered, all)에 따라 선택되는 행이 달라지고, selectAllCells와 selectColumnCells로 칸을 한꺼번에 골라요. 페이징과 필터가 있을 때 차이가 드러나요.selectAllRows selects different rows depending on the scope (visible, page, filtered, all), and selectAllCells and selectColumnCells pick cells in bulk. The difference shows with paging and a filter.

활용Intermediate
직접 써 보기Live preview전체 선택의 범위와 칸 선택Select all scopes and cell selection

코드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="visible">visible</button>
    <button type="button" id="page">page</button>
    <button type="button" id="filtered">filtered</button>
    <button type="button" id="all">all</button>
    <button type="button" id="cells">칸 전체 선택</button>
    <button type="button" id="column">이름 열 칸 선택</button>
    <button type="button" id="clear">모두 풀기</button>
  </div>
  <div id="grid" style="height: 260px"></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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
export const options = {
  columns: [
    { id: 'team', title: '팀', width: 90 },
    { id: 'name', title: '이름', width: 110 },
  ],
  rows: Array.from({ length: 24 }, (_, i) => ({
    id: i + 1,
    team: ['개발', '디자인', '영업'][i % 3],
    name: names[i % 6],
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  cellSelection: 'multiple',
  pagination: { mode: 'client', pageSize: 5 },
  filterRow: true,
};
let say = () => { };
export function setup(api, log) {
  say = log;
  const off = api.on('selectionChanged', ({ selectedKeys }) => log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }));
  api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
  log({
    ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
    en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
  });
  return () => off();
}
const scope = (name, ko, en) => (api) => {
  api.deselectAllRows();
  api.selectAllRows({ scope: name });
  say({
    ko: `${ko}: ${api.getSelectedKeys().length}행`,
    en: `${en}: ${api.getSelectedKeys().length} rows`,
  });
};
export const actions = {
  visible: scope('visible', 'visible(헤더 체크박스와 같아요)', 'visible (same as the header checkbox)'),
  page: scope('page', 'page(현재 페이지)', 'page (current page)'),
  filtered: scope('filtered', 'filtered(필터를 통과한 모든 페이지)', 'filtered (all pages passing the filter)'),
  all: scope('all', 'all(모든 행)', 'all (every row)'),
  cells: (api) => {
    api.selectAllCells();
    say({
      ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
      en: `selectAllCells: ${api.getSelectedCells().length} cells`,
    });
  },
  column: (api) => {
    api.selectColumnCells('name');
    say({
      ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
      en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
    });
  },
  clear: (api) => {
    api.deselectAllRows();
    api.clearCellSelection();
  },
};

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="visible">visible</button>
    <button type="button" id="page">page</button>
    <button type="button" id="filtered">filtered</button>
    <button type="button" id="all">all</button>
    <button type="button" id="cells">Select all cells</button>
    <button type="button" id="column">Select Name column cells</button>
    <button type="button" id="clear">Clear all</button>
  </div>
  <div id="grid" style="height: 260px"></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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const names = [
  'Liam Carter',
  'Emma Stone',
  'Noah Reed',
  'Olivia Hayes',
  'Ethan Brooks',
  'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
export const options = {
  columns: [
    { id: 'team', title: 'Team', width: 90 },
    { id: 'name', title: 'Name', width: 130 },
  ],
  rows: Array.from({ length: 24 }, (_, i) => ({
    id: i + 1,
    team: ['Dev', 'Design', 'Sales'][i % 3],
    name: names[i % 6],
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  cellSelection: 'multiple',
  pagination: { mode: 'client', pageSize: 5 },
  filterRow: true,
};
let say = () => { };
export function setup(api, log) {
  say = log;
  const off = api.on('selectionChanged', ({ selectedKeys }) => log(`${selectedKeys.length} selected`));
  api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
  log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
  return () => off();
}
const scope = (name, label) => (api) => {
  api.deselectAllRows();
  api.selectAllRows({ scope: name });
  say(`${label}: ${api.getSelectedKeys().length} rows`);
};
export const actions = {
  visible: scope('visible', 'visible (same as the header checkbox)'),
  page: scope('page', 'page (current page)'),
  filtered: scope('filtered', 'filtered (all pages passing the filter)'),
  all: scope('all', 'all (every row)'),
  cells: (api) => {
    api.selectAllCells();
    say(`selectAllCells: ${api.getSelectedCells().length} cells`);
  },
  column: (api) => {
    api.selectColumnCells('name');
    say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
  },
  clear: (api) => {
    api.deselectAllRows();
    api.clearCellSelection();
  },
};