Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Angular Mat-Table with Dynamic Columns generate and Data should be populated in horizontal way

displayedColumns: string[] = ['SAMPLERULENAME','DISPLAYNAME1','OPERATOR1','COUNT1','DISPLAYNAME2','OPERATOR2','COUNT2','DISPLAYNAME3','OPERATOR3','COUNT3','DISPLAYNAME4','OPERATOR4','COUNT4'];
  dataSource = ELEMENT_DATA;

  getValue(element, colname){
   console.log(element);
   var lastChar = colname.substr(colname.length - 1);
   console.log(lastChar);
   colname = colname.slice(0, -1); 
   console.log(colname);
   
   if(element["SAMPLERULECONDITIONS" + lastChar]){
    return (element["SAMPLERULECONDITIONS" + lastChar][colname]);
   }
  }

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">

<!-- Position Column -->

<ng-container *ngFor="let col of displayedColumns; let i = index" [matColumnDef]="col">

<ng-container  *ngIf="col === 'SAMPLERULENAME'" matColumnDef="SAMPLERULENAME">
<th mat-header-cell *matHeaderCellDef> </th>
<td mat-cell *matCellDef="let element"> {{element.SAMPLERULENAME}} </td>
</ng-container>

<ng-container *ngIf="col !== 'SAMPLERULENAME'">
    <th mat-header-cell *matHeaderCellDef>  </th>
    <td mat-cell *matCellDef="let element">
    {{getValue(element, col)}}
    </td>      
  </ng-container>  
  
</ng-container>

<!-- Header row first group -->
<ng-container matColumnDef="header-row-first-group">
<th mat-header-cell *matHeaderCellDef 
    [style.text-align]="center"
    [attr.colspan]="1"> 
  Name
</th>
</ng-container>

<!-- Header row second group -->
<ng-container matColumnDef="header-row-second-group">
<th mat-header-cell *matHeaderCellDef [attr.colspan]="3"> Second group </th>
</ng-container>

<!-- Header row 3 group -->
<ng-container matColumnDef="header-row-3-group">
<th mat-header-cell *matHeaderCellDef [attr.colspan]="3"> Condition1 </th>
</ng-container>

<!-- Header row 4 group -->
<ng-container matColumnDef="header-row-4-group">
<th mat-header-cell *matHeaderCellDef [attr.colspan]="3">Condition2 </th>
</ng-container>

<!-- Header row 4 group -->
<ng-container matColumnDef="header-row-5-group">
<th mat-header-cell *matHeaderCellDef [attr.colspan]="3"> Condition3 </th>
</ng-container>



<tr mat-header-row *matHeaderRowDef="['header-row-first-group', 'header-row-second-group','header-row-3-group','header-row-4-group','header-row-5-group']"></tr>


<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
Comment

PREVIOUS NEXT
Code Example
Javascript :: two dimensional array in javascript 
Javascript :: google script get sheet size 
Javascript :: react electron desktop app 
Javascript :: javascript debugger 
Javascript :: react native update app from play store ios app store 
Javascript :: one signal api to send notification 
Javascript :: jquery datatable server side pagination asp.net core 
Javascript :: display toastr info 
Javascript :: postman environment variable 
Javascript :: asynchronous function using function constructor 
Javascript :: js animations 
Javascript :: node js login and registration 
Javascript :: spam system discord.js 
Javascript :: jquery class 
Javascript :: react hooks update parent state from child 
Javascript :: what are built in objects in javascript 
Javascript :: regex for international phone number 
Javascript :: javascript Clone Array Using Spread Operator 
Javascript :: if( request()-ajax()==false 
Javascript :: react native spinkit 
Javascript :: jsx react 
Javascript :: access index of array javascript 
Javascript :: inline style to change background color 
Javascript :: reduce in javascript 
Javascript :: fullcalendar edit event modal react 
Javascript :: matches method in javascript 
Javascript :: constructor js 
Javascript :: how to use private github repo as npm dependency 
Javascript :: js foreach mdn 
Javascript :: create javascript set 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =