I am showing my table in the attachment.
It has a default index of 0, so when the table is opened, the focus is on the first row.
But suppose I click on the second row and do some editing. When I am done, it returns focus to the first row.
I would like to find a way of getting the focus to stay on the recently selected row after the editing is complete.
Is there a way of doing this?
Mike
Hey Mike,
As you correctly point out, whenever the query that is used as your table's datasource updates, your table will reset to it's default settings, of which also the index 0 settings.
I would take either of the following approaches:
Variable
- Have a variable, let's say selectedIndex, which has 0 as default value
- Have a selectRow event trigger that updates that variable with the selectedIndex
- Update the default Index value and change it from 0 to the actual variable value, e.g. {{ selectedIndex.value }}.
- As such, even when your table refreshes, the variable's value will not, and so the default index will remain the last value set for the variable
Script
- This one depends on your queries, but you could add all of your logic to one script, where at the beginning you define a constable with your selectedIndex, and add an onSuccess event to the query that resests your table which uses selectRow() with the defined index.
Hope this helps!
1 Like
Miguel:
Thank you for your answer.
I think I get the idea but I still need some help.
I have created a variable on local storage called "mIndex".
I set that as 0 in code that is routing to my master file and that works fine.
Now suppose my first edit is a number of rows down.
So I want to capture the value of the index of that row.
I have tried localStorage.setValue('mIndex',SelectedIndex) but that creates an error.
What is the syntax for capturing the value of the elected Index?
Mike
Hey Mike,
you can use table1.selectedDataIndex, so that would be localStorage.setValue('mIndex',table1.selectedDataIndex)
1 Like
Thank you so much Miguel. It works perfectly.
I will mark you answer as the Solution.
Thanks again.
Mike
1 Like