How to dynamically set text and background color for q-card-section in a masonry-like table #3073
-
QuestionI have a piece of code that works well overall: with ui.element('div').classes('w-full text-sm'):
with ui.row().classes('w-full'):
columns = [
{'name': 'category', 'label': 'Category', 'field': 'category'},
{'name': 'content', 'label': 'Content', 'field': 'content'},
]
rows = [
{'category': 'Summary', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele01', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele02', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele03', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele04', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele05', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'}
]
table = ui.table(columns=columns, rows=rows, row_key='category').props('grid')
table.add_slot('item', r'''
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3 grid-style-transition">
<q-card flat bordered :props="props">
<q-card-section class="text-center bg-gray-700">
<strong>{{ props.row.category }}</strong>
</q-card-section>
<q-separator />
<q-list>
<q-item>
<q-item-section>
<q-item-label>{{ props.row.content }}</q-item-label>
</q-item-section>
<q-item-section side>
<q-item-label caption>{{ props.row.value }}</q-item-label>
</q-item-section>
</q-item>
</q-card>
</div>
''') But I am currently struggling with two issues.
{'category': 'Summary', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Summary', 'content': 'aaa', 'value': '23'},
{'category': 'Summary', 'content': 'bbb', 'value': '22'},
{'category': 'Ele01', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele02', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele03', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele04', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'},
{'category': 'Ele05', 'content': 'fdskjfdskfdfdsffdsf', 'value': '22'} How can I display the rows belonging to the same category (like Summary) in a single table card (with each row of data on a separate line, corresponding to a set of <q-item>xxx</q-item>)? Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @happybeginning1,
|
Beta Was this translation helpful? Give feedback.
Hi @happybeginning1,
For dynamic colors you can write a JavaScript expression like this:
But it would certainly easier to simply add colors to the row dictionaries and refer to them directly:
This doesn't sound like a use case for
ui.table
. You may be better off bui…