hi,@AnnMarieW :
As in the official example, I used cellRendererSelector to render a column, but changed it to a button. When I clicked the button, the cellRendererData callback could not be triggered.
How to solve this problem? Please give me some advice.
columnDefs = [
{'field': 'value'},
{'field': 'type'},
{
'headerName': 'Rendered Value',
'field': 'value',
'cellRendererSelector': {"function": "customCellRendererSelector(params)"}
},
]
dagfuncs.customCellRendererSelector = (params) => {
const dbcButton= {
component: dagcomponentfuncs.DBC_Button,
};
const dmcButton= {
component: dagcomponentfuncs.DMC_Button,
};
if (params.data) {
if (params.data.type === 'gender') return dbcButton;
else if (params.data.type === 'mood') return dmcButton;
}
return undefined;
};
@callback(
Output("custom-component-btn-value-changed", "children"),
Input("custom-component-btn-grid", "cellRendererData"),
)
def showChange(n):
return json.dumps(n)
Sylvos:
dagfuncs.customCellRendererSelector = (params) => {
const dbcButton= {
component: dagcomponentfuncs.DBC_Button,
};
const dmcButton= {
component: dagcomponentfuncs.DMC_Button,
};
if (params.data) {
if (params.data.type === 'gender') return dbcButton;
else if (params.data.type === 'mood') return dmcButton;
}
return undefined;
};
Hello @Sylvos ,
Have you put this into your assets file? It needs to be registered in the proper name space.
Sylvos
May 24, 2024, 10:45pm
3
@jinnyzor Yes, I have added it to dashAgGridFunctions.js, and DBC_Button and DMC_Button have been added to dashAgGridComponentFunctions.js, these two files are in the assets folder
To trigger something to happen with a button click, you need to listen to setProps on the component t, by passing it as a function and take the n_clicks property and send data back to the grid either the api or using setData.
HI,@jinnyzor
DBC_Button is the official example, with setData()
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
dagcomponentfuncs.DBC_Button = function (props) {
const {setData, data} = props;
function onClick() {
setData();
}
return React.createElement(
window.dash_bootstrap_components.Button,
{
onClick,
color: props.color,
},
props.value
);
};
Just checking, but what version of dag are you using?
I have tried both version 31.0.1 and version 31.2.0
Is it possible to give a full MRE for this?
Adding a minimal reproducible example to your questions will help attract community members to answer your question. The goal of writing a MRE is to allow other members of the community to run the code on their computers and “reproduce” the error, so that they can best help you.
Please make sure that your MRE includes data and that the code is correctly pre-formatted.
To preformat, copy and paste the code in your post and then click on </> (Preformatted text), as shown on the image:
[pre-for…