Skip to content
Discussion options

You must be logged in to vote

Hi @akai-1024!

Too keep it simple, you can add the JavaScript function directly to the :class attribute:

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', 'age': 17},
]
table = ui.table(columns=columns, rows=rows, row_key='name')
table.add_slot('body-cell-age', r'''
    <q-td :props="props" :class="props.value < 18 ? 'bg-red' : 'bg-green'">
        {{ props.value }}
    </q-td>
''')

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@akai-1024
Comment options

@zan73
Comment options

@falkoschindler
Comment options

@Carsten-D
Comment options

@falkoschindler
Comment options

Answer selected by akai-1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants