简体   繁体   English

如何处理角度数据表中的列不匹配?

[英]How to handle the column mismatch in datatable in angular?

If all the conditions are satisfied and true then all columns are matched and shown in datatable like: 如果所有条件都满足且为true,则所有列都将匹配并显示在数据表中,例如:

在此处输入图片说明

client.auditorGroup is either true or false. client.auditorGroup为true或false。 The codes working is: 工作的代码是:

    <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>

At this last condition if it is false then the datatable becomes like column mismatch due to this statement: 在最后一个条件下,如果它为false,则由于此语句,数据表将变得像列不匹配:

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

在此处输入图片说明

You can check for them on HTML templating or create a function that returns true if found them all and add it to * ngIf condition. 您可以在HTML模板上检查它们,也可以创建一个找到所有返回的true的函数并将其添加到* ngIf条件。

Demo: 演示:

 <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> 

Second way: 第二种方式:

 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> 

Hope this helps 希望这可以帮助

The reason for this error is usually because the data is not available for the column. 出现此错误的原因通常是因为列中没有可用的数据。 So when the last table header is there. 因此,当最后一个表头在那里时。 Its expecting a data column as well but since you are using ngif and its false the last column is null. 它也期望数据列,但是由于您使用的是ngif且其值为false,因此最后一列为null。 but the header is expecting a column. 但标题需要一列。 place ngif on the header as well that should solve the problem. 将ngif放在标题上也可以解决问题。

    <th *ngIf="!client.auditorGroup">Action</th>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM