简体   繁体   English

PrimeNG - 粘性 header 在 p 表中不起作用

[英]PrimeNG - Sticky header not working in p-table

Hello I am using PrimeNG p-table which has both horizontal scroll and vertical scroll.您好,我正在使用同时具有水平滚动和垂直滚动的 PrimeNG p-table。 I want to use sticky header for the table for which I have tried following 2 methods -我想对我尝试过以下两种方法的表使用粘性 header -

[scrollable]="true"
scrollHeight="350px"

This one is making header sticky but column width is getting changed automatically, removes the horizontal scroll and trying to fit complete table in browser page width due to which columns data are overlapping with each other.这使得 header 具有粘性,但列宽会自动更改,移除水平滚动并尝试在浏览器页面宽度中调整完整表格,因为列数据相互重叠。

Another method I tried is using css -我尝试的另一种方法是使用 css -

:host ::ng-deep .ui-table-scrollable-header{
  position: sticky;
  position: -webkit-sticky;
  top: 0;
  z-index: 1000;
}

But this code has having no effect on my UI.但是这段代码对我的 UI 没有影响。

Can any body help me in fixing this?任何机构都可以帮我解决这个问题吗? Below is my p-table code and all my columns are of variable length.下面是我的 p 表代码,我所有的列都是可变长度的。

<p-table #dt [columns]="cols" [value]="data" [paginator]="true" dataKey="id" editMode="row" [rows]="25"
    [rowsPerPageOptions]="[10,25,50,75,100]" [autoLayout]='true' sortMode="multiple"
    selectionMode="multiple" [(selection)]="selected">

Have you seen this primeNg page ?你看过这个primeNg页面吗? They have implementation examples with sticky headers.他们有带有粘性标题的实现示例。 You may need to set the width to a hard-coded value to prevent the auto-resizing of the columns, but the sticky header comes built in.您可能需要将宽度设置为硬编码值以防止自动调整列的大小,但内置的粘性 header 是内置的。

PrimeNg example: PrimeNg 示例:

    <p-table [value]="customers" [scrollable]="true" [style]="{width:'600px'}" scrollHeight="200px">
        <ng-template pTemplate="colgroup" let-columns>
            <colgroup>
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
                <col style="width:250px">
            </colgroup>
        </ng-template>
        <ng-template pTemplate="header">
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Country</th>
                <th>Date</th>
                <th>Company</th>
                <th>Status</th>
                <th>Activity</th>
                <th>Representative</th>
            </tr>
        </ng-template>
        <ng-template pTemplate="body" let-customer>
            <tr>
                <td>{{customer.id}}</td>
                <td>{{customer.name}}</td>
                <td>{{customer.country.name}}</td>
                <td>{{customer.date}}</td>
                <td>{{customer.company}}</td>
                <td>{{customer.status}}</td>
                <td>{{customer.activity}}</td>
                <td>{{customer.representative.name}}</td>
            </tr>
        </ng-template>
    </p-table>

I also just ran into this problem, after some digging into the cause of it I ended up opening an issue where I give my take on the problem, perhaps they'll eventually make some changes on the way scrollable works https://github.com/primefaces/primeng/issues/11099我也刚刚遇到了这个问题,在深入研究了它的原因之后,我最终打开了一个问题,我对这个问题给出了看法,也许他们最终会对可滚动的工作方式进行一些更改https://github。 com/primefaces/primeng/issues/11099

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

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