I have a refresh button that is outside the primeNG datatable. How do I programmatically trigger to refresh the datatable?
something like this:
<div class="pull-right">
<button
id="FilterBtnId"
(click)="???">
</button>
</div>
<p-dataTable
#datatable
[value]="datasource"
[(selection)]="jobs"
[totalRecords]="totalRecords"
selectionMode="multiple"
resizableColumns="true"
[pageLinks]="10"
[rows]="10"
[rowsPerPageOptions]="[10, 25, 50, 100]"
[paginator]="true"
[responsive]="true"
[lazy]="true"
(onLazyLoad)="getNewDatasource($event)"
(onRowSelect)="onRowSelect($event)"
>
<p-column [style]="{'width':'40px'}" selectionMode="multiple"></p-column>
<p-column *ngFor="let col of dt.colDefs" [field]="col.field" [header]="col.headerName" [sortable]="true">
</p-column>
</p-dataTable>
The Angular form guide contains a small trick that could be used as a workaround, it consists on recreating the dom by adding
*ngIf
to the element to control its visibilityWe can have small trick to update the dataTable here: we can recreating the div by adding *ngIf to the element to control its visibility by this it will update dataTable also.
If you refresh the list in the component, the table refresh automatically. Example after confirm a delete operation: