我有一个 PrimeNg 表,表中的每个元素都有一个扩展行。
展开的行应该包含一个包含数据的表格
这是模板的代码。
<div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
<div class="col-12 text-right mb-2">
<button class="btn btn-primary" (click)="createOrEditLandlordPropertyPortfolioModal.show()">
<i class="fa fa-plus"></i> {{ l('Add') }}
</button>
</div>
<p-table
#dataTable
(onLazyLoad)="getLandlordPropertyPortfolios($event)"
[value]="primengTableHelper.records"
rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
[paginator]="false"
[lazy]="true"
dataKey="id"
[scrollable]="true"
ScrollWidth="100%"
[responsive]="primengTableHelper.isResponsive"
[resizableColumns]="primengTableHelper.resizableColumns"
>
<ng-template pTemplate="header">
<tr>
<th style="width: 20px"></th>
<th style="width: 130px">
{{ l('Actions') }}
</th>
<th style="width: 130px" pSortableColumn="id">
{{ l('Id') }}
<p-sortIcon field="id"></p-sortIcon>
</th>
<th style="width: 150px" pSortableColumn="name">
{{ l('Name') }}
<p-sortIcon field="name"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-record let-expanded="expanded">
<tr>
<td style="width: 10px">
<a [pRowToggler]="record">
<i [ngClass]="expanded ? 'pi pi-chevron-down' : 'pi pi-chevron-right'"></i>
</a>
</td>
<td
style="width: 130px"
[hidden]="
!isGrantedAny(
'Pages.LandlordPropertyPortfolios.Edit',
'Pages.LandlordPropertyPortfolios.Delete'
)
"
>
<div class="btn-group dropdown" dropdown container="body">
<button class="dropdown-toggle btn btn-sm btn-primary" dropdownToggle>
<i class="fa fa-cog"></i><span class="caret"></span> {{ l('Actions') }}
</button>
<ul class="dropdown-menu" *dropdownMenu>
<li>
<a
href="javascript:;"
(click)="createOrEditLandlordPropertyPortfolioModal.show(record.id)"
>{{ l('Edit') }}</a
>
</li>
<li>
<a href="javascript:;" (click)="deleteReasonModal.show(record)">{{ l('Delete') }}</a>
</li>
</ul>
</div>
</td>
<td style="width: 130px">
<span class="ui-column-title"> {{ l('Id') }}</span>
{{ record.id }}
</td>
<td style="width: 150px">
<span class="ui-column-title"> {{ l('Name') }}</span>
{{ record.name }}
</td>
</tr>
</ng-template>
<!--Nested table for property portfolios-->
<ng-template pTemplate="rowexpansion">
<div class="ui-g ui-fluid" style="font-size:16px;padding:20px">
<p-table
#nestedTable
[value]="primengTableHelper.records"
rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
[paginator]="false"
[lazy]="true"
dataKey="id"
[scrollable]="true"
ScrollWidth="100%"
[responsive]="primengTableHelper.isResponsive"
[resizableColumns]="primengTableHelper.resizableColumns"
>
<ng-template pTemplate="header">
<tr>
<th style="width: 130px" pSortableColumn="id">
{{ l('PropertyAddress') }}
<p-sortIcon field="id"></p-sortIcon>
</th>
<th style="width: 150px" pSortableColumn="name">
{{ l('PostalCode') }}
<p-sortIcon field="name"></p-sortIcon>
</th>
<th style="width: 150px" pSortableColumn="name">
{{ l('AgentName') }}
<p-sortIcon field="name"></p-sortIcon>
</th>
<th style="width: 150px" pSortableColumn="name">
{{ l('Tenant') }}
<p-sortIcon field="name"></p-sortIcon>
</th>
<th style="width: 150px" pSortableColumn="name">
{{ l('Status') }}
<p-sortIcon field="name"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-record let-expanded="expanded">
<tr>
<td style="width: 130px">
{{ record.properties.id}}
</td>
<td style="width: 150px">
{{ record.properties.postalCode }}
</td>
<td style="width: 150px">
{{ record.properties.agentName }}
</td>
<td style="width: 150px">
{{ record.properties.tenant }}
</td>
<td style="width: 150px">
{{ record.properties.status }}
</td>
</tr>
</ng-template>
</p-table>
</div>
</ng-template>
</p-table>
我的问题是 p-table,在展开的行中,容器的宽度不是 100%
是这样的
如何让它适合父容器的 100% 宽度?
最佳答案
内联样式
尝试将以下内联 CSS 属性绑定(bind)添加到嵌套表格中:
[tableStyle]="{'width.%': 100}"
独立风格
或者,如果您不喜欢内联样式,请尝试将其添加到关联的 css 文件中:
.expanded-table {
width: 100%;
}
和嵌套表的类:
[tableStyleClass]="'expanded-table'"
关于css - PrimeNg 展开容器的行全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56256693/