1

我正在尝试使 p-table 滚动条滚动到某个位置。它似乎根本没有做任何事情。这是我的代码:

ngAfterViewInit(): void {
    this.table.scrollTo({'top': 200})
}

“this.table”是

@ViewChild('dt', {static: false}) public table: Table;

在模板文件中它是这样定义的:

<p-table #dt
   [value]="items"
   class="ui-rtl"
   [styleClass]="styleClass"
   [scrollable]="true"
   [columns]="columns"
   scrollHeight="790px"
   dir="rtl">

忽略硬编码的数字,我现在只是想弄清楚如何让它工作。

有谁知道如何使用它?文档说:

options.top:指定沿 Y 轴的像素数

我试图将 {'options.top':200} 和 {top:200} 作为参数传递,但没有任何反应。

任何帮助将不胜感激!

谢谢

4

1 回答 1

0

试试这个,这对我有用

const body = this._materialTable.containerViewChild.nativeElement.getElementsByClassName('p-datatable-scrollable-wrapper')[0];
        body?.scrollTo({
            top: 0,
            left: 10,
            behavior: 'smooth'
        });
于 2021-12-13T11:26:12.947 回答