How do I set a custom aggrid cellRenderer? #1058
-
QuestionI cannot get a custom
and then adding All I want to do is linkify some text in a cell. Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @juledwar! ui.aggrid({
'columnDefs': [
{'headerName': 'Name', 'field': 'name'},
{'headerName': 'URL', 'field': 'url'},
],
'rowData': [
{'name': 'Google', 'url': '<a href="https://google.com">https://google.com</a>'},
{'name': 'Facebook', 'url': '<a href="https://facebook.com">https://facebook.com</a>'},
],
}, html_columns=[1]) |
Beta Was this translation helpful? Give feedback.
-
Hi there, thanks for the response! That's a shame we can't set custom renderers, but at least I can do the linkification for now, thanks. Is there anything specific that is preventing this from happening? Is it a bug or lack of a feature? I'm not familiar with the code at all but I could dive in if sufficiently motivated 😄 Thanks again. |
Beta Was this translation helpful? Give feedback.
-
<note to self/others> It appears that this became possible https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/aggrid.js#L18 E.g.: LinkRenderer = """
class LinkRenderer {
init(params) {
this.eGui = document.createElement('a');
this.eGui.innerText = params.value;
this.eGui.setAttribute('href', `https://website.com/profile/${params.data.id}`);
this.eGui.setAttribute('style', "text-decoration:none");
this.eGui.setAttribute('target', "_blank");
}
getGui() {
return this.eGui;
}
}
"""
gridOptions = {
"columnDefs": [
{
"field": "name",
"headerName": "Name",
},
{
"field": "profile",
"headerName": "Profile",
":cellRenderer": LinkRenderer,
}
]
} Note the |
Beta Was this translation helpful? Give feedback.
Hi @juledwar!
As far as I know it is currently not possible to set custom cell renderers in NiceGUI.
But for displaying links there is a parameter
html_columns
that allows specifying columns that should be rendered as HTML: