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
175 stars 25 forks source link

ValueFormatter with advanced grouping #63

Closed joonh-min closed 1 year ago

joonh-min commented 1 year ago

Hello, thanks for your works.

I've been working with a table with multiple layers of columns, like years, quarters, months, and so on.

I was exporting formatted numbers as string, but I saw that valueFormatter is available from a2, I wanted try it. but it seems like I won't able to get the valueFormatter working from 2nd level.

Would there be a way for me to get the params.value within those groups?

I just made a quick example from this.

Example ``` import dash_ag_grid as dag from dash import Dash, html, dcc import plotly.express as px df = px.data.gapminder() app = Dash(__name__) columnDefs = [ {"headerName": "Country", "field": "country", "flex":1}, {"headerName": "Continent", "field": "continent", "flex":1}, {"headerName": "Year", "field": "year", "flex":1}, {"headerName": "grouped", "flex":1, "groupId":"group1", "children": [ { "headerName": "Population", "field": "pop", "flex":1, "valueFormatter": {"function": "d3.format(',.0f')(params.value)"}, }, { "headerName": "GDP per Capita", "field": "gdpPercap", "flex":1, "valueFormatter": {"function": "d3.format('$,.1f')(params.value)"}, }, { "headerName": "group2", "groupId":"group2", "flex":1, "children":[ { "headerName": "Life_Expectancy", "field": "lifeExp", "flex":1, "valueFormatter": {"function": "d3.format(',.0f')(params.value)"}, }, { "headerName": "GDP per Capita2", "field": "gdpPercap", "flex":1, "valueFormatter": {"function": "d3.format('$,.1f')(params.value)"}, }, ] }, ] } ] app.layout = html.Div( [ dcc.Markdown("Gapminder Data with formatting"), dag.AgGrid( columnDefs=columnDefs, defaultColDef="", rowData=df.to_dict("records"), columnSize="sizeToFit", ), ], style={"margin": 20}, ) if __name__ == "__main__": app.run(debug=True) ```

I hope I am just missing something, Thanks for the works once again!

AnnMarieW commented 1 year ago

@hieut91 Thanks for reporting - this looks like a bug.

Nice minimal example too - that's helpful :slightly_smiling_face:

BSd3v commented 1 year ago

Hello @hieut91,

I actually am already working on this. 😄

Should have a PR here today that will address this concern.

joonh-min commented 1 year ago

@AnnMarieW @BSd3v That's awesome, Thanks a lot!

BSd3v commented 1 year ago

Hello @hieut91, this is available now in a3. 😄

Please reopen if there is an issue.

joonh-min commented 1 year ago

@BSd3v yup, they work as I expected, Thank you!👍