我从数据库中获取数据并使用Angular Datatable进行显示。每当单击td
时,我就调用一个函数。现在,无论何时我搜索或对列进行排序,click事件都将停止工作。我知道它与事件委托有关,但是不知道如何实现。
<table datatable [dtOptions]="dtOptions" [dtTrigger]="dttrigger2">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">email</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let customers of allCustomers; let i = index">
<th scope="row">{{i+1}}</th>
<td (click)="showComment(customers, $event)">{{customers?.name}}</td>
<td (click)="showComment(customers)">{{customers?.email}}</td>
<td (click)="showComment(customers)">{{customers?.mobile}}</td>
</tr>
</tbody>
</table>
ngOnInit(){
this.dtOptions = {
"pagingType": "full_numbers",
"lengthMenu":[
[25,50,-1],
[25,50,'All']
],
retrieve: true,
destroy:true,
searching: true,
ordering: true
language: {
search: "_INPUT_",
searchPlaceholder:"Search records",
}
};
}