javascript - 如何处理 Angular 数据表中的列不匹配?

标签 javascript angular datatable angular6

如果所有条件都满足且为真,则所有列都会匹配并显示在数据表中,如下所示:

enter image description here

client.auditorGroup 为 true 或 false。工作代码是:

    <table class="table table-bodered">
   <thead>
      <tr>
         <th>Mag No</th>
         <th>SelectionDate</th>
         <th> SelectedBy</th>
         <th>PanEximNumber</th>
         <th>Name</th>
         <th>Address</th>
         <th>PhoneNumber</th>
         <th>SelectionType</th>
         <th>Action</th>
      </tr>
   </thead>
   <tbody>
      <tr *ngFor="let client of clients" (click)="onClick(client)">
      <td  [ngStyle]="getStyle(this.client)">{{client.selectionId}}</td>
      <td>{{client.selectionDate}}</td>
      <td>{{client.selectedBy}}</td>
      <td>{{client.panEximNumber}}</td>
      <td>{{client.name}}</td>
      <td>{{client.address}}</td>
      <td>{{client.phoneNumber}}</td>
      <td>{{client.selectionType}}</td>
      <td *ngIf="!client.auditorGroup" [ngStyle]="getStyle(this.client)">Edit
      Delete</td>
      </tr>
   </tbody>
</table>

在最后一个条件下,如果它为 false,则由于以下语句,数据表变得像列不匹配:

<td *ngIf="!client.auditorGroup" [ngStyle]="getStyle(this.client)">Edit
          Delete</td>

enter image description here

最佳答案

您可以在 HTML 模板上检查它们,或者创建一个函数,如果找到它们,则返回 true 并将其添加到 * ngIf情况。

演示:

<tbody>
  <tr 
  *ngFor="let client of clients"
  *ngIf="client.selectionId&&
  client.selectedBy&&
  client.panEximNumber&&
  client.name&&
  client.phoneNumber&&
  client.selectionType" 
  (click)="onClick(client)">
    <td [ngStyle]="getStyle(this.client)">{{client.selectionId}}</td>
    <td>{{client.selectionDate}}</td>
    <td>{{client.selectedBy}}</td>
    <td>{{client.panEximNumber}}</td>
    <td>{{client.name}}</td>
    <td>{{client.address}}</td>
    <td>{{client.phoneNumber}}</td>
    <td>{{client.selectionType}}</td>
    <td *ngIf="!client.auditorGroup" [ngStyle]="getStyle(this.client)">Edit Delete
    </td>
  </tr>
</tbody>

第二种方式:

clientHasFullData() {

  return this.client.selectionId &&
    this.client.selectedBy &&
    this.client.panEximNumber &&
    this.client.name &&
    this.client.phoneNumber &&
    this.client.selectionType
}
<tbody>
  <tr *ngFor="let client of clients" *ngIf="clientHasFullData()" (click)="onClick(client)">
    <td [ngStyle]="getStyle(this.client)">{{client.selectionId}}</td>
    <td>{{client.selectionDate}}</td>
    <td>{{client.selectedBy}}</td>
    <td>{{client.panEximNumber}}</td>
    <td>{{client.name}}</td>
    <td>{{client.address}}</td>
    <td>{{client.phoneNumber}}</td>
    <td>{{client.selectionType}}</td>
    <td *ngIf="!client.auditorGroup" [ngStyle]="getStyle(this.client)">Edit Delete
    </td>
  </tr>
</tbody>

希望这有帮助

关于javascript - 如何处理 Angular 数据表中的列不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53168080/

相关文章:

javascript - 如何设置Angular 2.0的环境?

jsf - h :dataTable composite component, cc.attrs.var,IllegalArgumentException

jQuery Datatable,保存表的状态,如分页、搜索等

angularjs - 无法绑定(bind)到 'dtOptions' ,因为它不是 'table' 的已知属性。

javascript - Angular - 编译指令后无法访问 Controller 方法

javascript - 使用 javascript 编辑类(不是元素上的内联样式)

javascript - 将js库包含到pdf中

angularjs - Angular 错误 : core_1. InjectionToken 不是构造函数

angular - 将电话号码与 Angular 管对齐

javascript - 使用 JS/CSS 缩小工具作为 python distutils 命令?