|
| 1 | + |
| 2 | +import { Component, ViewChild } from '@angular/core'; |
| 3 | +import { RouterOutlet } from '@angular/router'; |
| 4 | +import { PivotViewModule } from '@syncfusion/ej2-angular-pivotview'; |
| 5 | +import { PivotFieldListModule,ConditionalFormattingService,ToolbarService } from '@syncfusion/ej2-angular-pivotview'; |
| 6 | +import { IDataOptions, PivotView, IAxisSet, IDataSet,ToolbarItems } from '@syncfusion/ej2-angular-pivotview'; |
| 7 | +import { renewableEnergy } from './data'; |
| 8 | + |
| 9 | +@Component({ |
| 10 | + standalone: true, |
| 11 | + imports: [RouterOutlet, PivotViewModule, PivotFieldListModule], |
| 12 | + providers: [ConditionalFormattingService,ToolbarService], |
| 13 | + selector: 'app-root', |
| 14 | + styleUrls: ['app.component.css'], |
| 15 | + templateUrl: 'app.component.html', |
| 16 | +}) |
| 17 | +export class AppComponent { |
| 18 | + public dataSourceSettings?: IDataOptions ; |
| 19 | + public cellTemplate?: string ; |
| 20 | + public toolbarOptions?: ToolbarItems[]; |
| 21 | + @ViewChild('pivotview') |
| 22 | + public pivotObj?: PivotView; |
| 23 | + |
| 24 | + trend(): void { |
| 25 | + let cTable: HTMLElement[] = [].slice.call(document.getElementsByClassName("e-table")); |
| 26 | + Array.from(cTable[1].children[1].children).forEach((row: Element) => { |
| 27 | + Array.from(row.childNodes).forEach((node: Node, j: number) => { |
| 28 | + let ri: any = (node as HTMLElement).getAttribute("index"); |
| 29 | + let currentValue: number = ((this.pivotObj?.pivotValues[ri][j] as IAxisSet) as any).value; |
| 30 | + if ((node as HTMLElement).querySelector('.tempwrap')) { |
| 31 | + let trendElement: HTMLElement | any = (node as HTMLElement).querySelector('.tempwrap'); |
| 32 | + trendElement.className = 'tempwrap pv-icons'; |
| 33 | + trendElement.className += (currentValue > 175) ? ' sb-icon-profit' : |
| 34 | + (currentValue > 100) ? ' sb-icon-neutral' : |
| 35 | + (currentValue > 0) ? ' sb-icon-loss' : ''; |
| 36 | + } |
| 37 | + }) |
| 38 | + }); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + ngOnInit(): void { |
| 43 | + this.toolbarOptions = ['ConditionalFormatting'] as ToolbarItems[]; |
| 44 | + this.cellTemplate = '<span class="tempwrap sb-icon-neutral pv-icons"></span>'; |
| 45 | + |
| 46 | + this.dataSourceSettings = { |
| 47 | + dataSource: renewableEnergy as IDataSet[], |
| 48 | + expandAll: true, |
| 49 | + formatSettings: [{ name: 'ProCost', format: 'C0' }], |
| 50 | + rows: [ |
| 51 | + { name: 'Year', caption: 'Production Year' }, |
| 52 | + { name: 'HalfYear', caption: 'Half Year' } |
| 53 | + ], |
| 54 | + columns: [ |
| 55 | + { name: 'EnerType', caption: 'Energy Type' }, |
| 56 | + { name: 'EneSource', caption: 'Energy Source' } |
| 57 | + ], |
| 58 | + values: [ |
| 59 | + { name: 'PowUnits', caption: 'Power Units'}, |
| 60 | + { name: 'ProCost', caption: 'Revenue Growth' } |
| 61 | + ], |
| 62 | + |
| 63 | + conditionalFormatSettings: [ |
| 64 | + { |
| 65 | + //measure: 'ProCost', |
| 66 | + value1: 100, |
| 67 | + conditions: 'LessThan', |
| 68 | + style: { |
| 69 | + backgroundColor: 'yellow', |
| 70 | + color: 'red', |
| 71 | + fontFamily: 'Tahoma', |
| 72 | + fontSize: '12px' |
| 73 | + } |
| 74 | + }, |
| 75 | + |
| 76 | + ] |
| 77 | + |
| 78 | + }; |
| 79 | + } |
| 80 | +} |
0 commit comments