You can copy and paste items to and from the grid using the system clipboard.
Copy to Clipboard
Copy to clipboard operation can be done in the following ways:
- Select 'Copy' from the context menu that appears when you right click over a cell.
- Press keys Ctrl+C while focus is on the grid.
- Use the API methods: copySelectedRowsToClipboard(includeHeaders) and copySelectedRangeToClipboard(includeHeaders)
The API calls take a boolean value includeHeaders
which when true, will include column headers in what is copied.
Paste from Clipboard
Paste to clipboard can only be done in one way:
- Press keys Ctrl+V while focus in on the grid with a cell selected.
The paste will then proceed starting at the selected cell if multiple cells are to be pasted.
The 'paste' operation in the context menu is not possible and hence always disabled.
take data from the clipboard without the user explicitly doing a paste command from the browser
data from the client via grabbing from the clipboard maliciously. The reason why ag-Grid keeps
the paste in the menu as disabled is to indicate to the user that paste is possible and it provides
the shortcut as a hint to the user. This is also why the API cannot copy from clipboard.
The copy operation will copy selected ranges, selected rows, or the currently focused cell, based
on this order:
You can copy multiple ranges in range selection by holding down ctrl to select multiple
ranges and then copy.
1. If range selected (via range selection), copy range.
2. Else if rows selected (via row selection), copy rows.
3. Else copy focused cell.
Copy to clipboard is not supported in Safari. This is because the Safari browser does not implement the
required API that ag-Grid uses, further details are described
here. ag-Grid does
not plan to support Safari clipboard as Safari is not generally used in corporate environments where
the target audience for this feature resides.
Below you can:
- Copy and Paste with the Context Menu.
- Copy with the provided buttons.
The example has both row click selection and range selection enabled. You probably won't do
this in your application as it's confusing, it's done below just to demonstrate them side by side.
When row click selection and range selection are enabled the shortcut would copy the selected row, not the
selected range, if you wish to let the range take precedence, then you can add this to your gridOptions
Controlling Clipboard Copy
If you want to do the copy to clipboard yourself (ie not use the grids clipboard interaction)
then implement the callback sendToClipboard(params). Use this if you are in a non-standard
web container that has a bespoke API for interacting with the clipboard. The callback gets the
data to go into the clipboard, it's your job to call the bespoke API.
The example below shows using sendToClipboard(params), but rather than using the clipboard,
demonstrates the callback by just printing the data to the console.