Clipboard

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.
It is not possible because of a browser security restriction that Javascript cannot
take data from the clipboard without the user explicitly doing a paste command from the browser
(eg Ctrl+V or from the browser menu). If Javascript could do this, then websites could steal
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:

1. If range selected (via range selection), copy range.

2. Else if rows selected (via row selection), copy rows.

3. Else copy focused cell.

You can copy multiple ranges in range selection by holding down ctrl to select multiple
ranges and then copy.

Safari Support

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.

Clipboard Example

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
suppressCopyRowsToClipboard:true

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
property clipboardDeliminator.

Suppress Paste

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
colDef.suppressPaste=true.

Welcome to ag-Grid

Niall Crosby spent years building Enterprise Web Applications and found the JavaScript
data grid choice frustrating. That frustration led to Niall quitting his job and
setting up the ag-Grid project.
Read more about ag-Grid →