diff --git a/src/lib/utils/propCategories.js b/src/lib/utils/propCategories.js index 60f819ac..bd535281 100644 --- a/src/lib/utils/propCategories.js +++ b/src/lib/utils/propCategories.js @@ -255,6 +255,7 @@ export const COLUMN_MAYBE_FUNCTIONS = { // Groups toolPanelClass: 1, + totalValueGetter: 1, // Groups: Header headerClass: 1, diff --git a/tests/assets/dashAgGridFunctions.js b/tests/assets/dashAgGridFunctions.js index a5bbcc36..d5ba9f96 100644 --- a/tests/assets/dashAgGridFunctions.js +++ b/tests/assets/dashAgGridFunctions.js @@ -541,4 +541,15 @@ dagfuncs.testToyota = (params) => { dagfuncs.customTheme = (theme, agGrid) => { return theme.withPart(agGrid.createPart(agGrid.colorSchemeDark)).withPart(agGrid.createPart(agGrid.iconSetAlpine)); -} \ No newline at end of file +} + + +dagfuncs.myTotalValueGetter = function (params) { + const isRootLevel = params.node.level === -1; + + if (isRootLevel) { + return 'Grand Total'; + } + + return `Sub Total (${params.value})`; + } diff --git a/tests/test_row_groupings.py b/tests/test_row_groupings.py index 4381d10a..15d1345d 100644 --- a/tests/test_row_groupings.py +++ b/tests/test_row_groupings.py @@ -181,4 +181,67 @@ def update(cell_changed, row_data, virtual_row_data): until(lambda: dash_duo.find_element('#grid-virtualRowData-info').text == "{'country': 'Ireland', 'type': 'Non Fiction', 'city': 'texas'}", - timeout=3) \ No newline at end of file + timeout=3) + + +def test_rg003_total_value_getter(dash_duo): + import dash + from dash import html + import dash_ag_grid as dag + + from dash.testing.wait import until + from . import utils + + app = dash.Dash(__name__) + + row_data = [ + {"country": "USA", "year": 2020, "gold": 1, "silver": 0, "bronze": 1}, + {"country": "USA", "year": 2020, "gold": 2, "silver": 1, "bronze": 0}, + {"country": "USA", "year": 2024, "gold": 1, "silver": 1, "bronze": 1}, + {"country": "Canada", "year": 2020, "gold": 0, "silver": 1, "bronze": 1}, + {"country": "Canada", "year": 2024, "gold": 2, "silver": 0, "bronze": 0}, + ] + + column_defs = [ + {"field": "country", "rowGroup": True, "hide": True}, + {"field": "year", "rowGroup": True, "hide": True}, + {"field": "gold", "aggFunc": "sum"}, + {"field": "silver", "aggFunc": "sum"}, + {"field": "bronze", "aggFunc": "sum"}, + ] + + auto_group_column_def = { + "minWidth": 300, + "cellRendererParams": { + "totalValueGetter": {"function": "myTotalValueGetter(params)"}, + }, + } + + app.layout = html.Div( + [ + dag.AgGrid( + id="grid", + rowData=row_data, + columnDefs=column_defs, + defaultColDef={"flex": 1, "minWidth": 150}, + enableEnterpriseModules=True, + dashGridOptions={ + "autoGroupColumnDef": auto_group_column_def, + "groupTotalRow": "bottom", + "grandTotalRow": "bottom", + "groupDefaultExpanded": 1, + }, + + ) + ] + ) + + dash_duo.start_server(app) + + grid = utils.Grid(dash_duo, "grid") + + until(lambda: "USA" in grid.get_cell(0, 0).text, timeout=3) + all_text = [el.text for el in dash_duo.find_elements(".ag-cell")] + + assert any("Sub Total (" in t for t in all_text) + assert "Grand Total" in all_text \ No newline at end of file