Use checkbox for boolean columns in Table #846
-
QuestionHi, Trying to adapt the table with dropdown selection example from the documentation to a table column with boolean values, hoping to turn it into a checkbox column: tried using the following code in place of the dropdown options <q-td key="is_true" :props="props">
<q-checkbox
v-model="props.row.is_true"
@update:model-value="() => $parent.$emit('update_is_true', props.row)"
/>
</q-td> The checkbox renders in the column, but there seems to be no event emitted. what am I doing wrong? I don't have enough understanding of neither quasar nor javascript to know what to do. I have 3 questions:
Many thanks, this is the code snippet I am referencing: from nicegui import ui
from typing import Dict
columns = [
{'name': 'name', 'label': 'Name', 'field': 'name'},
{'name': 'age', 'label': 'Age', 'field': 'age'},
]
rows = [
{'id': 0, 'name': 'Alice', 'age': 18},
{'id': 1, 'name': 'Bob', 'age': 21},
{'id': 2, 'name': 'Carol'},
]
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}')
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-tr>
''')
table.on('rename', rename)
ui.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Have you subscribed to the event you're emitting? I tried it myself and it seems to be working nicely: 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) To do something like this for dates, maybe with QDate, you should probably look into the Quasar documentation. Once you get a hang on emitting and receiving events from slot templates, adopting Vue code from the documentation should get easier. These scoped slots are certainly one of the most complicated things NiceGUI has to offer. I'm thinking about ways to simplify it for some time now, but so far I don't see how. Since these elements |
Beta Was this translation helpful? Give feedback.
Have you subscribed to the event you're emitting? I tried it myself and it seems to be working nicely: