Skip to content

How to dynamically set text and background color for q-card-section in a masonry-like table #3073

Closed Answered by falkoschindler
happybeginning1 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @happybeginning1,

  1. For dynamic colors you can write a JavaScript expression like this:

    <q-card-section class="text-center" :class="['Summary', 'Ele01'].includes(props.row.category) ? 'text-red-500 bg-gray-700' : ['Ele02', 'Ele05'].includes(props.row.category) ? 'text-red-800 bg-pink-500' : 'text-pink-300 bg-blue-300'">
        <strong>{{ props.row.category }}</strong>
    </q-card-section>

    But it would certainly easier to simply add colors to the row dictionaries and refer to them directly:

    <q-card-section class="text-center" :class="props.row.bg_color">
        <strong>{{ props.row.category }}</strong>
    </q-card-section>
  2. This doesn't sound like a use case for ui.table. You may be better off bui…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@happybeginning1
Comment options

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