# Autofill
URL: https://pro.rv-grid.com/guides/data-manage/autofill/
Source: src/content/docs/guides/data-manage/autofill.mdx
Description: Fill ranges with spreadsheet-like copy and sequence behavior.
The `AutoFillPlugin` adds spreadsheet-style drag fill to RevoGrid. Users select one
or more cells, drag the fill handle, and RevoGrid fills the target range with the
best matching strategy.

For a richer spreadsheet experience, pair it with `AutoFillPreviewPlugin`. The
preview plugin shows ghost values while the user is dragging, but it does not write
anything to the data store until the drop-time autofill is accepted.

  Select one or more seed cells in the demo below, then drag the fill handle to
  preview the values before releasing the mouse to commit them.

## Usage

```ts
import { AutoFillPlugin, AutoFillPreviewPlugin } from '@revolist/revogrid-pro';

const grid = document.createElement('revo-grid');
grid.plugins = [AutoFillPlugin, AutoFillPreviewPlugin];
```

Use only `AutoFillPlugin` when you want values to appear only after mouse release.
Add `AutoFillPreviewPlugin` when users should see the predicted values before they
drop the mouse.

### Crossing Pinned And Main Viewports

Add `MultiRangeSelectionPlugin` when users should be able to drag the autofill
handle from a pinned row or column into the main viewport, or from the main
viewport into a pinned section. Cross-viewport autofill is enabled by default
with multi-range selection.

```ts
import {
  AutoFillPlugin,
  MultiRangeSelectionPlugin,
} from '@revolist/revogrid-pro';

grid.plugins = [AutoFillPlugin, MultiRangeSelectionPlugin];
```

Cross-viewport autofill is scoped to visible viewport segments. If the main
viewport is scrolled, the plugin does not treat the pinned section and main data
as one hidden continuous range, and it does not write rows or columns behind the
scroll gap. The final selection is represented as multiple ranges so each visible
source and target segment remains explicit.

Disable the cross-viewport drag integration while keeping multi-range selection
enabled with:

```ts
grid.multiRangeSelection = { crossViewportAutofill: false };
```

## What Users See

1. Select a source cell or range.
2. Drag the small autofill handle from the selection corner.
3. Ghost values appear in the temporary target range when preview is enabled.
4. Release the mouse to commit the same values that were previewed.
5. Pressing escape, clearing the temporary range, or changing the source clears the preview.

Existing selected source cells are not visually replaced by preview values. The
preview only appears in the autofill target range.

## Built-In Strategies

AutoFill strategies are checked from most specific to most general. If no sequence
strategy can safely infer a pattern, RevoGrid repeats the selected values with copy
fallback.

| Strategy | User behavior | Example |
| --- | --- | --- |
| Linear numeric sequence | Continues a selected numeric interval. | `1, 3` -> `5, 7` |
| Single numeric step | Extends one selected number by `+1`. | `10` -> `11, 12` |
| Number in text | Continues labels with embedded numbers and preserves padding. | `INV-099` -> `INV-100`; `1st Floor` -> `2nd Floor` |
| Weekday names | Continues English weekday labels and wraps the week. | `Mon, Tue` -> `Wed` |
| Month names | Continues English month labels and wraps the year. | `Jan, Feb` -> `Mar` |
| Date unit sequence | Continues daily, weekly, monthly, quarterly, and yearly date intervals. | `2024-12-04, 2024-12-05` -> `2024-12-06` |
| Time sequence | Continues `HH:mm` and `HH:mm:ss` time intervals. | `09:00, 09:30` -> `10:00` |
| Boolean cycle | Repeats boolean-like toggle pairs. | `Yes, No` -> `Yes, No` |
| Text suffix sequence | Keeps compatibility with existing `Book 1`, `Book 2` fills. | `Book 1, Book 2` -> `Book 3` |
| Copy fallback | Repeats selected values when the pattern is plain or ambiguous. | `Draft, Approved` -> `Draft, Approved` |

## Strategy Notes

### Numeric Values

Select two or more numeric cells to preserve an interval. For example, selecting
`100` and `110` continues with `120`, `130`, and so on. Selecting one numeric cell
uses a simple `+1` sequence.

### Text With Numbers

AutoFill understands numbers inside labels, not only numbers at the end. It keeps
the visible text shape stable when the selected values are consistent.

```txt
Item 001 -> Item 002
INV-099 -> INV-100
1st Floor, 2nd Floor -> 3rd Floor
```

If labels use different prefixes, suffixes, or number formats, RevoGrid falls back
to copying the selected values instead of guessing.

### Dates And Times

Dates preserve the selected visible format when possible:

```txt
2024-12-04 -> 2024-12-05
2024/12/04 -> 2024/12/05
12/04/2024 -> 12/05/2024
```

Monthly, quarterly, and yearly fills are inferred from consistent month steps. Time
fills preserve `HH:mm` or `HH:mm:ss` and wrap across midnight.

### Weekdays And Months

Weekday and month strategies support English full names and three-letter labels.
The output format follows the source format:

```txt
Monday, Tuesday -> Wednesday
Mon, Tue -> Wed
January, February -> March
Jan, Feb -> Mar
```

### Boolean-Like Values

Boolean cycle supports `true/false`, `yes/no`, and `on/off`. String pairs require
both values in the selected range, so a single `Yes` cell is copied instead of
turning into an inferred toggle.

### Copy Fallback

Copy fallback is intentional. It handles plain text, mixed values, and unsupported
patterns by repeating the selected values exactly. This keeps AutoFill predictable
for status columns and other business data where guessing a sequence would be
surprising.

## Custom Strategies

Developers can register custom strategies for domain-specific patterns. Custom
strategies run before copy fallback, so they can override generic copy behavior.

```ts
import type { AutoFillStrategy } from '@revolist/revogrid-pro';

const priorityStrategy: AutoFillStrategy = (selectedData, direction, targetRange, context) => {
  // Return a matrix when your strategy supports the selection.
  // Return null to let the next strategy try.
  return null;
};

AutoFillPlugin.registerStrategy(priorityStrategy);
```

Return `null` when a strategy is not confident. Preview and final apply share the
same strategy list, so a custom strategy automatically affects both behaviors.
