简体   繁体   中英

PrimeNg p-table scrollTo() method doesnt work

I'm trying to make the p-table scrollbar scroll to a certain position. It doesn't seem to do anything at all. Here's my code:

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

"this.table" is

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

and in the template file it is defined this way:

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

Ignore to hard coded numbers, I'm only trying to figure out how to make it work for now.

Does anyone know how to use it? The documentation says:

options.top: Specifies the number of pixels along the Y axis

I have tried to pass as argument both {'options.top':200} and {top:200} but nothing happens.

Any help will be highly appreciated!

Thank you

Try this, this is working for me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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