Dash AG Grid dinamic cellRendererParams (for each row)

Hey!

Was wondering if there is a way to dinamically set cellRendererParams for each row based on value in that row/cell? Something along the lines of:

columnDefs=[                        
                        {
                            "field": "boolean_field",
                            "cellDataType": "boolean",
                            "cellRenderer": "agCheckboxCellRenderer",
                            "cellRendererParams": {
                                "disabled": "params.value === true ? false : true",
                            },
                            "suppressKeyboardEvent": {
                                "function": "params.event.key === ' '"
                            },
                        },
]

Thanks!

Got it to work :smile:

define the column like this:

                    {
                        "field": "boolean_field",
                        "cellDataType": "boolean",
                        "suppressKeyboardEvent": {
                            "function": "params.event.key === ' '"
                        },
                        "cellRendererSelector": {
                            "function": "cellRendererSelectorForagCheckboxCellRenderer(params)"
                        },
                    },

then add this to your dashAgGridFunctions.js file:

dagfuncs.cellRendererSelectorForagCheckboxCellRenderer = function (params) {
    const CellValue = params.value
    console.log(CellValue)

    if (CellValue === true) {
        return {
            component: 'agCheckboxCellRenderer',
            params: {
                disabled: true
            }
        }
    }

    else if (CellValue === false) {
        return {
            component: 'agCheckboxCellRenderer',
            params: {
                disabled: false
            }
        }
    }

    return undefined
}
1 Like

Hello @dashamateur,

Glad you found the solution.

Here are the docs from upstream docs that explain and give examples:

1 Like