Skip to content

Issue in updating aggrid on client using run_grid_method and run_row_method #5683

@krishanunayak

Description

@krishanunayak

First Check

  • I added a very descriptive title here.
  • This is not a security issue (those should be reported via the security advisory instead).
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

from uuid import uuid4

from nicegui import ui
from nicegui.events import GenericEventArguments


async def root():
    async def update_grid(event: GenericEventArguments):
        changed_row_id = event.args.get("rowId")
        changed_row_index = event.args.get("rowIndex")
        new_a = event.args.get("newValue")
        new_b = new_a * 3
        updated_row = event.args.get("data")
        updated_row.update({"a": new_a, "b": new_b})
        # option 1:
        await grid.run_grid_method("applyTransaction", "update", [updated_row])
        # option 2:
        # grid.options["rowData"][changed_row_index] = updated_row
        # option 3:
        # await grid.run_row_method(changed_row_id, "setDataValue", "b", new_b)
        # option 4:
        # await grid.run_row_method(changed_row_id, "setData", updated_row)
        # option 5:
        # await grid.run_row_method(changed_row_id, "updateData", updated_row)

    options = {
        "defaultColDef": {"enableCellChangeFlash": True},
        "columnDefs": [
            {
                "headerName": "A",
                "field": "a",
                "editable": True,
                "type": "numericColumn",
            },
            {
                "headerName": "B",
                "field": "b",
                "type": "numericColumn",
            },
        ],
        "rowData": [],
        ":getRowId": "(params) => params.data.row_id",
    }
    grid = ui.aggrid(options).classes("w-full")
    grid.options["rowData"] = [
        {"a": 3, "b": 9, "row_id": str(uuid4())},
        {"a": 4, "b": 12, "row_id": str(uuid4())},
    ]
    grid.on("cellValueChanged", update_grid)


if __name__ in ("__main__", "__mp_main__"):
    ui.run(root, reload=True)

Description

Objective: When user changes content of a cell, I need to compute on the server and update one or more rows on the client.

Issues Observed: While trying with different options, observed the following issues:

  • Option 1 (Preferred choice): Using run_grid_method with applyTransaction grid api method to update multiple rows at the same time on client does not update the grid.
  • Option 2: Updating rowData of the grid on the server itself causes the grid to fully refresh on client which works as expected but not useful due to loss of focus.
  • Option 3: Using run_row_method with setDataValue to update specific cells on client results multiple triggers (possibly recursive) of the handler (ideally due to cellValueChanged event).
  • Option 4 & Option 5: Using run_row_method with setData / updateData works as expected but would require multiple calls due to the nature of multi row update (my only choice at the moment).

So, it seems to me that Option 1 is supposed to work but isn't as expected and would highly appreciate your help on this.

NiceGUI Version

3.6.1

Python Version

3.12.10

Browser

Edge

Operating System

Windows

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions