Difficulty Passing Row Values from a Multi-Select Table

My table has row-level action buttons. One of them opens a modal containing a form. Traditionally, I had a number of form values pre-populate with 'selectedRow' values.

Now, with multi-select enabled, 'selectedRow' doesn't work, and it appears that the appearance of the modal eliminates the possibility of using 'currentRow' values.

I've tried passing the values to variables on click, but from what I can observe the modal's appearance again clears the currentRow values before anything can be stored.

Am I interpreting this issue correctly? If so, I'm looking to see how members of this community would tackle a similar challenge as efficiently as possible.

Note, I did ask a similar question in the below thread, but the challenge was different and solved by a community member so I wanted to open another discussion as this issue would ostensibly have a different solution.

Ok you have 2 options depending on what you want:

Option 1

Use when:

Upon clicking a row's action button, you want to deselect previously selected rows as well.

Steps:

  1. In your table's inspector, click the 3-dot-menu of the Interaction section
  2. Set "On Action click" to "Replace the selection"
  3. In your modal frame use table1.selectedRow to access data

Option 2

Use when:

Upon clicking a row's action button, you want to add that row to selected rows (if not already selected)

Steps:

  1. In your table's inspector, click the 3-dot-menu of the Interaction section
  2. Set "On Action click" to "Add the row to the selection"
  3. Introduce a temporary state called selectedRowForAbcRowAction
  4. In your table's relevant row action add 2nd event "Set variable" that set's the value of selectedRowForAbcRowAction to `{{currentRow}}
  5. In your modal frame use selectedRowForAbcRowAction.value to access data

Watch-out (re. option 2):

When considering this option, you might think that in order to access the row's data, instead of introducing a temporary state we can simply use table1.selectedRow or table1.selectedRows[table1.selectedRows.length-1] but you'll notice that this method fails when you click the row action of a previously selected row.


Hope this helps.
Abdul Wasae
Toolshed - Hire Retool Developers

1 Like

Hi @pod2,

@Toolshed 's suggestions should work, but if you want to keep your selection, you can set a variable in the action handler and then display the modal, like this:

image

You can see the first even handler on the action sets variable2 and then toggles modalFrame1 to show. Within the modal, I can now access all the data from the row that was clicked by referencing variable2.value

You can use currentRow or currentSourceRow depending on your needs, they are both available in the setValue action.

1 Like

Correct. This is "Option 2" already in my original answer. :slight_smile:

Sorry - I just skimmed it and read the watch-out which was talking about the selected rows, 100% correct, you've covered off the same suggestion.

1 Like

Hi all,

Thanks a ton for taking the time to provide these approaches. Using the 'Replace the selection' worked well for our use case.

As always, we appreciate the knowledge and assistance from the community here.

2 Likes