kasim mohamed

kasim mohamed

  • 1.6k
  • 42
  • 6.5k

Export mat-table as excel without action button column

Oct 6 2020 4:39 AM
Hi,
 
i have a mat-table like below
  1. <button mat-mini-fab class="my-fab" (click)="exporter.exportTable('xlsx')">  
  2. <mat-icon>cloud_download</mat-icon>  
  3. </button>  
  4. <table mat-table [dataSource]="listData" matSort class="mat-elevation-z8" matTableExporter #exporter="matTableExporter">  
  5. <!-- GroupID Column -->  
  6. <ng-container matColumnDef="groupid">  
  7. <th mat-header-cell *matHeaderCellDef mat-sort-header> GroupID </th>  
  8. <td mat-cell *matCellDef="let element"> {{element.GroupID}} </td>  
  9. </ng-container>  
  10. <!-- GroupName Column -->  
  11. <ng-container matColumnDef="groupname">  
  12. <th mat-header-cell *matHeaderCellDef mat-sort-header> GroupName </th>  
  13. <td mat-cell *matCellDef="let element"> {{element.GroupName}} </td>  
  14. </ng-container>  
  15. <!-- UserName Column -->  
  16. <ng-container matColumnDef="username">  
  17. <th mat-header-cell *matHeaderCellDef mat-sort-header> UserName </th>  
  18. <td mat-cell *matCellDef="let element"> {{element.UserName}} </td>  
  19. </ng-container>  
  20. <!-- Edit/Delete/View button -->  
  21. <ng-container matColumnDef="Action">  
  22. <th mat-header-cell *matHeaderCellDef></th>  
  23. <td mat-cell *matCellDef="let row">  
  24. <div class="button-row">  
  25. <button mat-icon-button color="primary"  
  26. style="margin-right: 0px;margin-bottom: 0px;width: 30px;height: 30px; line-height: unset;"  
  27. (click)="onEdit(row, 'EDIT')" *ngIf="editbtnvisible">  
  28. <mat-icon style="font-size:20px;">edit_outline</mat-icon>  
  29. </button>  
  30. <button mat-icon-button color="warn"  
  31. style="margin-right: 0px;margin-bottom: 0px;width: 30px;height: 30px; line-height: unset;"  
  32. (click)="onDelete(row)" *ngIf="deletebtnvisible">  
  33. <mat-icon style="font-size:20px;">delete_outline</mat-icon>  
  34. </button>  
  35. <button mat-icon-button color="primary"  
  36. style="margin-right: 0px;margin-bottom: 0px;width: 30px;height: 30px; line-height: unset;"  
  37. (click)="onEdit(row.ApproverGroupID, 'VIEW')" *ngIf="viewbtnvisible">  
  38. <mat-icon style="font-size:20px;">search</mat-icon>  
  39. </button>  
  40. </div>  
  41. </td>  
  42. </ng-container>  
  43.   
  44. <!-- <ng-container matColumnDef="Action">  
  45. <th mat-header-cell *matHeaderCellDef></th>  
  46. <td mat-cell *matCellDef="let row">  
  47. <div class="button-row">  
  48. <button mat-icon-button (click)="onEdit(row.UserID, 'EDIT')" *ngIf="editbtnvisible">  
  49. <mat-icon>edit_outline</mat-icon>  
  50. </button>  
  51. <button mat-icon-button color="warn" (click)="onDelete(row.UserID)" *ngIf="deletebtnvisible">  
  52. <mat-icon>delete_outline</mat-icon>  
  53. </button>  
  54. <button mat-icon-button (click)="onEdit(row.UserID, 'VIEW')" *ngIf="viewbtnvisible">  
  55. <mat-icon>search</mat-icon>  
  56. </button>  
  57. </div>  
  58. </td>  
  59. </ng-container> -->  
  60. <ng-container matColumnDef="loading">  
  61. <th mat-footer-cell *matFooterCellDef colspan="6">  
  62. Loading Data...  
  63. </th>  
  64. </ng-container>  
  65. <ng-container matColumnDef="noData">  
  66. <th mat-footer-cell *matFooterCellDef colspan="6">  
  67. No data.  
  68. </th>  
  69. </ng-container>  
  70. <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>  
  71. <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>  
  72. <tr mat-footer-row *matFooterRowDef="['loading']" [ngClass]="{'hide':listData!=null}"></tr>  
  73. <tr mat-footer-row *matFooterRowDef="['noData']" [ngClass]="{'hide':!(listData!=null && listData.data.length==0)}"></tr>  
  74. </table>  
Am using matTableExporter to export table data into excel. The data's are exporting into excel with extra action column and last row as 'LoadingData' and 'No Data'.
 
How to skip the action button column and last two row 'LoadingData' and 'No Data'
 
Please guide me
Thanks

Answers (1)