1

Assume I have a Datatable with 1000 rows, and it displays nicely with scrollbars. I would like to programmatically scroll to a specified row so that this specified row appears as the first row of my table, giving me the ability to scroll upwards or downwards from this row. Note that the entire table is loaded into memory.

Is there any way to accomplish this in Vue 3?

1 Answer 1

0

First, in your template add an ID to each row.

<tr v-for="(i, count) in arr" :key="i.id" :id="`id${count}`">
    <!-- YOUR ROW'S <td> TAGS -->
</tr>

Then in your javascript, you need to figure out where to scroll. Assuming you want to just scroll vertically you can find where to scroll based on the ID.

ScrollToID(recordNum){
    const ScrollToRow = window.scrollY + document.querySelector(`id${recordNum}`).getBoundingClientRect().top
    window.scrollTo({
      top: ScrollToRow,
      left: 0,
      behavior: 'smooth'
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.