remymumoh

Untitled

Sep 10th, 2020
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. @Component({
  3.   selector: 'app-homeurban',
  4.   templateUrl: './homeurban.component.html',
  5.   styleUrls: ['./homeurban.component.css'],
  6.   encapsulation: ViewEncapsulation.None,
  7. })
  8. export class HomeurbanComponent implements OnInit, AfterViewInit {
  9.  
  10.  
  11.   @ViewChild('myTable', {static: false}) myTable: ElementRef;
  12.  
  13.   constructor(private httpClient: HttpClient,
  14.               private modalService: ModalService,
  15.               private service: ReportService) {
  16.   }
  17.  
  18.  
  19.   ngAfterViewInit() {
  20.  
  21.     var table = this.myTable.nativeElement;
  22.     var row ;
  23.     var cell ;
  24.     var j = 1;
  25.     var r = 0;
  26.     var t = 0;
  27.     //console.log(table);
  28.     if (table !== null) {
  29.       while (row = table.rows[r++]) {
  30.         var c = 0;
  31.         while (cell = row.cells[c++]) {
  32.           var cellValue = cell;
  33.           if (c === 5 && cellValue > 25) {
  34.             console.log("rows 2" + c);
  35.             cell.style="#FF0000";
  36.           } else if (c === 5 && cellValue >= 10 && cellValue < 25) {
  37.             cell.style="#FFFF00";
  38.           }
  39.         }
  40.       }
  41.       //getting the average value of each column
  42.       var colL = table.rows.length - 1;
  43.       //console.log(table.rows[1].cells.length);
  44.       for (j = 1; j < table.rows[1].cells.length; j++) {
  45.         var sumVal = 0;
  46.         for (var i = 1; i < table.rows.length; i++) {
  47.           if (i < colL) {
  48.            //console.log(table.rows[i].cells[1].innerHTML);
  49.             if (Number.isInteger(parseInt(table.rows[i].cells[j].innerHTML)) === true) {
  50.               sumVal = sumVal + parseFloat(table.rows[i].cells[j].innerHTML);
  51.             } else {
  52.               table.rows[i].cells[j].value = "-";
  53.               table.rows[i].cells[j].style.backgroundColor = "#FFFF00";
  54.             }
  55.           }
  56.          // console.log(table.rows[colL].cells[table.rows.length - 1].innerHTML);
  57.         }
  58.  
  59.         //Setting the last cell with the avirrage value
  60.         if (table.rows[colL].cells[j] !== table.rows[colL].cells[table.rows[1].cells.length - 2]) {
  61.           var ans = (sumVal / (table.rows.length - 2)).toFixed(2);
  62.           table.rows[colL].cells[j].innerHTML = ans;
  63.         } else
  64.           table.rows[colL].cells[j].innerHTML = sumVal;
  65.  
  66.         //Taking out all cells with zore totals
  67.         if (parseInt(ans) === 0) {
  68.           for (t = 0; t <= colL; t++) {
  69.             table.rows[t].cells[j].style.display = 'none';
  70.           }
  71.         }
  72.  
  73.       }
  74.     }
  75.   }
  76. }
RAW Paste Data