Type Script function to scroll to specific table index

753 Views Asked by At

I need help to write a function in type script,so that i can scroll to specific index in material table.

Lets say i have 100 rows in my table showing 10 items at a time. If i provide input as 50, table should be scrolled upto row no. 50.

I am using type script with my angular html code.

1

There are 1 best solutions below

5
zainhassan On

You can get all rows of table as array and then scroll to specific row by using index

const rows = document.getElementsByClassName("mat-row cdk-row");
rows[50].scrollIntoView();

Or you can use query selector

document.querySelectorAll(".custom-table .mat-row");

Here custom-table is your table custom class name. This way you can get specific table rows if you have multiple tables on a page