Can we import/enable any of ag-grid export capabilities in its Dash counterpart? For example: JavaScript Data Grid: Excel Export
Hello @davzup89,
Currently, excel export from AG grid is only available for it’s enterprise customers.
Right now, there isnt access for the excel specific export, but the export of CSV is available.
You can, however, export the dataframe to excel via normal means, but this will not include things like formatting, etc.
The export of CSV is meant by means of dataframe export or as dash ag-grid function? How can we enable it?
It is available currently from dash-ag-grid.
You’ll have to create a button and on click, pass True to enableExportDataAsCsv
currently.
You can find an example in the docs here:
I was wondering if it was possible to implement clipboard function to Dash AG Grid.
Such as native JS Ag-grid enables by default: JavaScript Data Grid: Clipboard
Hello @mich2210,
That is an enterprise only feature, as denoted by the red e up at the top of the topic.
To turn it on, you need to enableEnterpriseFeatures
Thanks @jinnyzor! Totally missed that.
@mich2210
Clipboard is (surprisingly) an enterprise feature, but it is possible to do some simple clipboard operations with dcc.Clipboard
Here is an example
import pandas as pd
import dash_ag_grid as dag
from dash import Dash, html, dcc, Input, Output, State
import plotly.express as px
df = px.data.gapminder()
app = Dash(__name__)
columnDefs = [
{"headerName": "Country", "field": "country", "checkboxSelection": True, "headerCheckboxSelection": True},
{"headerName": "Continent", "field": "continent"},
{"headerName": "Year", "field": "year"},
{"headerName": "Life Expectancy", "field": "lifeExp"},
{"headerName": "Population", "field": "pop"},
{"headerName": "GDP per Capita", "field": "gdpPercap"},
]
app.layout = html.Div(
[
dcc.Markdown("This grid has multi-select rows with checkboxes."),
html.Button([html.Span("copy selected"), dcc.Clipboard(id="clipboard")]),
dag.AgGrid(
id="clipboard-grid",
columnDefs=columnDefs,
rowData=df.to_dict("records"),
columnSize="sizeToFit",
defaultColDef={"resizable": True, "sortable": True, "filter": True},
rowSelection="multiple",
),
dcc.Textarea(placeholder="paste area", id="clipboard-output", style={"width": "100%", "height":200}),
],
style={"margin": 20},
)
@app.callback(
Output("clipboard", "content"),
Input("clipboard", "n_clicks"),
State("clipboard-grid", "selectedRows"),
)
def selected(n, selected):
if selected is None:
return "No selections"
dff = pd.DataFrame(selected)
dff = dff[["country", "continent", "year", "lifeExp", "pop", "gdpPercap"]]
return dff.to_string()
if __name__ == "__main__":
app.run_server(debug=True)
This worked great but exports the entire grid regardless of visibility (i.e hidden or not). How can I go about only exporting the visible columns?
Did you try adjusting the params here?
Yes I did. I also tried using columnState as an input in a callback to set the hidden cols but columnState returns null each time
Hi @kbally
See example #2 in the docs to see how to use columnState in a callback with the Clipboard
I have tried that as well as the example below but i’m still getting Null. I am using Dash Enterprise V1.3.0 so maybe that’s the issue?
Dash Enterprise shouldnt be a factor, what version of Dash AG Grid are you running?
dash_ag_grid - 1.3.0
Yeah, you’ll need to install the current versions of the open source.
pip install dash-ag-grid==2.0.0a3
Yup that fixed it. Much appreciated