我在Angular视图中有两个数据表,然后按一下按钮试图破坏并重新填充其中一个表。但是我的代码同时破坏了两者,如何指定要破坏的表?这是我一直在使用的the documentation
按下按钮
searchByCoid(term: string): void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {dtInstance.destroy();});
this.getUsersByCoid(term.trim()); //repopulate the table with different data
}
创建表格的HTML
<table datatable [dtOptions]="dtOptionsComp" [dtTrigger]="dtTriggerCompany" class="row-border hover">
<thead><tr><th>ID</th><th>Name</th></tr></thead>
<tbody>
<tr *ngFor="let d of companylist" (click)="selectCompany($event, d)" [class.highlighted]="d.highlighted">
<td>{{d.id}}</td><td>{{d.name}}</td>
</tr></tbody>
</table>
<h1>Select User to Modify</h1>
<table datatable [dtOptions]="dtOptionsUser" [dtTrigger]="dtTriggerUser" class="row-border hover">
<thead><tr><th>First Name</th><th>Last Name</th><th>Company ID</th><th>User ID</th><th>PAIOS Acct ID</th></tr></thead>
<tbody>
<tr *ngFor="let c of userlist">
<td>{{c.firstname}}</td><td>{{c.lastname}}</td><td>{{c.companyId}}</td><td>{{c.user_id}}</td><td>{{c.PAIOS_acctid}}</td>
</tr></tbody>
</table>