J'ai une table primeng avec une ligne expansée pour chaque élément de la table.
La ligne expansée doit contenir une table avec des données p>
Voici le code du modèle. P>
<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>
3 Réponses :
Essayez d'ajouter la propriété de la propriété CSS en ligne suivante à votre table imbriquée: P>
[tableStyleClass]="'expanded-table'"
Ce n'est pas utile :(
On dirait que cela a aidé un peu. Heureux que vous ayez pu résoudre le colsan. :-)
Comme le contenu du gabarit RowExpansion sera ajouté à l'intérieur de la table, vous devez ajouter la balise TR et TD comme celle-ci:
<ng-template pTemplate="rowexpansion">
<tr>
<td [attr.colspan]="columns.length + 1">
<div class="ui-g ui-fluid" style="font-size:16px;padding:20px">
<p-table>
...
</p-table>
</div>
</td>
</tr>
</ng-template>
j'ai pu résoudre comme ça
Utilisation de Voici le code de réponse p> colspan = "4" code> attribut
Vous pouvez mettre cet exemple en jsfiddle ou n'importe quel PLZ