Hi, I am having trouble auto scrolling using the Table Element.
In my scenario a user will populate data entries which then appear in a table. As more entries are submitted the table will reach its max height and vertical scrolling will become available.
As the latest entries are the most important I want the focus of the table to always be on the last element.
Is there a way to auto focus/auto scroll to the last element in the table?
Ok I have played around a lot more and figured a few things out.
I had to enable ID Attributes in the general settings
added a unique ID for my table to reference
I had to swap from document.querySelector(“table-id”);
to document.getElementById(“table-id”);
Now the issue i have is that when the user triggers the workflow to call the javascript function the scroll does not go all the way down. It will sit one table row element off the bottom.
I tried to manually add height to the scroll top table.scrollTop = table.scrollHeight+200;
But this didn’t work.
@Dibbsie okay great, I’m glad you’re making progress.
So try adding a delay. This is a quick thing you can try and will see quickly if it works or not. By adding a small delay before attempting to scroll this ensures all new rows are fully rendered before the scroll action is executed.
Adding Delay: The setTimeout function introduces a slight delay, ensuring that the new row is fully rendered before scrolling.
Scrolling Action: After the delay, the table is scrolled to the bottom by setting table.scrollTop to table.scrollHeight.
<script>
function scrollToBottom() {
var table = document.querySelector(".your-table-class");
if (table) {
setTimeout(function() {
table.scrollTop = table.scrollHeight;
}, 100); // Adjust the timeout as needed
}
}
</script>
Thanks @llloyd
I think that has done the trick.
Occasionally the delay doesn’t work in testing but mostly its fine.
I will tweak the timeout more down the track.