【发布时间】:2020-04-11 19:01:53
【问题描述】:
我试图在带有粘性标题的表格上实现水平滚动条,问题是当我实现粘性时滚动条没有出现。它只能通过触控板而不是鼠标滚动。我使用 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;
}
它显示滚动条,但我丢失了粘性标题
【问题讨论】: