Passing a parameter between a table cell and a modal

Here's what I'm trying to do

  1. I have an app where there is a table called items with 3 columns, id, price, and description
    2.When someone clicks on the description of a row in that table, I want a modal called RequestDetailModal to open that has a table that shows all of the requests for that item.

I am almost there, but can't figure out the last bit

  1. I have created a query show_item_requests that populates the table in the modal
  2. I have set it up so that the WHERE statement in the show_item_requests is looking for the parameter {{description}}
WHERE
  description = {{description}}
  1. I have set up the event handler in the modal so that when the modal opens, it runs a script that triggers the query. For now I hard coded the parameter value, and when I change it manually it returns the correct rows
show_item_requests.trigger({
  additionalScope : {
    desription:'Bright Pink Shoelaces'}  
});
  1. In the app, I put an event handler on the Description column in the table that also runs a script that opens the modal correctly
RequestsDetailModal.show()

When I click on the Description column in a row in the table in the App, it correctly opens RequestsDetailModal and returns the data from show_item_requests. For now, it's just filtered for the hard coded value I put into the script in the modal, but I'd like it to filter for the cell I clicked on in the table in the App.

What I can't figure out is how to make it so that RequestsDetailModal.show() passes the parameter from the selected cell to the script in the modal.

Any help would be greatly appreciated!

When they click the description, I think currentSourceRow.Description should have the description they click that you can pass as the parameter to show_item_requests.

Thanks! Yes, I've been trying that, but I seem to be doing something wrong, and am wondering if I'm just confused about the syntax. I feel like this should work, but as soon as I replace the hard coded value in the trigger() statement, the query returns "No results found"

Here is what I have in the javascript in the main table

const description= currentRow.description;
RequestsDetailModel.show();

And here is what I have in the query trigger in the Modal

show_item_requests.trigger({
  additionalScope: {
    description: {{description}}
  }
});

I think I'm doing something wrong in script in the app, but can't figure out what.

I don't think const description= currentRow.description; is carrying through to the modal query (that variable is probably only valid in the event).

Can you try setting the modal trigger to

show_item_requests.trigger({
  additionalScope: {
    description: table1.selectedRow.description //table1 is whatever your table name is
  }
});

If that doesn't work or you don't like relying on the selection in a row of the table, another approach might be to set a variable and update your table event code to:

const description= currentRow.description;
await variable1.setValue(description); //set the state variable
RequestsDetailModel.show();

Then update your modal trigger to:

show_item_requests.trigger({
  additionalScope: {
    description: variable1.value
  }
});
3 Likes

The second approach worked!

Thank you!