I have big data on Y coordinate - there is virtual scroll and a lot of items are on the page on scroll. When i click on the data then additional data is displayed for the clicked element. That makes my page unfriendly for users because sometime the additional data is big - and when the additional data is collapsed sometimes scroll automatically goes down and the user needs to scroll a little bit up to see the data...
I need when the user click on the element- automatically page scrolls up or down to that clicked element on the Y coordinate
HTML
<div *ngFor="let mainRow of tableData; let i = index;" class="card" id="mainRow-{{i}}">
<div (click)="renderSubTable(i, mainRow, $event)">
... main data
</div>
<div *ngIf="mainRow.subTableData">
... additional data
</div>
</div>
** what i tried** TS
i tried with offsetY
renderSubTable(numRow, mainRow, event) {
let y = pos.offsetY;
window.scroll(0,y);
}
but that takes only the Y coordinates of the viewport - not on the whole page. PageY does not work also.
How can i resolve my issue
jQuery offset gives you the absolute position (relative to the document):
Here is a code snippet for Angular
Template
Controller
You can test it on Stackblitz