ahmed elbarbary

ahmed elbarbary

  • 597
  • 1.6k
  • 282.3k

How to display dynamic data and dynamic header on angular 7

May 3 2020 8:33 PM

How to handle component.html headers and data in case of data and header columns changed every time ?

I work on angular app give it report id then it returned different result depend on report id

so may be if i pass reportid =1 it display

  1. FinancialId FinancialName FinancialDate   
  2. 1                   cash           12/01/2020  

if I pass reportid=2 then it display

  1. InventoryId InventoryName InventoryQty InventoryPrice  
  2.  1                  Stor1                 10                50  

then it return data different and column headers different based on report id

so How to display this data dynamically on html component .

service.ts

  1. export class DisplayreportService   
  2. {   
  3. constructor(private http : HttpClient) { }   
  4. GetReportDetailsByReportId(id : string){ 
  5. return this.http.get('http://localhost:61265/api/report/Getreportdetails/id=' + id) .map(res=>res); } }  

on reportdetails.component.ts

  1. reportdetailslist: any[];  
  2.  constructor(private router: ActivatedRoute, private _displayreport: DisplayreportService) { }      
  3. ngOnInit() { 
  4. const paramIndex = window.location.href.indexOf('id=');  
  5.  if (paramIndex > 0) { let param = window.location.href.substring(paramIndex);
  6.  let param1 = param.split('&')[0];   
  7. let param2 = param.substr(param.indexOf('=') + 1); 
  8. this._displayreport.GetReportDetailsByReportId(param2).subscribe((data: any[]) => { this.reportdetailslist = data; });  

How to show data on component.html below

  1. <div> <table class="table table-hover" >    
  2.  <thead>    
  3.  <tr>     
  4. <th>    
  5. i dont know table header returned    
  6. </th>     
  7. </tr>    
  8.  </thead>     
  9. <tbody>     
  10. <tr *ngFor="let rep of reportdetailslist">     
  11.         idont know columns returned            
  12. </tr>     
  13. </tbody>    
  14.  </table> 

Answers (5)