|
| 1 | +import { Component } from '@angular/core'; |
| 2 | +import { IGX_PIVOT_GRID_DIRECTIVES } from 'igniteui-angular/grids/pivot-grid'; |
| 3 | +import { IgxPivotDateDimension, IPivotConfiguration } from 'igniteui-angular/grids/core'; |
| 4 | + |
| 5 | +@Component({ |
| 6 | + selector: 'app-pivot-grid', |
| 7 | + templateUrl: './pivot-grid.component.html', |
| 8 | + styleUrls: ['./pivot-grid.component.scss'], |
| 9 | + imports: [IGX_PIVOT_GRID_DIRECTIVES] |
| 10 | +}) |
| 11 | +export class PivotGridComponent { |
| 12 | + public data = [ |
| 13 | + { |
| 14 | + ProductCategory: 'Clothing', |
| 15 | + ProductName: 'Shirt', |
| 16 | + SellerName: 'John Doe', |
| 17 | + SellerCity: 'New York', |
| 18 | + Date: new Date('2023-01-15'), |
| 19 | + UnitsSold: 20, |
| 20 | + UnitPrice: 25.99, |
| 21 | + Revenue: 519.8 |
| 22 | + }, |
| 23 | + { |
| 24 | + ProductCategory: 'Clothing', |
| 25 | + ProductName: 'Shirt', |
| 26 | + SellerName: 'Jane Smith', |
| 27 | + SellerCity: 'Los Angeles', |
| 28 | + Date: new Date('2023-01-20'), |
| 29 | + UnitsSold: 15, |
| 30 | + UnitPrice: 25.99, |
| 31 | + Revenue: 389.85 |
| 32 | + }, |
| 33 | + { |
| 34 | + ProductCategory: 'Clothing', |
| 35 | + ProductName: 'Pants', |
| 36 | + SellerName: 'John Doe', |
| 37 | + SellerCity: 'New York', |
| 38 | + Date: new Date('2023-02-10'), |
| 39 | + UnitsSold: 10, |
| 40 | + UnitPrice: 45.50, |
| 41 | + Revenue: 455 |
| 42 | + }, |
| 43 | + { |
| 44 | + ProductCategory: 'Electronics', |
| 45 | + ProductName: 'Phone', |
| 46 | + SellerName: 'Bob Johnson', |
| 47 | + SellerCity: 'Chicago', |
| 48 | + Date: new Date('2023-02-15'), |
| 49 | + UnitsSold: 8, |
| 50 | + UnitPrice: 699.99, |
| 51 | + Revenue: 5599.92 |
| 52 | + }, |
| 53 | + { |
| 54 | + ProductCategory: 'Electronics', |
| 55 | + ProductName: 'Laptop', |
| 56 | + SellerName: 'Alice Williams', |
| 57 | + SellerCity: 'New York', |
| 58 | + Date: new Date('2023-03-01'), |
| 59 | + UnitsSold: 5, |
| 60 | + UnitPrice: 1299.99, |
| 61 | + Revenue: 6499.95 |
| 62 | + }, |
| 63 | + { |
| 64 | + ProductCategory: 'Electronics', |
| 65 | + ProductName: 'Phone', |
| 66 | + SellerName: 'Jane Smith', |
| 67 | + SellerCity: 'Los Angeles', |
| 68 | + Date: new Date('2023-03-10'), |
| 69 | + UnitsSold: 12, |
| 70 | + UnitPrice: 699.99, |
| 71 | + Revenue: 8399.88 |
| 72 | + }, |
| 73 | + { |
| 74 | + ProductCategory: 'Clothing', |
| 75 | + ProductName: 'Jacket', |
| 76 | + SellerName: 'Bob Johnson', |
| 77 | + SellerCity: 'Chicago', |
| 78 | + Date: new Date('2023-03-20'), |
| 79 | + UnitsSold: 7, |
| 80 | + UnitPrice: 89.99, |
| 81 | + Revenue: 629.93 |
| 82 | + }, |
| 83 | + { |
| 84 | + ProductCategory: 'Electronics', |
| 85 | + ProductName: 'Tablet', |
| 86 | + SellerName: 'John Doe', |
| 87 | + SellerCity: 'New York', |
| 88 | + Date: new Date('2023-04-05'), |
| 89 | + UnitsSold: 6, |
| 90 | + UnitPrice: 499.99, |
| 91 | + Revenue: 2999.94 |
| 92 | + } |
| 93 | + ]; |
| 94 | + |
| 95 | + public pivotConfigHierarchy: IPivotConfiguration = { |
| 96 | + rows: [ |
| 97 | + { |
| 98 | + memberName: 'ProductCategory', |
| 99 | + enabled: true |
| 100 | + }, |
| 101 | + { |
| 102 | + memberName: 'ProductName', |
| 103 | + enabled: true |
| 104 | + } |
| 105 | + ], |
| 106 | + columns: [ |
| 107 | + new IgxPivotDateDimension( |
| 108 | + { |
| 109 | + memberName: 'Date', |
| 110 | + enabled: true |
| 111 | + }, |
| 112 | + { |
| 113 | + months: false, |
| 114 | + quarters: true, |
| 115 | + years: true |
| 116 | + } |
| 117 | + ), |
| 118 | + { |
| 119 | + memberName: 'SellerCity', |
| 120 | + enabled: true |
| 121 | + } |
| 122 | + ], |
| 123 | + values: [ |
| 124 | + { |
| 125 | + member: 'UnitsSold', |
| 126 | + displayName: 'Units Sold', |
| 127 | + aggregate: { |
| 128 | + aggregator: (members: any[], data?: any[]) => members.reduce((acc, val) => acc + val, 0), |
| 129 | + key: 'SUM', |
| 130 | + label: 'Sum' |
| 131 | + }, |
| 132 | + enabled: true |
| 133 | + }, |
| 134 | + { |
| 135 | + member: 'Revenue', |
| 136 | + displayName: 'Revenue', |
| 137 | + aggregate: { |
| 138 | + aggregator: (members: any[], data?: any[]) => members.reduce((acc, val) => acc + val, 0), |
| 139 | + key: 'SUM', |
| 140 | + label: 'Sum' |
| 141 | + }, |
| 142 | + enabled: true, |
| 143 | + dataType: 'currency' |
| 144 | + } |
| 145 | + ], |
| 146 | + filters: null |
| 147 | + }; |
| 148 | +} |
0 commit comments