简体   繁体   English

PrimeNG:滚动时粘贴表格标题

[英]PrimeNG: stick table header while scrolling

I'm using Angular 4 in pair with PrimeNG 4.2.1. 我将Angular 4与PrimeNG 4.2.1结合使用。

I need to stick table header on the screen while scrolling its content. 滚动其内容时,我需要在屏幕上粘贴表格标题。 Here is an example of how it looks like in PrimeNG JSF components , but unfortunately there is nothing like that in Angular DataTable component . 这是一个在PrimeNG JSF组件中的外观示例,但不幸的是,在Angular DataTable组件中却没有类似的外观

I tried to use standard html+css way like it is described here or here but I didn't make it work (I managed to have a scroll bar inside a table, however it brakes the rest of the UI). 我尝试使用此处此处描述的标准html + css方式,但是我没有使它正常工作(我设法在表内设置了滚动条,但它制动了UI的其余部分)。 I tried this solution as well, but it doesn't work. 我也尝试过此解决方案 ,但是它不起作用。

Q: Is there some way to make PrimeNG DataTable component header fixed while scrolling? 问:有什么方法可以使滚动时固定PrimeNG DataTable组件标头?

I guess the solution might be simple, but I'm not expert in frontend technologies. 我想解决方案可能很简单,但是我不是前端技术专家。

UPDATE: There is a possibility to set scrollable and scrollHeight on the DataTable component so scroll bar appears automatically. 更新:可以在DataTable组件上设置scrollablescrollHeight ,以便自动显示滚动条。 It works well, however I can't manage to set table size to feet the screen, otherwise it looks ugly. 它运作良好,但是我无法将表格大小设置为屏幕的一英尺,否则看起来很难看。

Here is a link to PrimeNg documentation for data tables. 是数据表的PrimeNg文档的链接。 You can find here some examples for several scrollable tables options and the code changes you need to apply. 您可以在此处找到一些可滚动表格选项的示例,以及需要应用的代码更改。

The easiest implementation would be to use 最简单的实现是使用

<p-table [columns]="cols" [value]="value" [scrollable]="true" scrollHeight="200px">

(You might need to upgrade your PrimeNG version for that to work). (您可能需要升级PrimeNG版本才能工作)。 Is that what you are looking for? 那是您要找的东西吗?

As Mentioned in Update , you should use "[scrollable]="true" scrollHeight="200px"". 如Update所述,您应该使用“ [scrollable] =” true“ scrollHeight =” 200px“”。 Set scrollheight according to your need. 根据需要设置滚动高度。

One More thing you can use position: sticky for you header and set the desired "top". 您还可以使用位置的另一件事:为标题设置粘性并设置所需的“顶部”。

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

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