Skip to content

Commit 1bb276c

Browse files
Add table demo: Delete button in Actions column using Quasar template (zauberzeug#5150)
### Motivation Add an example to the NiceGUI table documentation showing how to include a Delete button in a custom “Actions” column using Quasar template slots. This addresses a common question in the discussions about rendering per-row buttons in tables, which wasn’t clearly covered in the existing docs. ### Implementation Added a new demo in website/documentation/content/table_documentation.py using table.add_slot() with a Quasar template. The demo shows a red Delete button in each row’s Actions column that triggers a notification when clicked. Could you ensure the button displays correctly and is aligned with the row content? ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] Pytests have been added (or are not necessary). [x] (not required for UI demo) - [x] Documentation has been added (or is not necessary). [x] (demo added directly to table documentation) <img width="346" height="232" alt="Table_delete_button" src="https://github.com/user-attachments/assets/c3c99718-79f4-4c74-b186-12f5dc511fd4" /> --------- Co-authored-by: Falko Schindler <[email protected]>
1 parent c5c9dfe commit 1bb276c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

website/documentation/content/table_documentation.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,33 @@ def toggle(column: dict, visible: bool) -> None:
139139
column=column: toggle(column, e.value))
140140

141141

142+
@doc.demo('Table with buttons', '''
143+
You can add buttons to the table cells using a named slot "body-cell-[name]".
144+
In this example, we add a button to the "action" column.
145+
When the button is clicked, a custom "notify" event is emitted with the row as argument.
146+
The "notify" event is handled by a lambda function, which emits a notification with the name of the row.
147+
''')
148+
def table_with_buttons():
149+
columns = [
150+
{'name': 'name', 'label': 'Name', 'field': 'name'},
151+
{'name': 'action', 'label': 'Action', 'align': 'center'},
152+
]
153+
rows = [
154+
{'name': 'Alice'},
155+
{'name': 'Bob'},
156+
]
157+
table = ui.table(columns=columns, rows=rows)
158+
table.add_slot('body-cell-action', '''
159+
<q-td :props="props">
160+
<q-btn label="Notify" @click="() => $parent.$emit('notify', props.row)" flat />
161+
</q-td>
162+
''')
163+
table.on('notify', lambda e: ui.notify(f'Hi {e.args["name"]}!'))
164+
165+
142166
@doc.demo('Table with drop down selection', '''
143167
Here is an example of how to use a drop down selection in a table.
144-
After emitting a `rename` event from the scoped slot, the `rename` function updates the table rows.
168+
After emitting a "rename" event from the scoped slot, the `rename` function updates the table rows.
145169
''')
146170
def table_with_drop_down_selection():
147171
from nicegui import events

0 commit comments

Comments
 (0)