Skip to content

[data grid] Allow triggering clipboard copy/paste through API #17334

Open
@ElliottMiller

Description

@ElliottMiller

Summary

I've gotten this working locally by doing the following, but I know it's wrong 😄

const copiedCells = controlledDataGridRef.current.unstable_applyPipeProcessors('clipboardCopy', ''); navigator.clipboard.writeText(copiedCells);

Basically, I'd rather not reference unstable internal functions when implementing functionality. We need to be able to right click a cell or selection of cells to copy them to the clipboard. This presented a couple issues (having to use slots and having to rely on an event rather than getting params for the context menu, like header context, made it more difficult to determine whether the cell is selected), but primary among them that in order to implement the copy functionality, I had the option of either re-implementing the handleClipboardCopy functionality that exists in useGridSelection.tsx (ew), or using unstable_applyPipeProcessors to get at the guts of the function and reusing it.

Don't make me do bad things, please ;)

(P.S: If I can get really greedy, I'd also like first class support for cell context menus that pass cell and row context like the header context menus do).

Examples

No response

Motivation

I've implemented this already in my code using the unstable_applyPipeProcessors code above, but I'm implementing a cell context menu that allows users to context click a selection of cells to copy them to the clipboard:

Image

There was no programmatic/clean way to trigger a copy. I'd like that to be added.

Search keywords: copy, clipboard

Order ID: 108843

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature: ClipboardRelated to clipboard copy or paste functionalitiesnew featureNew feature or requestsupport: premium standardSupport request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

    Projects

    Status

    🆕 Needs refinement

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions