我试图在带有粘性标题的表格上实现水平滚动条,问题是当我实现粘性时滚动条没有出现。它只能通过触控板滚动,而不能通过鼠标滚动。即时通讯使用ng2智能表格进行角度显示
<ng2-smart-table
*ngIf="showMainTable"
[settings]="settings"
[source]="localDataSource"
(edit)="rowEdited($event, 'edit')"
(editConfirm)="rowEdited($event, 'editConfirm')"
></ng2-smart-table>
样式
:host /deep/ ng2-smart-table table tr td:first-child {
position: sticky;
left: 0;
z-index: 1;
background: white !important;
// box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
border-left: none !important;
border-right: none !important;
border-top: none !important;
border-bottom: solid 1px #f4f2f0 !important;
box-shadow: 10px 0 10px -2px rgb(245, 241, 241) !important;
}
:host /deep/ ng2-smart-table table tr th:first-child {
position: sticky;
left: 0;
width: 100px;
z-index: 2;
background: white !important;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
:host /deep/ ng2-smart-table table tr th:first-child {
z-index: 2;
background: white !important;
}
:host /deep/ ng2-smart-table table thead tr {
position: sticky;
white-space: nowrap;
padding: 10px 40px !important;
top: 0;
background: white !important;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
:host /deep/ ng2-smart-table table thead th {
position: sticky;
top: 0;
background: white !important;
border: none;
color: #ccc;
cursor: pointer;
white-space: nowrap;
padding: 0;
height: 56px;
padding-left: 56px;
vertical-align: middle;
outline: none !important;
color: rgba(0, 0, 0, 0.54);
font-size: 12px;
font-weight: 500;
}
:host /deep/ ng2-smart-table table tr:nth-child(1) th {
// display: inline-flex !important;
white-space: nowrap;
padding: 10px 40px !important;
}
:host /deep/ .ng2-smart-sort-link {
// display: inline-flex !important;
color: rgba(0, 0, 0, 0.54) !important;
font-size: 12px !important;
font-weight: 500 !important;
text-transform: uppercase;
}
:host /deep/ ng2-smart-table table tbody {
// overflow: hidden;
}
:host /deep/ ng2-smart-table table {
border: none;
}
:host /deep/ ng2-smart-table table tr td {
// display: inline-flex !important;
text-align: center !important;
height: 48px;
padding: 0 0 0 56px;
height: 48px;
font-size: 1.2rem;
font-weight: 300;
color: #111;
white-space: nowrap;
// overflow: hidden;
text-overflow: ellipsis;
border-left: none !important;
border-right: none !important;
border-top: none !important;
border-bottom: solid 1px #f4f2f0 !important;
}
host和deep是角度选择器,它将样式应用于该表生成的表 我将表格包装在一个容器中,并且能够实现滚动功能,但是表格失去了粘性。我希望标题为粘性,表格在底部始终具有固定的水平滚动条,该滚动条始终可见。
我将桌子包装在容器中
<div
class="table-flow"
[ngClass]="{ 'disable-cover': mainTableLoading }"
>
<ng2-smart-table
*ngIf="showMainTable"
[settings]="settings"
[source]="localDataSource"
(edit)="rowEdited($event, 'edit')"
(editConfirm)="rowEdited($event, 'editConfirm')"
></ng2-smart-table>
</div>
样式
.table-flow {
overflow-x: scroll;
}
它显示滚动条,但我丢失了粘性标题
Codesandbox链接https://codesandbox.io/s/elastic-satoshi-7ycxm
答案 0 :(得分:1)
我已通过为容器提供固定的最大高度来解决此问题,这样它将具有粘性标头和滚动功能。
.table-flow {
max-height: 555px;
overflow-x: scroll;
max-width: auto;
position: relative;
}
答案 1 :(得分:0)
您的表流需要为position:relative atleast,您需要将其最大宽度设置为例如100%,然后将overflow设置为:auto :)
答案 2 :(得分:0)
HTML
<div class="table-container">
<ng2-smart-table
[settings]="settings"
[source]="source"
></ng2-smart-table>
</div>
CSS
.table-container {
height: 600px;
overflow-y: auto;
border-top: 1px solid #dee2e6;
}
::ng-deep table tr:first-child th {
position: sticky !important;
top: -1px;
z-index: 100;
background: white;
border: 1px solid #dee2e6;
height: 58px;
}