Getting a value from a local table

I am in a local table called table1.
The user puts an X in the Extra4 field of table1. The table has a unique row number in row7.
I would like to know how to put the value of row7 where Extra4 = "X" into local storage with a name of mrow7.
How I do this?

1 Like

Hey @mdsmith1

You can use Retool’s localStorage function to store the value:
localStorage.setValue('name', 'JOY')

Once the value is stored, you can access it anywhere in your app using:
localStorage.values

Widle:

I need something that has terminology like "where Extra4 = "X". I don't think this is possible with Java Script.

Anyway, I have found a work around where I using the "selected" term which allows me to deal with the cases one at a time.

So I am OK.

Mike

1 Like

Hi @mdsmith1, sounds like you have found a good workaround for what you are trying to achieve!

I believe you can use Javascript to find the rows in the table1 data array and store the value(s):

// Find the row where Extra4 = "X"
const match = table1.data.find(row => row.Extra4 === "X");

if (match) {
  localStorage.setValue('mrow7', match.row7);
}

table1.data should be an array of row objects, so using the JS method .find() (or .filter() if more than one row has Extra4 = "X") allows you to filter arrays based on a certain condition.

You could also trigger this from an event handler on the table (e.g. on row update) so it runs automatically instead of needing a manual selection step.

Just leaving this here in case you decide to try Javascript down the road :slight_smile:

-Jen

1 Like