如何滚动到 PrimeNG TurboTable 组件的最后一行

Fel*_*Fel 0 primeng angular primeng-turbotable

我在 Angular 7 应用程序上使用 PrimeNG TurboTable 组件,并且有一个按钮可以向其中添加新行。问题是,当添加新行时,用户必须向下滚动到表格底部才能开始编辑它。我怎么能滚动到它?

这就是我在模板中定义表格的方式:

<p-table [value]="gridOptions" [scrollable]="true" scrollHeight="13em" 
selectionMode="single" [(selection)]="selectedOption" 
(onEditComplete)="onDataChanged($event)"
(onRowReorder)="onDataChanged($event)">
  [ ... ]

</p-table>
Run Code Online (Sandbox Code Playgroud)

这是“添加选项”处理程序:

onAddOption() {
  // This adds a new option to the TurboTable
  this.gridOptions.push({ name: "", arg: "", comment: "", scope: this.scope });

  // I expected that selecting an option would scroll to it, but it doesn't work
  this.selectedOption = this.gridOptions[this.gridOptions.length-1];
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

phu*_*cnh 6

更新:添加演示

你只需要使用 javascript

$('.ui-table-scrollable-body').scrollTop($('.ui-table-scrollable-body')[0].scrollHeight);
Run Code Online (Sandbox Code Playgroud)

或动画:

$(".ui-table-scrollable-body").animate({ scrollTop: $('.ui-table-scrollable-body').prop("scrollHeight")}, 200
Run Code Online (Sandbox Code Playgroud)

没有jQuery:

TS:

scroll(table: Table) {
    let body = table.containerViewChild.nativeElement.getElementsByClassName("ui-table-scrollable-body")[0];
    body.scrollTop = body.scrollHeight;
  }
Run Code Online (Sandbox Code Playgroud)

HTML:

<p-table #table [columns]="cols" [value]="sales" [scrollable]="true" scrollHeight="200px"> ... </p-table>
<button (click)="scroll(table)">Scroll</button>
Run Code Online (Sandbox Code Playgroud)