hello,
i’m quite new to plotly dash, and even more to Ag Grid … It is possible to paste datas from an excel sheet into a dash DataTable (paste columns for example). It seems that, by default, it is not possible with Ag Grid tables. Did I miss something (highly possible ) ? I spent some times looking at videos on the (great) youtube channel “Charming Data”, but did not see that possibility yet … .
thank you,
Vincent
Hello @VincentL,
Welcome to the community!
I dont believe that this is available by default, however, it looks to be possible (with AG Grid Enterprise).
We allow you to bring your own clipboard functions.
processCellForClipboard: 1,
processHeaderForClipboard: 1,
processGroupHeaderForClipboard: 1,
processCellFromClipboard: 1,
sendToClipboard: 1,
processDataFromClipboard: 1,
Read more here:
@jinnyzor Thank you for your answer !
well, so i 'm going to use datatables a little bit more for some applications
kind regards,
vincent
Hi @jinnyzor , but by any chance do you have some idea on how you would implement these clipboard functions in python?
I have AGGrid Enterprise but after some tries i cant seem to make this work.
Here is just a basic snippet of code that i would have expected to work when copying cells from excel and pasting in the grid (selected the first cell and Ctrl+V for paste).
import dash_ag_grid as dag
from dash import Dash, html, dcc
import plotly.express as px
app = Dash(__name__)
df = px.data.medals_wide()
app.layout = html.Div(
[
dcc.Markdown("This grid has string editing enabled on all columns"),
dag.AgGrid(
id="basic-editing-example",
columnDefs=[{"field": i} for i in df.columns],
rowData=df.to_dict("records"),
columnSize="sizeToFit",
defaultColDef={"editable": True, "cellDataType": False},
dashGridOptions={"animateRows": False,},
licenseKey="MYSECRETKEY",
),
]
)
if __name__ == "__main__":
app.run(debug=False)
Hello @Silvio,
Check out the documentation here and see if it can shed any light:
1 Like
Hi @jinnyzor i did yes.
Unfortunately as per the react docs the pasting option should be enabled by default when applying the enterprise license and ensuring that editable is set to True to all cells where the pasting of a value is expected.
However this does not work at all at the moment in Dash AGGrid. The maximum i managed to do is to enable pasting from cliupboard into one single cell and that requires entering the cell edit first (i.e. with single or double click on the cell). Selecting the cell and pasting is not working at all it seems (on the react example in the docs it does work).
The below is the single cell paste example working:
import dash
from dash import html
import dash_ag_grid as dag
app = dash.Dash(__name__)
# Sample data for the AG Grid table
data = [
{"column1": "value1", "column2": "value2"},
{"column1": "value3", "column2": "value4"},
]
# Column definitions for the AG Grid table
column_defs = [
{"headerName": "Column 1", "field": "column1", "editable": True},
{"headerName": "Column 2", "field": "column2", "editable": True},
]
# Dash Grid Options including clipboard settings
grid_options = {
"enableRangeSelection": True,
"enableFillHandle": True,
"clipboard": {
"paste": True,
"pasteMode": "overwrite"
}
}
app.layout = html.Div([
dag.AgGrid(
id="my-grid",
columnDefs=column_defs,
rowData=data,
dashGridOptions=grid_options, # Pass grid options here
defaultColDef={"resizable": True, "sortable": True, "filter": True},
licenseKey="LICENSE_KEY",
)
])
if __name__ == "__main__":
app.run_server(debug=True)
OK answered my own question hehe
perhaps worth adding this to the Dash AGGrid documentation? (not sure if you can push that @adamschroeder )
The requirement to paste from excel into the grid is the following:
-
Enterprise license is required - passing in the license key via licenseKey="YOUR_LICENSE_KEY_HERE"
-
enableEnterpriseModules has to be set to True via enableEnterpriseModules=True
-
All fields expecting data to be pate4d into them need to have editable set to true in their column definitions via column_defs = [ {"headerName": "Column 1", "field": "column1", "editable": True}, ... ]
Rest is self explanatory.
Thanks for the help though!
hehe no in terms of expanding on the clipboard documentation (similar to how the react clipboard docs at the bottom have the paste to grid docs).
If you are referring to just AG grid, the goal of dash ag grid was to maintain the functionality so that their documentation would translate easily over. And a dash developer could utilize their documentation as well as ours.
As AG Grid is quite extensive in its functionally, it would take a couple of people full time hours to implement all of the documentation that they have. And then also to maintain any changes from the updates that they come out with quite regularly.
If you would like to help with the dag docs, you can do so by contacting @liamc or @AnnMarieW could also help you get in contact and gain access.
My thoughts are, highlight the most common use cases. Which this may fall under, but highlighting all of the things that AG grid can do with the copy and paste is a lot.
2 Likes