gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:59:41 29 4
gpt4 key购买 nike

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

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

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

</p-table>

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

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];
}

有什么想法吗?谢谢!

最佳答案

更新: 添加 demo

你只需要使用javascript

$('.ui-table-scrollable-body').scrollTop($('.ui-table-scrollable-body')[0].scrollHeight);

或动画:

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

没有jquery:

TS:

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

HTML:

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

关于angular - 如何滚动到 PrimeNG TurboTable 组件的最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54094753/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com