Why is it so hard to set different row color in tables?

Hi, guys,

When I try to set different colors on my table using the feature "Row color", I always have a hard time. I don't know much about javascript, but so far I've always been able to handle retool stuff.

I never know if I should use '==', '=' or '==='. Sometimes it works with 2 equals other times with 3 equals. Now I am trying to understand what I am doing wrong to set the color of my table:

Everytime the number of SMS sent is zero and numb_hk higher than 3, then the row color should be red ('#ba6565') and when it doesn't meet the criteria, then it should be grey. Now all rows are grey, despite having the column 'SMS sent' as zero. Why??

I've just made another test and when I set the criteria to be numb_hk higher than 3 it changes color. What is wrong with ==0?

Hey @Bruna_Tourinho

To answer the = / == / === question first:
=: value setting operator. this won't work in line to change values in your table
==: loose equality operator: this will attempt to convert values to be the same type before making the comparison (and might be the issue in your case)
===: strict equality operator: will not convert types but use them as seen.

For your row color issue, how is the sms_sent field stored in your DB?

Hey @Bruna_Tourinho,

So:

  • == checks value only (allows type conversion).
  • === checks both value and type (strict comparison).

In your case, currentRow.sms_sent might not be a number but a string ("0" instead of 0). Try explicitly converting it:

{{ parseInt(currentRow.sms_sent) === 0 && currentRow.numb_hk > 3 ? "#ba6565" : "grey" }}

Hope this helps

2 Likes

Hi, guys,

Thank you for the explanation! Really helpful.

As suggested, I was investigating how it was stored and maybe this is the issue, but there is a strange behavior that happens with JSON SQL.

So my data source is a JSON SQL query, I am making left join between PostgreSQL tables and here I believe it may have a problem. Those zeros means that one of my PostgreSQL queries do not return values for this metric, so the count(distinct) is zero.

image

The color setting just worked when I used =='0' (It doesn't work for ==='0', though). Funny thing is that despite using count(distinct) it doesn't filter the JSON SQL when I use HAVING clause after a group by.

Not sure if any of you have an explanation for this JSON SQL "issue". Would be nice to know, but color row problem is solved. Thank you for the help, guys!

2 Likes

Is the zero a string in one table but a number in other table?