PablocFonseca / streamlit-aggrid

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

From a beginner:A nested table program error #282

Closed atlasfish closed 2 weeks ago

atlasfish commented 2 weeks ago

I am trying to replicate a nested table in the cook book using my local data,but it triggered an exception capture in init.py line 348:

` except components.components.MarshallComponentException as ex:

uses a more complete error message.

    args = list(ex.args)
    args[0] += ". If you're using custom JsCode objects on gridOptions, ensure that allow_unsafe_jscode is True."
    ex = components.components.MarshallComponentException(*args)
    raise(ex)`

And the compiler prompted me strangely:

module 'streamlit.components.v1' has no attribute 'components'

(I dont have this when I tried to run the offical demo.) Therefore, it's difficult for me to find out bugs. Please tell me if I did something wrong, thank you!

Here is my code and data:

gridOptions = {
    # enable Master / Detail
    "masterDetail": True,
    "rowSelection": "single",
    # the first Column is configured to use agGroupCellRenderer
    "columnDefs": [
        {
            "field": "单号",
            "cellRenderer": "agGroupCellRenderer",
            "checkboxSelection": True,
        },
        {"field": "销售日期"},
        {"field": "售出时间"},
        {"field": "营业员id"},
        {"field": "总金额"},
    ],
    "defaultColDef": {
        "flex": 1,
    },
    # provide Detail Cell Renderer Params
    "detailCellRendererParams": {
        # provide the Grid Options to use on the Detail Grid
        "detailGridOptions": {
            "rowSelection": "multiple",
            "suppressRowClickSelection": True,
            "enableRangeSelection": True,
            "pagination": True,
            "paginationAutoPageSize": True,
            "columnDefs": [
                {"field": "明细编号", "checkboxSelection": True},
                {"field": "图书编号"},
                {"field": "书名"},
                {"field": "标价"},
                {"field": "折扣"},
                {"field": "折后价格"},
                {"field": "数量"},
                {"field": "单项总价"},
            ],
            "defaultColDef": {
                "sortable": True,
                "flex": 1,
            },
        },
        "getDetailRowData": JsCode(
            """function (params) {
                params.successCallback(params.data.details_list);
}"""
        ),
    },
    "rowData": data
}

    r = AgGrid(
        None,
        gridOptions=gridOptions,
        enable_enterprise_modules=True,
        # update_mode=GridUpdateMode.SELECTION_CHANGED,
        key="an_unique_key",
    )

my local data:

  {
    "单号": 1,
    "销售日期": "datetime.date(2024, 1, 5)",
    "售出时间": "datetime.time(5, 18, 23)",
    "营业员id": "2401",
    "总金额": "Decimal('280.50')",
    "details_list": [
      {
        "明细编号": 1,
        "单号": 1,
        "图书编号": "b-0007",
        "书名": "草房子",
        "标价": "Decimal('50.00')",
        "折扣": "Decimal('0.94')",
        "折后价格": "Decimal('46.75')",
        "数量": 6,
        "单项总价": "Decimal('280.50')"
      }
    ]
  },
...
]```

image image