I have integrated Jquery Data table in my Angular 6 application,How to refresh jquery datatable in angular 6 app after event performed like delete and update records In Datatable
HTML
<table class="table table-hover" datatable [dtOptions]="dtOptions"
[dtTrigger]="dtTrigger" cellspacing="0" >
<thead>
<tr>
<th>Country Name</th>
<th>Country Code</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let country of country$">
<td>{{ country.sCountryName }}</td>
<td>{{ country.sCountryCode }}</td>
<td *ngIf="country.isActive"> Active </td>
<td *ngIf="!country.isActive"> In Active</td>
<td><a class="btn btn-default" (click)="openedit(editcontent,country)" ><i class="glyphicon glyphicon-pencil" ><span class="i-text">Edit</span></i></a> <a class="btn btn-default" rel="nofollow" href="javascript:void(0)" (click)="deleteCountry(country)"><i class="glyphicon glyphicon-trash" ><span class="i-text">Delete</span></i></a></td>
</tr>
</tbody>
</table>
Component.ts
ngOnInit() {
this.getallCountries();
}
getallCountries(){
this.dtOptions = {
dom: '<"table-search-left"f><"table-count-right"l>tip',
pagingType: 'full_numbers',
pageLength: 10,
processing: true
};
this.crudservice.getCountryList().subscribe(data => {
this. country$ = data;
});
}
deleteCountry(country) {
this.http.delete('https://localhost:8444/api/config/country/delete/'+country.iCountryID)
.subscribe(res => {
this.rerender();
}, (err) => {
console.log(err);
}
);
}
rerender(): void {
console.log('this');
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.draw();
});
}
I'm going to delete country and call rerender function but datatable not refreshed.