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

채우기 핸들로 칸 채우기Fill cells with the fill handle

cellFill을 켜면 고른 칸 끝의 작은 네모를 끌어 아래·오른쪽으로 채워요. 숫자는 같은 간격으로 이어 가고 글자는 되풀이하며, 되돌리기는 한 단계예요. Ctrl+D·Ctrl+R과 fillRange도 같은 규칙이에요.With cellFill on, drag the small square at the end of the selection to fill down or right. Numbers continue with the same step, text repeats, and undo is one step. Ctrl+D, Ctrl+R and fillRange use the same rules.

활용Intermediate
직접 써 보기Live preview채우기 핸들로 칸 채우기Fill cells with the fill handle

코드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="select">월·매출 2×2 선택</button>
    <button type="button" id="code">코드로 채우기</button>
    <button type="button" id="undo">되돌리기</button>
  </div>
  <div id="grid" style="height: 330px"></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('select').addEventListener('click', () => actions.select(api));
document.getElementById('code').addEventListener('click', () => actions.code(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
example.js
const rows = [
  { id: 1, month: 1, sales: 100, item: '노트북', note: '' },
  { id: 2, month: 2, sales: 120, item: '모니터', note: '' },
  { id: 3, month: 0, sales: 0, item: '', note: '' },
  { id: 4, month: 0, sales: 0, item: '', note: '' },
  { id: 5, month: 0, sales: 0, item: '', note: '' },
  { id: 6, month: 0, sales: 0, item: '', note: '' },
];
// cellFill: true는 채우기 핸들을 켜요. 고른 칸 끝의 작은 네모를 끌면 아래·오른쪽으로 채워요.
// 숫자가 둘 이상이고 간격이 같으면 같은 간격으로 이어 가고, 글자는 되풀이해요. 메모 열은 fillable: false라서 채워지지 않아요.
export const options = {
  columns: [
    { id: 'month', title: '월', kind: 'number', width: 80, editable: true },
    { id: 'sales', title: '매출', kind: 'number', width: 100, editable: true },
    { id: 'item', title: '품목', width: 110, editable: true },
    { id: 'note', title: '메모', width: 110, editable: true, fillable: false },
  ],
  cellSelection: 'multiple',
  cellFill: true,
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log({
    ko: '월·매출 첫 두 줄을 고르면 모서리에 작은 네모(채우기 핸들)가 나와요. 끌어서 아래로 내려 보세요.',
    en: 'Select the first two month and sales cells; a small square (the fill handle) appears at the corner. Drag it down.',
  });
  const offs = [
    api.on('fillEnded', (e) => log({
      ko: `채웠어요 (${e.direction === 'y' ? '아래로' : '오른쪽으로'}): ${e.count}칸, 못 채운 칸 ${e.rejected.length}개${e.rejected[0] ? ` (${e.rejected[0].reason})` : ''}`,
      en: `Filled (${e.direction === 'y' ? 'down' : 'right'}): ${e.count} ${e.count === 1 ? 'cell' : 'cells'}, ${e.rejected.length} refused${e.rejected[0] ? ` (${e.rejected[0].reason})` : ''}`,
    })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  select: (api) => {
    api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
  },
  code: (api) => {
    // 코드로도 같은 규칙으로 채워요: 두 줄을 여섯 줄까지.
    api.fillRange({ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 2, columnId: 'item' } }, { from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 6, columnId: 'item' } });
  },
  undo: (api) => {
    api.undo();
  },
};

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="select">Select 2×2</button>
    <button type="button" id="code">Fill in code</button>
    <button type="button" id="undo">Undo</button>
  </div>
  <div id="grid" style="height: 330px"></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('select').addEventListener('click', () => actions.select(api));
document.getElementById('code').addEventListener('click', () => actions.code(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
example.js
const rows = [
  { id: 1, month: 1, sales: 100, item: 'Laptop', note: '' },
  { id: 2, month: 2, sales: 120, item: 'Monitor', note: '' },
  { id: 3, month: 0, sales: 0, item: '', note: '' },
  { id: 4, month: 0, sales: 0, item: '', note: '' },
  { id: 5, month: 0, sales: 0, item: '', note: '' },
  { id: 6, month: 0, sales: 0, item: '', note: '' },
];
// cellFill: true turns on the fill handle. Dragging the small square at the end of the selection fills downward or to the right.
// With two or more numbers at an equal step, the same step continues; text repeats. The note column has fillable: false, so it is not filled.
export const options = {
  columns: [
    { id: 'month', title: 'Month', kind: 'number', width: 90, editable: true },
    { id: 'sales', title: 'Sales', kind: 'number', width: 100, editable: true },
    { id: 'item', title: 'Item', width: 110, editable: true },
    { id: 'note', title: 'Note', width: 110, editable: true, fillable: false },
  ],
  cellSelection: 'multiple',
  cellFill: true,
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  log('Select the first two month and sales cells; a small square (the fill handle) appears at the corner. Drag it down.');
  const offs = [
    api.on('fillEnded', (e) => log(`Filled (${e.direction === 'y' ? 'down' : 'right'}): ${e.count} ${e.count === 1 ? 'cell' : 'cells'}, ${e.rejected.length} refused${e.rejected[0] ? ` (${e.rejected[0].reason})` : ''}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  select: (api) => {
    api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
  },
  code: (api) => {
    // The same rule also fills from code: two rows up to six rows.
    api.fillRange({ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 2, columnId: 'item' } }, { from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 6, columnId: 'item' } });
  },
  undo: (api) => {
    api.undo();
  },
};