Scroll to component from dynamic list

Hello, No-Coders.

Today we figure out how to scroll to components from a dynamic list.

How does scrolling work? We get the Scroll To Component block and connect to it another block that represents the component you want to scroll to.

image

But when we try to scroll to a component from Dynamic List, we can’t choose a specific one, because each dynamic block is the same in Codeless Logic.

So we have a question: How to get a certain component from the dynamic list?

Let’s imagine we have a pretty simple UI with a list of articles. For example, a Select component where we can choose an article and a Button that scrolls the page to the selected article.

:one: Create a Block with some Id and Dynamic List Behaviour

This logic shows how I set records to dynamic list, but you can use any other kind of data(for example database records), and set them to dynamic list anywhere. Only one thing is very important now - your dynamic list must have an object with a unique value that helps to identify this item in the list (the objectId value works well for this purpose)


For our convenience, I will name the records variable to original list

:two: Add some dynamic content for dynamic items inside the container block

And now we have the most confusing place in the entire guide

image

What happened here?

  • We get a unique value from our dynamic list item and use is as the key.
  • We get a component object and use is as the value.
  • We save this pair somewhere, for example, in Page Data.

Now, we can get any component object anywhere where we want, one thing that we should know - is a unique value from original list

:three: And details for Select and Button that helps us to navigate.

Select logic:
image

Button logic:
image

Nothing hard here, we just use a dynamic list to create options for Select
And when some value has been chosen, we call Scroll to component function on the block, previously stored in Page Data, and taken here using the unique value from the dynamic list.

I hope we made one more thing clear for you. But if you still have any questions, you are welcome!

Confusing because of the incorporation of the Select action… I generally get the idea, but might you describe a more simple example? We have a block (overflow: scroll) that contains a long list of dynamic items. When the block mounts, we would like the user to be scrolled within the block such that one of the items is visible at the top.

Our particular scenario is that our repeater contains buttons that show all times between midnight and midnight in 15 minute intervals… a person can select any time, but we would like “9:00am” to be the first thing they see, instead of “0:00am” and having to scroll down a bunch. How to do?

Hello @Alex_Klein!

This solution can also be adapted for your needs with some minor adjustments.
The key change you’ll need to make is not to use a uuid, but instead, an identifier that you know, to enable scrolling to that component.
And the scrolling can be added in the onPageEnter handler.
Here is an example of how this can be implemented:




I hope this has helped you.

Regards,
Alexander

Brilliant, works great. We’re not using Page Data but the data model in a Modal (where our scrollable block lives), but still works perfectly. Thank you so much! :heart_eyes:

1 Like