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

마우스를 올리면 행이 켜질까, 칸이 켜질까?Highlight the row, the cell, or nothing on hover

마우스를 올렸을 때 행 전체를 칠할지, 칸 하나만 칠할지, 아무것도 안 칠할지를 설정 하나로 정해요.One setting decides whether the mouse paints the whole row, a single cell, or nothing.

입문Beginner
직접 써 보기Live preview마우스를 올리면 행이 켜질까, 칸이 켜질까?Highlight the row, the cell, or nothing on hover

코드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="mode">
      <option value="row" selected>행 전체 (기본)</option>
      <option value="cell">칸 하나</option>
      <option value="none">칠하지 않기</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
const regions = ['서울', '부산', '대구', '제주'];
const managers = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
const statuses = ['배송 준비', '배송 중', '배송 완료'];
// 지역(region) 칸은 같은 값끼리 세로로 합쳐 보여요(merge). 합쳐진 칸 위에서 마우스 올림이 어떻게 보이는지도 확인해 보세요.
export const options = {
  columns: [
    { id: 'region', title: '지역', width: 90, merge: true, align: 'center' },
    { id: 'manager', title: '담당자', width: 110 },
    { id: 'customer', title: '고객번호', width: 120 },
    { id: 'product', title: '상품', width: 160 },
    { id: 'status', title: '상태', width: 110 },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    region: regions[Math.floor(i / 4)],
    manager: managers[(i * 3) % 5],
    customer: `C-${String(1000 + ((i * 137) % 900)).padStart(4, '0')}`,
    product: products[(i * 2) % 5],
    status: statuses[(i * 7) % 3],
  })),
  rowKey: 'id',
  striped: false,
  hover: 'row',
};
// hover 옵션 하나로 마우스를 올렸을 때 칠할 범위를 정해요.
//  'row'  : 올라간 행 전체(기본값)
//  'cell' : 올라간 칸 하나
//  'none' : 칠하지 않음
export const actions = {
  mode: (api, value) => api.setOptions({ hover: value === 'cell' || value === 'none' ? value : 'row' }),
};

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="Hover range" id="mode">
      <option value="row" selected>Whole row (default)</option>
      <option value="cell">Single cell</option>
      <option value="none">Nothing</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
const regions = ['Seoul', 'Busan', 'Daegu', 'Jeju'];
const managers = ['Liam Carter', 'Emma Stone', 'Noah Brooks', 'Olivia Reed', 'Ethan Hayes'];
const products = [
  'Wireless Earbuds',
  'Smart Watch',
  'Laptop Stand',
  'Power Bank',
  'Bluetooth Speaker',
];
const statuses = ['Preparing', 'Shipping', 'Delivered'];
// The region cells merge vertically where values repeat (merge). Also check how hover looks over a merged cell.
export const options = {
  columns: [
    { id: 'region', title: 'Region', width: 90, merge: true, align: 'center' },
    { id: 'manager', title: 'Manager', width: 130 },
    { id: 'customer', title: 'Customer ID', width: 120 },
    { id: 'product', title: 'Product', width: 160 },
    { id: 'status', title: 'Status', width: 110 },
  ],
  rows: Array.from({ length: 16 }, (_, i) => ({
    id: i + 1,
    region: regions[Math.floor(i / 4)],
    manager: managers[(i * 3) % 5],
    customer: `C-${String(1000 + ((i * 137) % 900)).padStart(4, '0')}`,
    product: products[(i * 2) % 5],
    status: statuses[(i * 7) % 3],
  })),
  rowKey: 'id',
  striped: false,
  hover: 'row',
};
// A single hover option sets how much is painted when the mouse is over the grid.
//  'row'  : the whole hovered row (default)
//  'cell' : the single hovered cell
//  'none' : paint nothing
export const actions = {
  mode: (api, value) => api.setOptions({ hover: value === 'cell' || value === 'none' ? value : 'row' }),
};