订购或搜索后,Angular Datatable Click事件不起作用

时间:2019-03-07 13:02:36

标签: angular datatable event-delegation jquery-click-event

我从数据库中获取数据并使用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",
      }
    };  
  }

0 个答案:

没有答案
相关问题