我也有这个问题,我只是想出了一个简单的 scss 方法
:host ::ng-deep .p-datatable { .p-datatable-scrollable-wrapper { display: flex; flex-direction: row-reverse; .p-datatable-scrollable-view.p-datatable-unfrozen-view { position: initial; }
您将遇到的唯一问题是,您需要在 td 和 th 上设置高度来归档与标准表相同的布局
所以这是将它移到右侧的部分。现在我有一个快速而肮脏的解决方案。更好的选择是通过指令解决它并使用 throttleTime(rxjs 所以将它包装在一个 observable 中) 以获得更好的性能。
为了相处,您需要在<p-table #table> 上使用#table 作为示例来获取表格本身
之后,您需要在 .ts 文件中获取它。为此,您实现AfterViewInit 以进行进一步编码。你还需要一个@ViewChild('table') table: Table;
然后你需要像这样使用 ngAfterViewInit:
ngAfterViewInit(): void {
(this.table.scrollableViewChild.scrollBodyViewChild.nativeElement as HTMLElement).style.overflowY = 'hidden';
(this.table.scrollableFrozenViewChild.scrollBodyViewChild.nativeElement as HTMLElement).style.overflowY = 'scroll';
(this.table.scrollableFrozenViewChild.scrollBodyViewChild.nativeElement as HTMLElement).addEventListener('scroll', ((e) => (this.table.scrollableViewChild.scrollBodyViewChild.nativeElement as HTMLElement).scrollTop = (e.target as HTMLElement).scrollTop));
}
在这里你也可以更新 freezeTable 的 td 和 th ;) 但正如我所说,请在指令中执行,而不是那样执行 :)
顺便说一下,我对这种错误的格式感到抱歉,我很欣赏更好的格式,谢谢:)
在 PrimeNG V12.0.0 上测试