gpt4 book ai didi

angular - 删除行后无法刷新 p 表中的数据 (PrimeNg)

转载 作者:行者123 更新时间:2023-12-04 15:37:37 29 4
gpt4 key购买 nike

I m using primeng 8.1 with angular 8
I refer my p-table with #dt then i call dt.reset() and getcandidates() to refresh
But it shows first page of p-table without refreshing list i searched in official documentation but i don't find a solution so the only way to refresh data is to reload entire navigator page

<p-table #dt  
[paginator]="true"
[columns] = "cols"
[value]="listcandidats"
[totalRecords]="listcandidats.length"
[paginator]="true"
[rows]="5"
[style.top.px]="screenHeight/6"
>

<ng-template pTemplate="caption">
<div style="text-align: right">
<i class="fa fa-search" style="margin:4px 4px 0 0"></i>
<input type="text" pInputText size="50" placeholder="Recherche multioption"
(input)="dt.filterGlobal($event.target.value, 'contains')" style="width:auto">
</div>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th>Candidat</th>

<th>Action</th>
</tr>


</ng-template>
<ng-template pTemplate="body" let-rowData >
<tr [pSelectableRow]="rowData" >


<td [style.width.px]="screenWidth/8"> <h3>{{rowData.nom}}</h3></td>


<td>
<button pButton type="button" label="modifier" (click)="showDialog(rowData.id)" class="ui-
button-rounded ui-button-warning">
</button>

<button pButton type="button" label="supprimer"
(click)="deletecandidat(rowData.id);dt.reset();getcandidats()" class="ui-button-rounded ui-
button-danger"></button>
</td>

</tr>
<hr [style.width.px]="screenWidth">
</ng-template>


</p-table>

最佳答案

As per PrimeNg Document

在某些情况下,例如重新应用排序,表可能需要知道其值的变化。出于性能考虑,仅当值的引用发生变化时才会这样做,这意味着使用 setter 而不是 ngDoCheck/IterableDiffers 这会降低性能。所以当你对值进行操作时,比如删除或添加一个项目,而不是使用array方法,比如pushsplice创建一个新的数组引用使用展开运算符或类似运算符。

关于angular - 删除行后无法刷新 p 表中的数据 (PrimeNg),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59232193/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com