Table questions #3405
-
QuestionHello @falkoschindler, your replies have been very helpful for me, Thank you!
I can't seem to figure out a way to get the args from the event object... from nicegui import ui
from typing import Dict
columns = [
{'name': 'name', 'label': 'Name', 'field': 'name'},
{'name': 'age', 'label': 'Age', 'field': 'age'},
{'name': 'male', 'label': 'Male'},
]
rows = [
{'id': 0, 'name': 'Alice', 'age': 18, 'male': False},
{'id': 1, 'name': 'Bob', 'age': 21, 'male': True},
{'id': 2, 'name': 'Carol', 'male': False},
]
name_options = ['Alice', 'Bob', 'Carol']
def rename(msg: Dict) -> None:
for row in rows:
if row['id'] == msg['args']['id']:
row['name'] = msg['args']['name']
ui.notify(f'Table.rows is now: {table.rows}')
def update_male(msg: Dict) -> None:
for row in rows:
if row['id'] == msg['args']['id']:
row['male'] = msg['args']['male']
ui.notify(f'Table.rows is now: {table.rows}')
table = ui.table(columns=columns, rows=rows, row_key='name').classes('w-full')
table.add_slot('body', r'''
<q-tr :props="props">
<q-td key="name" :props="props">
<q-select
v-model="props.row.name"
:options="''' + str(name_options) + r'''"
@update:model-value="() => $parent.$emit('rename', props.row)"
/>
</q-td>
<q-td key="age" :props="props">
{{ props.row.age }}
</q-td>
<q-td key="male" :props="props">
<q-checkbox v-model="props.row.male" @update:model-value="() => $parent.$emit('update_male', props.row)" />
</q-td>
</q-tr>
''')
table.on('rename', rename)
table.on('update_male', update_male)
ui.run() I apologize if there is something obvious I'm missing! Also, I'm trying to make a label that displays only certain values of the selected rows. ui.label().bind_text_from(table, 'selected', lambda val: f'selected rows: {val}').classes('col-span-full') But I cannot for the life of me figure out how to bind the label from the specific values of that list I'm looking for. I think the answer has something to do with async/await... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @AnonyDon, Nowadays the generic event registration from nicegui import events
...
def rename(e: events.GenericEventArguments) -> None:
for row in rows:
if row['id'] == e.args['id']:
row['name'] = e.args['name']
ui.notify(f'Table.rows is now: {table.rows}') See https://nicegui.io/documentation/table#table_with_drop_down_selection for a very similar example. Regarding your second question: How does it relate to the code above? Your table has no selection enabled, so there are not selected rows. If it is unrelated, it might be better to post a separate question with a minimal code example to avoid confusion. Thanks! |
Beta Was this translation helpful? Give feedback.
Hi @AnonyDon,
Nowadays the generic event registration
.on()
returnsGenericEventArguments
instead of a plain dictionary. You can access the argument dictionary like this:See https://nicegui.io/documentation/table#table_with_drop_down_selection for a very similar example.
Regarding your second question: How does it relate to the code above? Your table has no selection enabled, so there are not selected rows. If it is unrelated, it might be better to post a …