How to use icon dynamically?

I want to use different prefix icon for admin and user in a table column but the following js doesn't work; gives an array.
Screenshot 2023-12-18 160108

without knowing the structure of your data, I am taking a guess here:[i] or[i].user_type

1 Like

Hello, you can try

currentRow.user_type === "Admin" ? "icon" : "icon"

An alternative:
You can define tag by tag the icons in Add-ons > Option list

1 Like

you say: gives an array.

but the code says is a string.

If it is actually an array (I'd assume so that a user could have more than one 'type' or 'role') then you need to check all the items in the array. As your code stands right now you're comparing with typeof Array to "Admin" with typeof String. The comparison will always be false, which is why the mapped array in your screenshot shows 3 icons for the false condition of the ternary operator.

I believe what you are looking for:
{{"Admin") ? admin_icon : user_icon }}

if this doesn't help, I'd suggest taking a look at @ScottR's answer and possibly using it with this one.

1 Like

currentSourceRow.user_type should work actually

alternative solution


Second solution works for me. Thank You!

1 Like