채우기 핸들로 칸 채우기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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));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();
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>채우기 핸들로 칸 채우기</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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라서 채워지지 않아요.
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',
};
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());
}
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();
},
};
options.ariaLabel = "채우기 핸들로 칸 채우기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('select').addEventListener('click', () => actions.select(api));
document.getElementById('code').addEventListener('click', () => actions.code(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.select(api)}
>월·매출 2×2 선택</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.code(api)}
>코드로 채우기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 코드로도 같은 규칙으로 채워요: 두 줄을 여섯 줄까지.
api.fillRange(
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 2, columnId: 'item' } },
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 6, columnId: 'item' } },
);
},
undo: (api: GridApi<Row>) => {
api.undo();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.select(api)">월·매출 2×2 선택</button>
<button type="button" :disabled="!api" @click="api && actions.code(api)">코드로 채우기</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">되돌리기</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 코드로도 같은 규칙으로 채워요: 두 줄을 여섯 줄까지.
api.fillRange(
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 2, columnId: 'item' } },
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 6, columnId: 'item' } },
);
},
undo: (api: GridApi<Row>) => {
api.undo();
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.select(api)"
>월·매출 2×2 선택</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.code(api)"
>코드로 채우기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 코드로도 같은 규칙으로 채워요: 두 줄을 여섯 줄까지.
api.fillRange(
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 2, columnId: 'item' } },
{ from: { rowKey: 1, columnId: 'month' }, to: { rowKey: 6, columnId: 'item' } },
);
},
undo: (api: GridApi<Row>) => {
api.undo();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<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>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));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();
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fill cells with the fill handle</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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.
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',
};
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());
}
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();
},
};
options.ariaLabel = "Fill cells with the fill handle";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('select').addEventListener('click', () => actions.select(api));
document.getElementById('code').addEventListener('click', () => actions.code(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.select(api)}
>Select 2×2</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.code(api)}
>Fill in code</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>Undo</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 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: GridApi<Row>) => {
api.undo();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.select(api)">Select 2×2</button>
<button type="button" :disabled="!api" @click="api && actions.code(api)">Fill in code</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">Undo</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 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: GridApi<Row>) => {
api.undo();
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.select(api)"
>Select 2×2</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.code(api)"
>Fill in code</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>Undo</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
month: number;
sales: number;
item: string;
note: string;
}
const rows: Row[] = [
{ 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: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'month' }, { rowKey: 2, columnId: 'sales' });
},
code: (api: GridApi<Row>) => {
// 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: GridApi<Row>) => {
api.undo();
},
};