plotly / dash-ag-grid

Dash AG Grid is a high-performance and highly customizable component that wraps AG Grid, designed for creating rich datagrids.
https://dash.plotly.com/dash-ag-grid
MIT License
177 stars 28 forks source link

Is it possible to automatically generate a legend based on the `cellStyle`? #309

Closed huong-li-nguyen closed 4 months ago

huong-li-nguyen commented 4 months ago

Hey guys,

First of all, amazing work on the dash-ag-grid! 🥳 I almost use it in every demo I have.

I was wondering if there is an easy / recommended way of adding legends to the dash-ag-grid that correspond to the cellStyle?

For example, in this app, I would love it if there was a legend below the table explaining the color coding in the cells of the dash-ag-grid.

Will this be enabled natively at some point? If not, is there a recommended way of doing so?

Best, Li

BSd3v commented 4 months ago

Hello @huong-li-nguyen,

What do you mean by the celltStyle? Are you thinking of something similar to conditional formatting?

As these are coming from Python, you can setup something that would pull it out and explain how it is working.

For example, with what you have, you would do something like this:

rowData = []
for s in CELL_STYLE['styleConditions']:
    rowData.append({"condition": s['condition'], "cell_style": s["style"]})

columnDefs = [{"field": "condition", "cellStyle": {"function": "params.data.cell_style"}, {"field": "cell_style", "hide": True}]

dag.AgGrid(rowData=rowData, columnDefs=columnDefs)

image

AnnMarieW commented 4 months ago

Hi @huong-li-nguyen

Are you looking for a legend like this? https://dash.plotly.com/dash-ag-grid/styling-cells#cell-shading-examples

image

It's unlikely that this would be built in to dash-ag-grid, but this would be a great topic for the forum. Would you like to close this and continue the discussion over there?

huong-li-nguyen commented 4 months ago

Hey @BSd3v and @AnnMarieW ,

thanks for your quick response! 🚀

I find both very helpful. Indeed, I was looking for a legend in the style of @AnnMarieW's example but find you way of pulling the information very useful @BSd3v!

I'll continue the discussion on the Plotly forums 👍