繁体   English   中英

PrimeNg p-table scrollTo() 方法不起作用

[英]PrimeNg p-table scrollTo() method doesnt work

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

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} 作为参数传递,但没有任何反应。

任何帮助将不胜感激!

谢谢

试试这个,这对我有用

const body = this._materialTable.containerViewChild.nativeElement.getElementsByClassName('p-datatable-scrollable-wrapper')[0];
        body?.scrollTo({
            top: 0,
            left: 10,
            behavior: 'smooth'
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM