swimlane / ngx-datatable:如何检测点击的行是否展开?

swimlane / ngx-datatable: how to detect if a row on click is expand or not?

如果你点击一行,它会展开,可以看到详细信息。这显然发生在“切换”时。但是现在怎么判断一行是否已经展开了呢?

HTML

 <ngx-datatable
   #dataTable
   ...
   (select)='onRowSelect($event)'
   (activate)="onLoadDataDetails($event)">

TS

  onRowSelect(row: any): void {
    if (row && row.selected) {
      this.dataTable.rowDetail.toggleExpandRow(row.selected[0]);
    }
  }

  onLoadDataDetails(row: any): void {
    if (row.type === 'click') {
      this.loadDetails(row.row.id);
    }
  }

否则打开和关闭时触​​发请求(this.loadDetails)

我通过添加一个设置内部变量的方法解决了这个问题。

<ngx-datatable-row-detail
 #myDetailRow>
  <ng-template let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
    <div *ngIf="expanded?setExpandStatus(expanded):false"></div>

组件:

  setExpandStatus(expanded: any): void {
    this.rowIsNotExpanded = expanded;
  }

  onLoadDataDetails(row: any): void {
    if (row.type === 'click') {
      if (!this.rowIsNotExpanded) {
        this.loadDetails(row.row.id);
      }
    }
  }