javascriptlistviewnativescriptnativescript-vuenativescript-telerik-ui

How to scroll down ListView to the bottom of it after button tapping (using scrollToIndex for instance)? NativeScript-Vue


Maybe it seems to be an easy task, but I don't really know how to solve it.

I have a ListView component in my NativeScript-vue application. And I need the ListView to scroll down to the end of it after I've tapped on a button.

I tried this:

<ListView ref="listViewEl" for="item in items">
<TextView :text="item.value"></TextView>
</ListView>
...

tappingButton() {
    this.$refs.listViewEl.scrollIndexTo(lastIndexScroll);
}

But it doesn't work and I recieve an error:

this.$refs.listViewEl.scrollToIndex is not a function.

It also doesn't work for other methods like "scrollTo, smoothScrollToPosition, scrollToVerticalOffset, etc."

What Do I miss?

Thank you in advance.


Solution

  • You are missing .nativeView. In order to access the actual ListView element from the reference, you have to call the .nativeView property.

    tappingButton() {
       this.$refs.listViewEl.nativeView.scrollToIndex(lastIndexScroll);
    }
    

    Also the method name is scrollToIndex