Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when cell_selectable=False table text cannot be copied to the clipboard in data table #1978

Open
ned2 opened this issue Mar 18, 2022 · 5 comments
Labels
bug something broken dash-data-table related to DataTable component P3 backlog

Comments

@ned2
Copy link
Contributor

ned2 commented Mar 18, 2022

Describe the bug

When a DataTable is initialised with cell_selectable=False, text cannot be copied to the clipboard. This is independent of the issue in #1975 where cells in columns with presentation value of input do not appear to be visually selected. The text can actually be selected, however when attempting to copy the selection, nothing is added to the clipboard.

Expected behavior
When cell_selectable is false, text selected inside DataTable cells should be able to be copied to the clipboard as is normally handled by the browser.

Minimal Example
Text in any cell (regardless of presentation) cannot be copied to the clipboard.

import dash
import pandas as pd
from dash import html
from dash.dash_table import DataTable

url = "https://github.com/plotly/datasets/raw/master/26k-consumer-complaints.csv"
df = pd.read_csv(url, nrows=100)
columns = [{"name": col, "id": col, "selectable": True} for col in df.columns]
columns[2]["presentation"] = "markdown"

app = dash.Dash(__name__)
app.layout = html.Div(
    [
        DataTable(
            columns=columns,
            data=df.to_dict("records"),
            cell_selectable=False,
        )
    ]
)

if __name__ == "__main__":
    app.run_server(debug=True, port=8050)

Environment

dash                          2.3.0
dash-bootstrap-components     1.0.3
dash-core-components          2.0.0
dash-html-components          2.0.0
dash-table                    5.0.0

- OS: Ubuntu 21.10
- Browser Chrome
- Version 99.0.4844.51
@ned2 ned2 changed the title [BUG] [BUG] DataTable: when cell_selectable=False table text cannot be copied to the clipboard Mar 18, 2022
@ned2
Copy link
Contributor Author

ned2 commented Mar 19, 2022

I did a bit of digging and it looks like the issue is that the onCopy event handler in dash-table/components/ControlledTable/index.tsx makes the assumption that the DataTable is in cell_selectable=True mode, as it always defers to TableClipboardHelper.toClipboard, which takes data from its selectedCells param, however this will always be empty when cell_selectable=False.

I'm wondering if what's needed is for the copy event handling logic to opt-out of using the DataTable's copying machinery and defer to the browser's default handling?

@alexcjohnson is this something we could address with a relatively small change? If so I'd be up for trying to put together a PR. Or is this opening a broader question that needs untangling first?

@alexcjohnson
Copy link
Collaborator

@ned2 thanks for the investigation! (and apologies for the slow reply, this came in during a vacation and then slipped off my radar 🙈 ) I think you're right that these events should just revert to the browser when cell_selectable=False. And if this is easy to change, by all means go for it!

@benedikt-budig
Copy link
Contributor

benedikt-budig commented Jul 1, 2022

@ned2 thanks for your hints, I have created a pull request that solves this issue: #2114

@alexcjohnson I'd be very happy to get some feedback on it from you, particularly since this is my first PR for dash 🙂

@AnnMarieW
Copy link
Collaborator

Will copy/paste of partial cell content be fixed with this PR too, or will it still be a separate issue?

@benedikt-budig
Copy link
Contributor

@AnnMarieW the fix from the PR will only affect copy/paste behavior in situations where no cell has been selected, so I assume it will not (completely) fix the issue you mentioned.

However, feel free to try it out yourself: the fix has already been included in the latest dash release 👍

@T4rk1n T4rk1n added the dash-data-table related to DataTable component label Mar 13, 2023
@gvwilson gvwilson self-assigned this Jul 24, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P3 backlog bug something broken labels Aug 13, 2024
@gvwilson gvwilson changed the title [BUG] DataTable: when cell_selectable=False table text cannot be copied to the clipboard when cell_selectable=False table text cannot be copied to the clipboard in data table Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken dash-data-table related to DataTable component P3 backlog
Projects
None yet
Development

No branches or pull requests

6 participants