justpy-org / justpy

An object oriented high-level Python Web Framework that requires no frontend programming
https://justpy.io
Apache License 2.0
1.22k stars 96 forks source link

Ag-Grid Master/Detail view : how to define getDetailRowData #397

Closed PyT closed 2 years ago

PyT commented 2 years ago

Hello all,

thanks first for this amazing component :) Did anyone find out a way to make Master/Detail view in ag-grid available with justpy ?

import justpy as jp

data = [{"make":"Toyota","model":"Celica","price":10, "details":[{"callId":555,"direction":"North","number":1}] }]

grid_options ={
    "masterDetail":True,
    "columnDefs": [
        { "field": 'make', "cellRenderer": 'agGroupCellRenderer' },
        { "field": 'model'}, {"field":'price' }
    ],
    "detailCellRendererParams": {
        "detailGridOptions": {
            "columnDefs": [
                {"field": 'callId'},
                {"field": 'direction'},
                {"field": 'number'}
            ],
            "defaultColDef": {
                "flex": 1,
            }
},
        "getDetailRowData": '''function(params) { params.successCallback(params.data.details); }'''
},    "rowData": data
}

def grid_test():
    wp = jp.WebPage()
    grid = jp.AgGrid(a=wp,options=grid_options)
    grid.evaluate=["getDetailRowData"]
    return wp

jp.justpy(grid_test)

I tried several way to express getDetailRowData without success. Each time I click on the button to see the detail grid I have this javascript error :

Uncaught TypeError: t is not a function at t.loadRowData (ag-grid-enterprise.js:8:1203603) at t.init (ag-grid-enterprise.js:8:1201788) at e.initComponent (ag-grid-enterprise.js:8:322750) at e.createAndInitUserComponent (ag-grid-enterprise.js:8:319690) at e.newFullWidthCellRenderer (ag-grid-enterprise.js:8:318098) at ag-grid-enterprise.js:8:406215 at ag-grid-enterprise.js:8:1504494 at Array.forEach (<anonymous>) at e.flushRowTemplates (ag-grid-enterprise.js:8:1504466) at ag-grid-enterprise.js:8:1333644

Any idea ?

Thanks a lot for your help

PyT

sandeep-gh commented 2 years ago

I have not used ag-grid. Inspect the code on the browser side. Most likely, value of getDetailRowData is being read as string. I am not sure if there is mechanism to pass javascript function from justpy.

WolfgangFahl commented 2 years ago

i assume this is about the https://www.ag-grid.com/javascript-data-grid/master-detail/ feature