Button not showing in ui.table custom column with add_slot #5133
-
First Check
Example Codefrom nicegui import ui
columns = [
{'name': 'id', 'label': 'ID', 'field': 'id'},
{'name': 'name', 'label': 'Name', 'field': 'name'},
{'name': 'age', 'label': 'Age', 'field': 'age'},
{'name': 'actions', 'label': 'Actions'}, # No field: 'actions' to avoid serialization error
]
rows = [
{'id': 0, 'name': 'Paul', 'age': 38 }
]
table = ui.table(columns=columns, rows=rows, row_key='id', pagination=10).classes('w-full')
table.add_slot('body-cell-actions')
with ui.row().classes('gap-2').on('click.stop', None):
ui.button('Delete', on_click=lambda: ui.notify('Deleted!'))
ui.run() DescriptionHello, Expected behavior: Actual behavior: NiceGUI Version2.24.0 Python VersionPython 3.12.2 BrowserEdge Operating SystemWindows Additional ContextIt seems that either I am misusing add_slot, or the docs/examples don’t cover how to return UI elements for body-cell slots without decorators. Would appreciate clarification or a working example showing how to render per-row buttons in a table column using the context manager style. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I would like to update that the code finally worked when I used Quasar template in table.add_slot() instead of using context manager with ui.row as in the original code. from nicegui import ui
columns = [
{'name': 'id', 'label': 'ID', 'field': 'id'},
{'name': 'name', 'label': 'Name', 'field': 'name'},
{'name': 'age', 'label': 'Age', 'field': 'age'},
{'name': 'actions', 'label': 'Actions'},
]
rows = [{'id': 0, 'name': 'Paul', 'age': 38}]
table = ui.table(columns=columns, rows=rows, row_key='id').classes('w-full')
# Quasar template for Actions column
table.add_slot(
'body-cell-actions',
'''
<q-btn color="red" label="Delete" @click="() => $q.notify({message: 'Deleted ' + props.row.name + '!'})" />
'''
)
ui.run() |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
Yes, as far as I know that's the only way. It's similar to expandable rows example in the docs.