Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component({
- selector: 'app-homeurban',
- templateUrl: './homeurban.component.html',
- styleUrls: ['./homeurban.component.css'],
- encapsulation: ViewEncapsulation.None,
- })
- export class HomeurbanComponent implements OnInit, AfterViewInit {
- @ViewChild('myTable', {static: false}) myTable: ElementRef;
- constructor(private httpClient: HttpClient,
- private modalService: ModalService,
- private service: ReportService) {
- }
- ngAfterViewInit() {
- var table = this.myTable.nativeElement;
- var row ;
- var cell ;
- var j = 1;
- var r = 0;
- var t = 0;
- //console.log(table);
- if (table !== null) {
- while (row = table.rows[r++]) {
- var c = 0;
- while (cell = row.cells[c++]) {
- var cellValue = cell;
- if (c === 5 && cellValue > 25) {
- console.log("rows 2" + c);
- cell.style="#FF0000";
- } else if (c === 5 && cellValue >= 10 && cellValue < 25) {
- cell.style="#FFFF00";
- }
- }
- }
- //getting the average value of each column
- var colL = table.rows.length - 1;
- //console.log(table.rows[1].cells.length);
- for (j = 1; j < table.rows[1].cells.length; j++) {
- var sumVal = 0;
- for (var i = 1; i < table.rows.length; i++) {
- if (i < colL) {
- //console.log(table.rows[i].cells[1].innerHTML);
- if (Number.isInteger(parseInt(table.rows[i].cells[j].innerHTML)) === true) {
- sumVal = sumVal + parseFloat(table.rows[i].cells[j].innerHTML);
- } else {
- table.rows[i].cells[j].value = "-";
- table.rows[i].cells[j].style.backgroundColor = "#FFFF00";
- }
- }
- // console.log(table.rows[colL].cells[table.rows.length - 1].innerHTML);
- }
- //Setting the last cell with the avirrage value
- if (table.rows[colL].cells[j] !== table.rows[colL].cells[table.rows[1].cells.length - 2]) {
- var ans = (sumVal / (table.rows.length - 2)).toFixed(2);
- table.rows[colL].cells[j].innerHTML = ans;
- } else
- table.rows[colL].cells[j].innerHTML = sumVal;
- //Taking out all cells with zore totals
- if (parseInt(ans) === 0) {
- for (t = 0; t <= colL; t++) {
- table.rows[t].cells[j].style.display = 'none';
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment