Reputation: 3243
Is there a way to prevent a column from being copied to the clipboard?
I currently have row-grouping enabled with groupDisplayType: 'groupRows'
and enableRangeSelection: true
If I drag a selection across rows, and thus across the row-group labels, they get included in the clipboard payload - I would like to exclude it, is this possible? I don't see any clipboard related events related to copying data, only pasting
I first tried setting gridOptions.copyGroupHeadersToClipboard=false
but this did not prevent it from being copied / pasted
I also tried implementing processCellForClipboard
and I can return params.node.group ? undefined : params.value
however it still creates a blank row in the pasted data from the clipboard (an improvement but is there a way to remove the row completely?)
The most radical approach I tried was implementing onRangeSelectionChanged
and basically de-selecting (by splitting the CellRange objects into two if a row-group cell existed in the middle of one) and calling api.clearRangeSelection()
and api.addCellRange()
but this was flaky at best
Upvotes: 2
Views: 1702
Reputation: 3243
Solved this by implementing the sendToClipboard
event, here the data
is a pipe-delimited string that you can process.
First I split it into rows by doing a .split("\r\n")
then I get the indexes of all row-group rows by combination of iterating over the range of api.getRangeCells()
and calling api.getDisplayedRowAtIndex()
to check the group
property and recording the rowIndex
I then take the lowest starting index of all the range select objects, and then delete splitRows[groupRowIndex - startOffset]
then .filter(Boolean).join("\r\n")
again
You then need to send the processed data to the clipboard via navigator.clipboard.writeText()
Upvotes: 2