# Copy and paste support

Copy and Paste support is built in to Glide Data Grid. It is not enabled by default to ensure developers are expecting its behavior.

### Copy

By default copy is not enabled, to enabled copy implement the `getCellsForSelection` callback. The callback returns results as row-major ordering.

> `getCellsForSelection` is used instead of `getCellContent` to allow optimization when fetching large amounts of data outside of the visible region.

This example uses the built in generic function which simply calls `getContent`, which is inefficient but fine for a local data source.

```tsx
return <DataEditor {...rest} getCellsForSelection={true} />
```

Congratulations. Copy now works! You may wish to implement [`getCellsForSelection` ](https://docs.grid.glideapps.com/api/dataeditor/important-props#getcellsforselection)with a more efficient means that lots of calls to `getCellContent`. It is also worth knowing that normally `getCellContent` is only called for cells within the current view. Once you pass `true` to `getCellsForSelection` this promise no longer holds. This is another reason an implementor may choose to handle this callback directly.

### Paste

The easiest way to enable paste is to set `onPaste` to true when `onCellEdited` is already working. The Glide Data Grid will automatically parse the paste buffer and send cell update events.

```tsx
return <DataEditor {...rest} onCellEdited={onCellEdited} onPaste={true} />
```

If desired, paste events can be handled manually. Passing a callback to `onPaste` will instead receive a parsed verison of the pasted data. Returning `true` from the callback will cause the paste event to be handled the same as before, emitting `onCellEdited`. Returning `false` will prevent the edit callback from being emitted.

```tsx
return <DataEditor
    {...rest}
    onCellEdited={onCellEdited}
    onPaste={(target, value) => {
        window.alert(JSON.stringify({ target, value }));
        return false;
    }}
/>
```

Paste, like copy, has an efficiency gain to be had. Instead of listening to `onCellEdited` an implementor may choose to implement `onCellsEdited`. This receives the entire paste buffer at once for all cells pasted and allows more efficient writes to the backend without having to manually handle paste buffer parsing.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.grid.glideapps.com/extended-quickstart-guide/copy-and-paste-support.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
