Drop down using tag on a table component - selected value not detected

Hi!

I have a table component on which I have a column with a dropdown using tag called changeRole. I have 3 values in a dropdown. When I select a value i would expect to get that value inside {{ table1.selectedRow.changeRole }} but the value is never picked up and i'm getting undefined. Please see attached screenshots of my setup. Any ideas what am i doing wrong?

Thank you for the help!


1 Like

Hi @Talita,

Welcome to the community!

The issue you're experiencing is likely due to the way you're attempting to access the selected value from the dropdown. The {{ table1.selectedRow.changeRole }} expression is attempting to access the value of the changeRole property directly from the selectedRow object. However, since the changeRole property is a dropdown, it's not stored directly on the selectedRow object. Instead, it's stored within the rowActions array.

To access the selected value of the dropdown, you need to use the .value property of the selectedRow object within the rowActions array. Here's the correct expression:

{{ table1.selectedRow.rowActions[0].value }}

This expression will access the value of the first rowAction object, which is where the changeRole dropdown is stored. If you have multiple rowActions, you'll need to use the index of the rowAction that corresponds to the changeRole dropdown.

Please note that this code is untested, but I hope it helps you get started.

:grinning:

Patrick

Thank you so much for quick reply!

I actually couldn't find {{ table1.selectedRow.rowActions[0].value }}, maybe is Retool version, i'm using Retool 3.20.0.

What i did find instead is {{ table1.changesetArray[numeric_key].changeRole }} and {{ table1.changesetObject[row_primary_key].changeRole }}.

First one, i couldn't help with, because it starts up empty and populates dynamically when i select values from dropdown on different rows, meaning arrays numeric index does not match with the selected row index.

Second one tho, starts up full, and array key matches with my row primary key so i was able to do {{ table1.changesetObject[table1.selectedRow.ID].changeRole }} and get the selected value.

Goal achieved. Thank you!

May I ask 2 more questions?

  1. Is there a way to hide dropdown from certain rows? For example, hide dropdown if {{ table1.selectedRow.role == "OWNER" }}. I could only found an a way to hide an entire column on certain row selection.

  2. Is there a way to hide certain values in a dropdown based on condition? For example, if my row has role MEMBER {{ table1.selectedRow.role == "MEMBER" }}, then i want in a drop down just OWNER and ADMIN. -> Found it! :slight_smile: I could use this also for question 1 and make the dropdown empty, but not hide it, which i would prefer.

Thank you for all the help!

Hi @Talita,

To conditionally hide a dropdown based on a condition, you can use the Hidden property of the dropdown component. The Hidden property accepts an expression that evaluates to a boolean value. If the expression evaluates to true, the dropdown will be hidden.

In your case, you could use the following expression to hide the dropdown if the role property of the selected row is OWNER: {{ table1.selectedRow.role == "OWNER" }}

This expression will evaluate to true if the role property of the selected row is equal to "OWNER", and false otherwise. If the expression evaluates to true, the dropdown will be hidden.

To hide certain values in a dropdown based on a condition, you can use the Filter property of the dropdown component. The Filter property accepts an expression that evaluates to an array of values. The dropdown will only display the values that are included in the filtered array.

In your case, you could use the following expression to filter the dropdown to only display the values OWNER and ADMIN if the role property of the selected row is MEMBER : {{ table1.selectedRow.role == "MEMBER" ? ["OWNER", "ADMIN"] : table1.availableRoles }}

This expression will evaluate to an array of values. If the role property of the selected row is MEMBER , the array will contain the values OWNER and ADMIN . Otherwise, the array will contain all of the available roles. The dropdown will only display the values that are included in the filtered array.

:grinning:

Patrick

Ey you get that users list from retool itself?

Hi @agaitan026,

Great question!

Whether or not you can get a list of users from Retool itself depends on whether you are using the cloud-hosted or on-premises version of Retool. If you are using the cloud-hosted version, then you cannot directly access a list of users from Retool itself. This is because the user data is stored in Retool's own database, and Retool does not provide an API for accessing this data.

However, if you are using the on-premises version of Retool, then you can access a list of users from Retool itself. This is because the user data is stored in the database that you configure when you deploy Retool on-premises. You can query this database directly to get a list of users.

Here is an example of how to query the database to get a list of users:

SELECT * FROM users;

This query will return a list of all users in the database. The users table contains the following columns:

  • id: The unique identifier for the user.
  • name: The name of the user.
  • email: The email address of the user.
  • role: The role of the user.

You can use this information to display a list of users in your Retool app.

Hope this helps.

:grinning:

Patrick

1 Like

Got it and what about user creation? Using a retool app workout going to user setting. Im using self hosted

Hi @agaitan026,

As far as I know creating users in a self-hosted Retool app requires accessing the Retool database directly. The process involves executing SQL queries to insert new user records into the users table. However, since Retool doesn't provide a built-in API for user management, you'll need to establish a connection to the database and execute the necessary SQL queries yourself.

:grinning:

Patrick

1 Like

But how will be the query ? So when I execute that i receive invitation. I know its a insert but any special variable i need to send o have in count in the query? Also when changing roles etc theres no documentation? Of which tables i need to insert or only users table

Just wanted to pop in here and see if there are any remaining questions!

@agaitan026 - are you still blocked here? :slight_smile:

1 Like

Im ok now

1 Like