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
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 copy operation will copy selected ranges, selected rows, or the currently focused cell, based on this order:
- If range selected (via range selection), copy range.
- Else if rows selected (via row selection), copy rows.
- 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 with the Context Menu or 'Ctrl & C'.
- Paste with 'Ctrl & V'.
- 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.
Processing Clipboard Data
If you wish to process the data before pasting into or out of the Grid, you can use the following call backs to do so:
processCellForClipboard(params):Allows you to process cells for the clipboard. Handy if you have date objects that you need to have a particular format if importing into Excel.
processCellFromClipboard(params):Allows you to process cells from the clipboard. Handy if you have for example number fields, and want to block non-numbers from getting into the grid.
Changing the Deliminator
By default, the grid will use '\t' (tab) as the field deliminator. This is to keep the
copy / paste compatible with Excel. If you want another deliminator then use the
The colDef has a property
suppressPaste where you can specify to not allowing
clipboard paste for a particular cell. This can be a boolean or a function (use a function
to specify for a particular cell, or boolean for the whole column).
More Complex Example
The example below demonstrates:
Uses CSV by setting
clipboardDeliminator=','. To test, copy to clipboard, then paste into a text editor.
Does not allow paste into the 'silver' column by setting