Color button by expression

I need to color a button or object background color dynamically.
The database has been filtered by url parameter.
field values are 1,2 or 3 (1 green , 2 yellow, 3 red)
Is this possible?

Yes you can. This tutorial shows how to do it with table rows, but it is exactly the same for buttons.

Thank you for your reply
when using the btn-danger class with expression there are no color changes!

Can you provide a link to your page, where we can check this?

button background color has been set to info

database fieldvalue = 3 (class toggle = btn-danger)

condition = db.data.qry[0].status = 3

iscan.bus.nl/bus.aspx/?id=1000

The code on your page is wrong. I see the classes entered twice:


<button class="btn flex-xl-shrink-1 bg-info" data-toggle="button" dmx-class:btn-danger.btn-danger="dbitec.data.qryitec[0].certificate_status = 3" dmx-class:btn-warning.btn-warning="dbitec.data.qryitec[0].certificate_status = 2" dmx-class:btn-success.btn-success="dbitec.data.qryitec[0].certificate_status = 1">

They should only be entered once, like:

dmx-class:btn-danger="..."

I also see your expression is wrong:

"dbitec.data.qryitec[0].certificate_status = 3"

must be:

"dbitec.data.qryitec[0].certificate_status == 3"

i.e. the right expression for equals to is ==

it is working… thks

1 Like

Please see my last reply :slight_smile: