PablocFonseca / streamlit-aggrid

Implementation of Ag-Grid component for Streamlit
https://pypi.org/project/streamlit-aggrid/
MIT License
1.08k stars 203 forks source link

grand totals at bottom of columns #252

Open mc-its-sorted opened 8 months ago

mc-its-sorted commented 8 months ago

hi

Awesome to use this in streamlit

I'm trying to get grand totals at the bottom of columns.

I'm trying this:

gb.configure_column(field='profit', sort='asc', groupIncludeTotalFooter=True, aggFunc='sum')

alas not working ... is this supported ?

Any help appreciated Thanks Mark

lomnes-atlast-food commented 6 months ago

@mc-its-sorted It looks like the correct implementation is:

# Remove the groupIncludeFooter parameter from the configure_column method
gb.configure_column(field='profit', sort='asc', aggFunc='sum')

# Instead use the configure_grid_options method to include the groupIncludeFooter AND the groupIncludeTotalFooter parameters.
gb.configure_grid_options(groupIncludeFooter=True, groupIncludeTotalFooter=True)
lomnes-atlast-food commented 6 months ago

Ag-grid 31.3.0 changed how total rows are handled here: https://ag-grid.com/archive/31.3.0/javascript-data-grid/grouping-footers/

likely the new way to do this is:

gb.configure_grid_options(groupTotalRow='bottom', grandTotalRow ='bottom')
mc-its-sorted commented 6 months ago

Thanks Steve

lennondata commented 6 months ago

Hello,

I'm able to get groupTotalRow and grandTotalRow showing as you described @lomnes-atlast-food, thank you! However, enabling these options now means that any edited cells are not tracked in my streamlit app:

gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_grid_options( ..., groupTotalRow='bottom', grandTotalRow='bottom',...)
gridOptions = gb.build()
# Display the grid
grid_response = AgGrid(
    df,
    gridOptions=gridOptions,
    allow_unsafe_jscode=True,
    data_return_mode=DataReturnMode.AS_INPUT,
    update_mode=GridUpdateMode.VALUE_CHANGED,
)

start streamlit app

grid_response.event_data is None # returns True

edit cell value

grid_response.event_data is None # returns True

This only happens when I enable groupTotalRow and grandTotalRow, otherwise cells edits are tracked in grid_response.event_data as type:cellValueChanged - anyone know what I might be missing?

Thanks, Matt