|
1 | | -import { Component } from "@angular/core"; |
| 1 | +import { Component, ViewChild } from "@angular/core"; |
2 | 2 |
|
3 | 3 | import { |
4 | 4 | IPivotConfiguration, PivotAggregation, IgxPivotNumericAggregate, |
5 | 5 | IgxPivotDateDimension, FilteringExpressionsTree, FilteringLogic, IgxStringFilteringOperand, |
6 | 6 | PivotRowLayoutType, |
7 | | - IPivotUISettings |
| 7 | + IPivotUISettings, |
| 8 | + IChangeCheckboxEventArgs, |
| 9 | + IgxPivotGridComponent, |
| 10 | + PivotSummaryPosition |
8 | 11 | } from "igniteui-angular" |
9 | 12 | import { SALES_DATA } from "../../data/dataToAnalyze"; |
10 | 13 |
|
@@ -42,95 +45,123 @@ export class IgxTotalSaleAggregate { |
42 | 45 | }) |
43 | 46 | export class PivotGridLayoutComponent { |
44 | 47 | public data = SALES_DATA; |
| 48 | + public enableSummaries = true; |
45 | 49 | public pivotUI: IPivotUISettings = { showRowHeaders: true, rowLayout: PivotRowLayoutType.Horizontal }; |
46 | 50 |
|
47 | | - public pivotConfig: IPivotConfiguration = { |
48 | | - columns: [ |
49 | | - new IgxPivotDateDimension( |
50 | | - { |
51 | | - memberName: 'Date', |
52 | | - enabled: true |
53 | | - }, |
| 51 | + @ViewChild("grid1") |
| 52 | + public grid1: IgxPivotGridComponent; |
| 53 | + |
| 54 | + public pivotConfig = this.buildPivotConfig(); |
| 55 | + |
| 56 | + public buildPivotConfig(): IPivotConfiguration { |
| 57 | + return { |
| 58 | + columns: [ |
| 59 | + new IgxPivotDateDimension( |
| 60 | + { |
| 61 | + memberName: 'Date', |
| 62 | + enabled: true |
| 63 | + }, |
| 64 | + { |
| 65 | + months: false, |
| 66 | + quarters: true, |
| 67 | + fullDate: false |
| 68 | + } |
| 69 | + ) |
| 70 | + ], |
| 71 | + rows: [ |
54 | 72 | { |
55 | | - months: false, |
56 | | - quarters: true, |
57 | | - fullDate: false |
58 | | - } |
59 | | - ) |
60 | | - ], |
61 | | - rows: [ |
62 | | - { |
63 | | - memberFunction: () => 'All Products', |
64 | | - memberName: 'AllProducts', |
65 | | - enabled: true, |
66 | | - horizontalSummary: true, |
67 | | - width: "150px", |
68 | | - childLevel: { |
69 | | - memberFunction: (data) => data.Product.Name, |
70 | | - memberName: 'ProductCategory', |
71 | | - horizontalSummary: true, |
72 | | - width: "150px", |
| 73 | + memberFunction: () => 'All Products', |
| 74 | + memberName: 'AllProducts', |
73 | 75 | enabled: true, |
| 76 | + horizontalSummary: this.enableSummaries, |
| 77 | + width: "150px", |
74 | 78 | childLevel: { |
75 | | - memberName: 'City', |
| 79 | + memberFunction: (data) => data.Product.Name, |
| 80 | + memberName: 'ProductCategory', |
| 81 | + horizontalSummary: this.enableSummaries, |
76 | 82 | width: "150px", |
77 | | - memberFunction: (data) => data.Seller.City, |
78 | | - enabled: true |
| 83 | + enabled: true, |
| 84 | + childLevel: { |
| 85 | + memberName: 'City', |
| 86 | + width: "150px", |
| 87 | + memberFunction: (data) => data.Seller.City, |
| 88 | + enabled: true |
| 89 | + } |
79 | 90 | } |
80 | 91 | } |
81 | | - } |
82 | | - ], |
83 | | - values: [ |
84 | | - { |
85 | | - member: 'Value', |
86 | | - aggregate: { |
87 | | - key: 'SUM', |
88 | | - aggregator: IgxPivotNumericAggregate.sum, |
89 | | - label: 'Sum' |
90 | | - }, |
91 | | - aggregateList: [{ |
92 | | - key: 'SUM', |
93 | | - aggregator: IgxPivotNumericAggregate.sum, |
94 | | - label: 'Sum' |
95 | | - }], |
96 | | - enabled: true, |
97 | | - styles: { |
98 | | - downFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) <= 150, |
99 | | - upFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) > 150 |
100 | | - }, |
101 | | - formatter: (value) => value ? '$' + parseFloat(value).toFixed(3) : undefined |
102 | | - }, |
103 | | - { |
104 | | - member: 'AmountofSale', |
105 | | - displayName: 'Amount of Sale', |
106 | | - aggregate: { |
107 | | - key: 'SUM', |
108 | | - aggregator: IgxTotalSaleAggregate.totalSale, |
109 | | - label: 'Sum of Sale' |
| 92 | + ], |
| 93 | + values: [ |
| 94 | + { |
| 95 | + member: 'Value', |
| 96 | + aggregate: { |
| 97 | + key: 'SUM', |
| 98 | + aggregator: IgxPivotNumericAggregate.sum, |
| 99 | + label: 'Sum' |
| 100 | + }, |
| 101 | + aggregateList: [{ |
| 102 | + key: 'SUM', |
| 103 | + aggregator: IgxPivotNumericAggregate.sum, |
| 104 | + label: 'Sum' |
| 105 | + }], |
| 106 | + enabled: true, |
| 107 | + styles: { |
| 108 | + downFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) <= 150, |
| 109 | + upFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) > 150 |
| 110 | + }, |
| 111 | + formatter: (value) => value ? '$' + parseFloat(value).toFixed(3) : undefined |
110 | 112 | }, |
111 | | - aggregateList: [{ |
112 | | - key: 'SUM', |
113 | | - aggregator: IgxTotalSaleAggregate.totalSale, |
114 | | - label: 'Sum of Sale' |
115 | | - }, { |
116 | | - key: 'MIN', |
117 | | - aggregator: IgxTotalSaleAggregate.totalMin, |
118 | | - label: 'Minimum of Sale' |
119 | | - }, { |
120 | | - key: 'MAX', |
121 | | - aggregator: IgxTotalSaleAggregate.totalMax, |
122 | | - label: 'Maximum of Sale' |
123 | | - }], |
124 | | - enabled: true, |
125 | | - dataType: 'currency' |
126 | | - } |
127 | | - ], |
128 | | - filters: [ |
129 | | - { |
130 | | - memberName: 'SellerName', |
131 | | - memberFunction: (data) => data.Seller.Name, |
132 | | - enabled: true |
133 | | - } |
134 | | - ] |
135 | | - }; |
| 113 | + { |
| 114 | + member: 'AmountofSale', |
| 115 | + displayName: 'Amount of Sale', |
| 116 | + aggregate: { |
| 117 | + key: 'SUM', |
| 118 | + aggregator: IgxTotalSaleAggregate.totalSale, |
| 119 | + label: 'Sum of Sale' |
| 120 | + }, |
| 121 | + aggregateList: [{ |
| 122 | + key: 'SUM', |
| 123 | + aggregator: IgxTotalSaleAggregate.totalSale, |
| 124 | + label: 'Sum of Sale' |
| 125 | + }, { |
| 126 | + key: 'MIN', |
| 127 | + aggregator: IgxTotalSaleAggregate.totalMin, |
| 128 | + label: 'Minimum of Sale' |
| 129 | + }, { |
| 130 | + key: 'MAX', |
| 131 | + aggregator: IgxTotalSaleAggregate.totalMax, |
| 132 | + label: 'Maximum of Sale' |
| 133 | + }], |
| 134 | + enabled: true, |
| 135 | + dataType: 'currency' |
| 136 | + } |
| 137 | + ], |
| 138 | + filters: [ |
| 139 | + { |
| 140 | + memberName: 'SellerName', |
| 141 | + memberFunction: (data) => data.Seller.Name, |
| 142 | + enabled: true |
| 143 | + } |
| 144 | + ] |
| 145 | + }; |
| 146 | + } |
| 147 | + |
| 148 | + public onShowRowHeaders(event: IChangeCheckboxEventArgs) { |
| 149 | + this.pivotUI.showRowHeaders = event.checked; |
| 150 | + this.grid1.pivotUI = this.pivotUI; |
| 151 | + } |
| 152 | + |
| 153 | + public onLayoutToggle(event: IChangeCheckboxEventArgs) { |
| 154 | + this.pivotUI.rowLayout = event.checked ? PivotRowLayoutType.Horizontal : PivotRowLayoutType.Vertical; |
| 155 | + this.grid1.pivotUI = this.pivotUI; |
| 156 | + } |
| 157 | + |
| 158 | + public onSummariesToggle(event: IChangeCheckboxEventArgs) { |
| 159 | + this.enableSummaries = event.checked; |
| 160 | + this.grid1.pivotConfiguration = this.buildPivotConfig(); |
| 161 | + } |
| 162 | + |
| 163 | + public onSummariesPositionToggle(event: IChangeCheckboxEventArgs) { |
| 164 | + this.pivotUI.horizontalSummariesPosition = event.checked ? PivotSummaryPosition.Top : PivotSummaryPosition.Bottom ; |
| 165 | + this.grid1.pivotUI = this.pivotUI; |
| 166 | + } |
136 | 167 | } |
0 commit comments