Sticky header 无法在 Primeng 中使用可调整大小的列。?
Sticky header not working with resizable column in Primeng.?
我正在尝试实现这两个 column resize and stick header。但是如果我不使用列调整大小,sticky header 可以正常工作。如果我同时实现两者,则列调整大小有效但粘性 header 无效。
我使用了来自 primeng 的以下 css 作为粘性 header。
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky;
top: 70px;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
top: 100px;
}
}
对于列大小调整,我使用了以下代码,[resizableColumns]="true"
、pResizableColumn
<p-table [columns]="cols" [value]="cars1" [resizableColumns]="true">
...
<th *ngFor="let col of columns" pResizableColumn>
如果我删除 resizbleColumns
和 pResizableColumn
粘性 header 工作正常。我怎样才能让它同时起作用。?这是 stackblitz and Demo
当您将 p-table 列设置为可调整大小时,添加一个 class ui-table-resizable
这将重置其某些 css 属性 之一th
相对的位置,所以你将失去粘性 future
这应该可以解决问题
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
:host ::ng-deep .ui-table-resizable > .ui-table-wrapper {
overflow-x: initial !important;
}
:host ::ng-deep .ui-table-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
top: 0px;
}
}
已更新!
添加组件装饰器中的样式是不可重用的,primeng主题的基础推荐创建自定义样式我们可以这样做
style.scss
.sticky-table {
&.ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky !important;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
&.ui-table-resizable > .ui-table-wrapper {
overflow-x: initial !important;
}
&.ui-table-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
.ui-table .ui-table-thead > tr > th {
top: 0px;
}
}
}
模板
<p-table styleClass="sticky-table" [columns]="cols" [value]="cars [resizableColumns]="true">
....
</p-table>
任何可能仍然感兴趣的人:
对我来说,只需添加以下内容就可以了
:host ::ng-deep .p-datatable .p-datatable-wrapper {
overflow-x: initial;
}
Resizable-Fatures 添加了“overflow-x: auto”到 table,它隐藏了 stick header。
:host ::ng-deep .p-datatable .p-datatable-thead > tr > th {
position: -webkit-sticky;
position: sticky;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
:host ::ng-deep .p-datatable-resizable > .p-datatable-wrapper {
overflow-x: initial !important;
}
:host ::ng-deep .p-datatable-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .p-datatable .p-datatable-thead > tr > th {
top: 0px;
}
}
请使用以下代码:
<p-table [columns]="cols" [value]="rows" [autoLayout]="true">
我正在尝试实现这两个 column resize and stick header。但是如果我不使用列调整大小,sticky header 可以正常工作。如果我同时实现两者,则列调整大小有效但粘性 header 无效。
我使用了来自 primeng 的以下 css 作为粘性 header。
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky;
top: 70px;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
top: 100px;
}
}
对于列大小调整,我使用了以下代码,[resizableColumns]="true"
、pResizableColumn
<p-table [columns]="cols" [value]="cars1" [resizableColumns]="true">
...
<th *ngFor="let col of columns" pResizableColumn>
如果我删除 resizbleColumns
和 pResizableColumn
粘性 header 工作正常。我怎样才能让它同时起作用。?这是 stackblitz and Demo
当您将 p-table 列设置为可调整大小时,添加一个 class ui-table-resizable
这将重置其某些 css 属性 之一th
相对的位置,所以你将失去粘性 future
这应该可以解决问题
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
:host ::ng-deep .ui-table-resizable > .ui-table-wrapper {
overflow-x: initial !important;
}
:host ::ng-deep .ui-table-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .ui-table .ui-table-thead > tr > th {
top: 0px;
}
}
已更新!
添加组件装饰器中的样式是不可重用的,primeng主题的基础推荐创建自定义样式我们可以这样做
style.scss
.sticky-table {
&.ui-table .ui-table-thead > tr > th {
position: -webkit-sticky;
position: sticky !important;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
&.ui-table-resizable > .ui-table-wrapper {
overflow-x: initial !important;
}
&.ui-table-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
.ui-table .ui-table-thead > tr > th {
top: 0px;
}
}
}
模板
<p-table styleClass="sticky-table" [columns]="cols" [value]="cars [resizableColumns]="true">
....
</p-table>
任何可能仍然感兴趣的人:
对我来说,只需添加以下内容就可以了
:host ::ng-deep .p-datatable .p-datatable-wrapper {
overflow-x: initial;
}
Resizable-Fatures 添加了“overflow-x: auto”到 table,它隐藏了 stick header。
:host ::ng-deep .p-datatable .p-datatable-thead > tr > th {
position: -webkit-sticky;
position: sticky;
background: blue;
color: white;
top: 0px;
z-index: 1;
}
:host ::ng-deep .p-datatable-resizable > .p-datatable-wrapper {
overflow-x: initial !important;
}
:host ::ng-deep .p-datatable-resizable .ui-resizable-column {
position: sticky !important;
}
@media screen and (max-width: 64em) {
:host ::ng-deep .p-datatable .p-datatable-thead > tr > th {
top: 0px;
}
}
请使用以下代码:
<p-table [columns]="cols" [value]="rows" [autoLayout]="true">