Select to view content in your preferred language

Modify List Element Background Color w/ Arcade Advanced Formatting

1685
4
04-10-2023 07:12 AM
Labels (1)
ZacharyStanley
Occasional Contributor

Hello,

I'm trying to using a single when statement to change the background color of a list element. My arcade returns no errors but work as expected. Here's my code sample:

var co = IIF($datapoint.CleanoutNeeded == 'Yes', "Cleanout Needed", "");
var cb = IIF($datapoint.CBMarkerNeeded == 'Yes', "CB Marker Needed", "");
var id = IIF($datapoint.IllicitDischarge == 'Yes', "Illicit Discharge", "");
var sd = IIF($datapoint.StructuralDamage == 'Yes', "Structural Damage", "");
var other = IIF($datapoint.OtherIssues == 'Yes', "Other Issues - see data", "");
var color = When(
        $datapoint.IllicitDischarge  == 'Yes', "#b51963",
        $datapoint.CleanoutNeeded == 'Yes', "#c44601", '')



return {
  textColor: '',
  backgroundColor: '',
    attributes: {
        attribute1: color
   },
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     co: co,
     cb: cb,
     id: id,
     sd: sd,
     other: other
   }
}

 Any ideas?

Thanks,

Zac

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Set backgroundColor color directly. You have added some additional unnecessary attributes

return {
  textColor: '',
  backgroundColor: color,
  separatorColor:'',
  selectionColor: '',

 

0 Kudos
ZacharyStanley
Occasional Contributor

Thank you! That approach works fine but I actually want to change the individual elements of the background color as show in this image:

ListElement.jpg

Any ideas?

0 Kudos
JenniferAcunto
Esri Regular Contributor

It sounds like you want to change the background color of your font. You would need to use HTML to do that along with your Arcade. Add your color to the rest of the attributes instead of trying to force it into the background color section of your return statement. Then in the rich text editor for your list, add a background font color to the desired text element. It doesn't matter what color you pick.

JenniferAcunto_2-1681145685752.png

 

Then go into the source to view the HTML, replace the hex code in the HTML with your Arcade color attribute. 

JenniferAcunto_1-1681145601208.png

 

This post walks you through how to do this for a table background, but the general process is the same. 

- Jen
ZacharyStanley
Occasional Contributor

Thanks @JenniferAcunto this is exactly wheat I needed.

0 Kudos