Original Post announcing Dash AG Grid Open Source:
For an overview of Dash AG Grid Features, please see:
New in Dash AG Grid V2.0.0a3
We are pleased to announce the third pre-release of Dash AG Grid. This one is packed with new features!
pip install dash-ag-grid==2.0.0a3
JavaScript Functions
See the Beyond The Basics section of the docs for an introduction to using JavaScript functions with dash-ag-grid props.
While it’s not necessary to use JavaScript functions with most of AG Grid features, using functions allows you to add custom components to the grid and to take customization to the next level. There are now more than 80 Dash props where you can pass JavaScript functions from Dash to AG Grid.
We’ll be adding lots of examples to the docs, but here are a few to get you started:
Selectable Rows
Here’s a simple JavaScript function that determines whether a row is selectable. (Only rows having a year earlier than 2007 are selectable.)
dag.AgGrid(
dashGridOptions = {'isRowSelectable': {"function": "params.data ? params.data.year < 2007 : false" }},
# other props
)
See the full example in the Selection Checkbox section of Dash AG Grid docs.
Column Spanning
By using a function to set the column width of certain rows, you can make reports that look like this:
See complete example in the docs in the Column Spanning section. This works with Row Spanning too!
Aggregation with Custom Functions (AG Grid Enterprise)
See complete example in the Enterprise Examples
Cell Class Rules and Row Class Rules
You can now use class names with condition formatting. In this example, we use Bootstrap class names – so the background colors of the highlighted cells will match your selected Bootstrap theme.
See this example in the Cell Styling section. You can learn how to use class names with conditional formatting to set Row Styles too.
Date and Number Formatting
Dash AG Grid includes the d3-format
and d3-time-format
libraries - making it easy to format numbers and dates.
See more examples in the Value Formatters with d3-format section of the docs.
Date Filters
We have Included examples in the docs of how to make the date filters to work “out-of-the-box” using d3.time-format to convert string dates into date objects.
See more examples in the Filtering section of the docs.
Custom Components
You can now add custom components to the grid using the cellRenderer.
This example shows how to create links, display values as a badge, display boolean values as a checkbox, add custom buttons and dropdowns to cells. Use these examples to learn how to create your own custom components.
See the example in the Custom Components using the Cell Renderer docs.
You can also add a custom tooltip to the grid. See this example in Custom Tooltips.
Breaking Changes
- in 2.0.0a3
- Prop name changed from
clickData
tocellRendererData
This is used in the RowMenu Component.
- Prop name changed from
- in 2.0.0a2
- Prop name changed from
selectionChanged
toselectedRows
- Prop name change from
dangerously_allow html
todangerously_allow_code
. This prop now only needs to be on the grid level, rather than on both the grid level and on the columnDefs.
- Prop name changed from
- in 2.0.0a1
- Added
dangerously_allow_html
prop. Must be set to True to render html or execute cell expressions.
- Added
Migration from 2.0.0a1
For an example of migrating from 2.0.0a1 to 2.0.0a3 see two versions of the same app in GitHub
In the latest version you will notice that there is no need to set the grid to dangerously_allow_code=True
This is because we are not using raw html in any components, and we are using functions instead of string expressions.
- The new way to safely pass known JavaScript functions to the Grid:
{"function": string}
where string is the body of the function as a string, or the variable name of a function defined in the dashAgGridFunctions
namespace.
For example, in demo_stock_portfolio app:
# New way to use functions as props
columnDefs = [
"valueFormatter": {"function": "Number(props.value).toFixed(2)"},
]
# The old way used in 2.0.0a1 -- Don't do it this way
columnDefs = [
"valueFormatter": "Number(value).toFixed(2)",
"dangerously_allow_html": True,
]
- Prop name change:
selectionChanged
is now called selectedRows
# New prop name in V2.0.0a3
@app.callback(
Output("candlestick", "figure"),
Input("portfolio-grid", "selectedRows"),
)
# Old prop name in V2.0.0a1
@app.callback(
Output("candlestick", "figure"),
Input("portfolio-grid", "selectionChanged"),
)
- New Prop:
dashGridOptions
Only a subset of AG Grid props are defined in Dash. Valid AG Grid props can be passed to the grid in a dict using the dashGridOptions
prop. For example:
dag.AgGrid(
columnDefs=columnDefs,
rowData=df.to_dict("records"),
dashGridOptions={"undoRedoCellEditing": True, "rowSelection": "single"},
)
To do before V2.0.0
There will be a few more changes to prop names before the 2.0.0 release. Also, we’ll be removing many AG Grid props that are defined in Dash in the pre-release version of dash-ag-grid. These props can still be used - they just need to be passed to the grid using the dashGridOptions
prop as shown above.
Thanks to @jinnyzor for doing the development work on this component, and thanks to @alexcjohnson for the mentoring and code reviews!