1- import { Component , OnInit , ViewChild } from "@angular/core" ;
1+ import {
2+ Component ,
3+ ViewChild ,
4+ OnInit ,
5+ AfterViewInit
6+ } from "@angular/core" ;
27import {
38 IgxTreeGridComponent ,
49 IgxColumnComponent ,
5- IgxButtonDirective ,
6- IgxSummaryResult
10+ IgxSummaryResult ,
11+ IgxButtonGroupComponent
712} from "igniteui-angular" ;
813import { ORDERS_DATA } from "../data/orders" ;
914import { IgxPreventDocumentScrollDirective } from "../../directives/prevent-scroll.directive" ;
@@ -15,6 +20,7 @@ class UnitsSummary {
1520 fieldName = ""
1621 ) : IgxSummaryResult [ ] {
1722 const result = [ ] ;
23+
1824 result . push ( {
1925 key : "totalDelivered" ,
2026 label : "Total Units Delivered" ,
@@ -61,14 +67,16 @@ class UnitsSummary {
6167 IgxTreeGridComponent ,
6268 IgxPreventDocumentScrollDirective ,
6369 IgxColumnComponent ,
64- IgxButtonDirective
70+ IgxButtonGroupComponent
6571 ]
6672} )
67- export class TreeGridDisableSummariesComponent implements OnInit {
73+ export class TreeGridDisableSummariesComponent implements OnInit , AfterViewInit {
6874 @ViewChild ( "treegrid1" , { read : IgxTreeGridComponent , static : true } )
6975 public treeGrid1 : IgxTreeGridComponent ;
7076
71- public data ;
77+ public data : any [ ] ;
78+ public defaultSummaries : any [ ] ;
79+ public customSummaries : any [ ] ;
7280
7381 public unitsSummary = UnitsSummary ;
7482
@@ -78,11 +86,101 @@ export class TreeGridDisableSummariesComponent implements OnInit {
7886 this . data = ORDERS_DATA ;
7987 }
8088
81- public disableDefaultSummaries ( ) {
82- this . treeGrid1 . getColumnByName ( "UnitPrice" ) . disabledSummaries = [ "min" , "max" ] ;
89+ public ngAfterViewInit ( ) : void {
90+ this . defaultSummaries = [
91+ {
92+ label : 'Count' ,
93+ selected : this . treeGrid1 . getColumnByName ( 'UnitPrice' ) . disabledSummaries . includes ( 'count' ) ,
94+ togglable : true ,
95+ value : 'count'
96+ } ,
97+ {
98+ label : 'Min' ,
99+ selected : this . treeGrid1 . getColumnByName ( 'UnitPrice' ) . disabledSummaries . includes ( 'min' ) ,
100+ togglable : true ,
101+ value : 'min'
102+ } ,
103+ {
104+ label : 'Max' ,
105+ selected : this . treeGrid1 . getColumnByName ( 'UnitPrice' ) . disabledSummaries . includes ( 'max' ) ,
106+ togglable : true ,
107+ value : 'max'
108+ } ,
109+ {
110+ label : 'Sum' ,
111+ selected : this . treeGrid1 . getColumnByName ( 'UnitPrice' ) . disabledSummaries . includes ( 'sum' ) ,
112+ togglable : true ,
113+ value : 'sum'
114+ } ,
115+ {
116+ label : 'Average' ,
117+ selected : this . treeGrid1 . getColumnByName ( 'UnitPrice' ) . disabledSummaries . includes ( 'average' ) ,
118+ togglable : true ,
119+ value : 'average'
120+ }
121+ ] ;
122+
123+ this . customSummaries = [
124+ {
125+ label : 'Total Units Delivered' ,
126+ selected : this . treeGrid1 . getColumnByName ( 'Units' ) . disabledSummaries . includes ( 'totalDelivered' ) ,
127+ togglable : true ,
128+ value : 'totalDelivered'
129+ } ,
130+ {
131+ label : 'Total Units Not Delivered' ,
132+ selected : this . treeGrid1 . getColumnByName ( 'Units' ) . disabledSummaries . includes ( 'totalNotDelivered' ) ,
133+ togglable : true ,
134+ value : 'totalNotDelivered'
135+ } ,
136+ {
137+ label : 'Average Units per Order' ,
138+ selected : this . treeGrid1 . getColumnByName ( 'Units' ) . disabledSummaries . includes ( 'averageUnits' ) ,
139+ togglable : true ,
140+ value : 'averageUnits'
141+ } ,
142+ {
143+ label : 'Highest Units' ,
144+ selected : this . treeGrid1 . getColumnByName ( 'Units' ) . disabledSummaries . includes ( 'maxUnits' ) ,
145+ togglable : true ,
146+ value : 'maxUnits'
147+ }
148+ ] ;
83149 }
84150
85- public disableCustomSummaries ( ) {
86- this . treeGrid1 . getColumnByName ( "Units" ) . disabledSummaries = [ "averageUnits" , "maxUnits" ] ;
151+ public disableDefaultSummary ( event ) {
152+ const selectedValue = this . defaultSummaries [ event . index ] . value ;
153+ const column = this . treeGrid1 . getColumnByName ( 'UnitPrice' ) ;
154+
155+ if ( ! column . disabledSummaries . includes ( selectedValue ) ) {
156+ column . disabledSummaries = [ ...column . disabledSummaries , selectedValue ] ;
157+ }
158+ }
159+
160+ public enableDefaultSummary ( event ) {
161+ const selectedValue = this . defaultSummaries [ event . index ] . value ;
162+ const column = this . treeGrid1 . getColumnByName ( 'UnitPrice' ) ;
163+
164+ column . disabledSummaries = column . disabledSummaries . filter (
165+ ( summary ) => summary !== selectedValue
166+ ) ;
167+ }
168+
169+ public disableCustomSummary ( event ) {
170+ const selectedValue = this . customSummaries [ event . index ] . value ;
171+ const column = this . treeGrid1 . getColumnByName ( 'Units' ) ;
172+
173+ if ( ! column . disabledSummaries . includes ( selectedValue ) ) {
174+ column . disabledSummaries = [ ...column . disabledSummaries , selectedValue ] ;
175+ }
176+ }
177+
178+ public enableCustomSummary ( event ) {
179+ const selectedValue = this . customSummaries [ event . index ] . value ;
180+ const column = this . treeGrid1 . getColumnByName ( 'Units' ) ;
181+
182+ column . disabledSummaries = column . disabledSummaries . filter (
183+ ( summary ) => summary !== selectedValue
184+ ) ;
87185 }
88186}
0 commit comments