Can't get a table to focus on the last row on return

I have a table which is indexed on row1.
I have the default index of the table as {{localStorage.values.mIndex}}.
I focus on a particular row and I store row1 of that row to localStorage with the code:
localStorage.setValue ('mIndex', table1.selectedRow.row1);

I check in the debugger and mIndex is saving fine. mIndex is 44.

OK, I leave the table and then come back to it. When I return there is no selected row.

I would like the table to focus or select where row1 = 44 when I return.

Is there a way of doing that?

Mike

Summary

A table is indexed on a 'row1' column and the selected row's row1 value (e.g. 44) is saved to localStorage; on returning to the table, setting the Default row to {{localStorage.values.mIndex}} does not re-select/focus that row.

AI Response

The Default selected row setting expects a positional row index (0-based), not a stored column value like 44, which is why passing mIndex directly doesn't match. Instead, compute the index by finding where the column value equals the stored value, e.g. set the default row to {{ table1.data.findIndex(r => r.row1 == localStorage.values.mIndex) }}. Alternatively, on the table's data load, run table1.selectRow({ mode: 'key', key: localStorage.values.mIndex }) to select by matching value rather than position.

Sources

:bookmark: Select row of table based on table data property
Covers selecting a table row by a data property/ID value rather than by numeric index, matching the goal of re-selecting the row where row1 equals the stored value.
:bookmark: How to Select Table rows programatically?
Solved thread showing how to programmatically select rows with table.selectRow(), which can be triggered on load to focus the stored row.

The Community Team is testing out a new automation. Let us know if it's helpful (or not) by leaving a :heart:, :+1:, or :-1:. Or by marking this post as the "Solution"! Let us know if you have any feedback here. :rocket:

Hey @mdsmith1 - can you clarify what leaving the table and coming back to it means in this context? Are you closing the app and reopening it at a later point in time? Secondly, are you setting the default row by Key or Index?

Hi Darrel:
I figured this one out. Normally I would come back to the forum and report this sort of thing but for the last 6 months I have not been able to get back into the forum unless someone replies to me.

Here's what I found, there is a delay between the time something is put in storage and when it is officially there.

await GetRowIndex7.trigger();  // this puts the row number in storage as mR1
await new Promise(resolve => setTimeout(resolve, 1000));
await GetDate16.trigger(); // this gets the value of the date in the selected row

So I have introduced a delay of 1000 ms between the time I store and the time I retrieve.

This seems to have solved my problem.

Mike

Using await should typically guarantee synchronous execution, but I'm glad you found a solution!

Darren:
I started at 500 ms. The code did not work until I got to 1000 ms.
One issue could be the distance from my computer to your server.
I think your server is in California. I am in Ontario, Canada.
This may be a factor.
Mike