1
+ @using IgniteUI .Blazor .Controls
2
+
3
+ @inject IJSRuntime JS
4
+
5
+ <div class =" container vertical ig-typography" >
6
+ <div class =" container vertical fill" >
7
+ <div class =" wrapper" >
8
+ <span class =" summaries-title" >Disable Summaries for Column:</span >
9
+ <div class =" summaries-buttons" >
10
+ @if (grid != null && columns ? .Length > 0 )
11
+ {
12
+ @foreach ( IgbColumn column in columns )
13
+ {
14
+ <IgbButton Variant =" ButtonVariant.Contained" class =" summary-button"
15
+ @onclick =" () => OnDialogShow(column)" >@column.Header </IgbButton >
16
+ }
17
+ }
18
+ </div >
19
+ <IgbDialog @ref =" dialog" Title =" @dialogTitle" CloseOnOutsideClick =" true" >
20
+ <div class =" summaries-dialog-items" >
21
+ @if (currentColumn != null && currentColumn .HasSummary && summaries .Count () > 0 )
22
+ {
23
+ @foreach ( var summary in this .summaries )
24
+ {
25
+ <IgbCheckbox Value =" @summary.Key" Checked =" @currentColDisabledSummaries.Contains(summary.Key)"
26
+ Change =" @((evt) => ToggleSummary(evt))" >@summary.Value </IgbCheckbox >
27
+ }
28
+ }
29
+ </div >
30
+ <IgbButton slot =" footer" Variant =@ButtonVariant.Flat Disabled =" currentColDisabledSummaries.Count == summaries.Count()"
31
+ @onclick =" () => ToggleAllSummaries(false)" >Disable All</IgbButton >
32
+ <IgbButton slot =" footer" Variant =@ButtonVariant.Flat Disabled =" currentColDisabledSummaries.Count == 0"
33
+ @onclick =" () => ToggleAllSummaries(true)" >Enable All</IgbButton >
34
+ </IgbDialog >
35
+
36
+ <IgbGrid AutoGenerate =" false"
37
+ Name =" grid"
38
+ Id =" grid"
39
+ @ref =" grid"
40
+ Data =" NwindData"
41
+ PrimaryKey =" ProductID"
42
+ ColumnInitScript =" ColumnInitScript" >
43
+ <IgbColumn Field =" ProductID"
44
+ Name =" ProductID"
45
+ Header =" Product ID"
46
+ HasSummary =" true"
47
+ @ref =" productID" >
48
+ </IgbColumn >
49
+
50
+ <IgbColumn Name =" ProductName"
51
+ @ref =" productName"
52
+ Field =" ProductName"
53
+ Header =" Product Name"
54
+ HasSummary =" true" >
55
+ </IgbColumn >
56
+
57
+ <IgbColumn Name =" UnitPrice"
58
+ @ref =" unitPrice"
59
+ Field =" UnitPrice"
60
+ Header =" Unit Price"
61
+ HasSummary =" true" >
62
+ </IgbColumn >
63
+
64
+ <IgbColumn Name =" UnitsInStock"
65
+ @ref =" unitsInStock"
66
+ Field =" UnitsInStock"
67
+ Header =" Units In Stock"
68
+ HasSummary =" true"
69
+ DataType =" GridColumnDataType.Number" >
70
+ </IgbColumn >
71
+
72
+ <IgbColumn Name =" Discontinued"
73
+ @ref =" discontinued"
74
+ Field =" Discontinued"
75
+ HasSummary =" true"
76
+ Header =" Discontinued" >
77
+ </IgbColumn >
78
+
79
+ <IgbColumn Name =" OrderDate"
80
+ @ref =" orderDate"
81
+ Field =" OrderDate"
82
+ Header =" Order Date"
83
+ HasSummary =" true"
84
+ DataType =" GridColumnDataType.Date" >
85
+ </IgbColumn >
86
+
87
+ </IgbGrid >
88
+ </div >
89
+
90
+ </div >
91
+ </div >
92
+
93
+ @code {
94
+ private IgbGrid grid ;
95
+ private IgbColumn productID ;
96
+ private IgbColumn productName ;
97
+ private IgbColumn unitPrice ;
98
+ private IgbColumn unitsInStock ;
99
+ private IgbColumn discontinued ;
100
+ private IgbColumn orderDate ;
101
+
102
+ private IgbColumn [] columns { get ; set ; } = [];
103
+ private IgbColumn currentColumn ;
104
+
105
+ private Dictionary <string , string > summaries = [];
106
+ private List <string > currentColDisabledSummaries { get ; set ; } = new List <string >();
107
+
108
+ private IgbDialog dialog ;
109
+ private string dialogTitle ;
110
+
111
+ private NwindData _nwindData = null ;
112
+ public NwindData NwindData
113
+ {
114
+ get
115
+ {
116
+ if (_nwindData == null )
117
+ {
118
+ _nwindData = new NwindData ();
119
+ }
120
+ return _nwindData ;
121
+ }
122
+ }
123
+
124
+ protected override async Task OnAfterRenderAsync (bool firstRender )
125
+ {
126
+ if (firstRender )
127
+ {
128
+ if (grid != null )
129
+ {
130
+ columns = new IgbColumn [] { productID , productName , unitPrice , unitsInStock , discontinued , orderDate };
131
+ StateHasChanged ();
132
+ }
133
+ }
134
+ }
135
+
136
+ public async Task OnDialogShow (IgbColumn column )
137
+ {
138
+ if (this .dialog != null )
139
+ {
140
+ this .currentColumn = column ;
141
+ this .dialogTitle = " Disable Summaries for: " + column .Header ;
142
+ this .currentColDisabledSummaries .Clear ();
143
+ if (currentColumn .DisabledSummaries != null )
144
+ {
145
+ this .currentColDisabledSummaries = currentColumn .DisabledSummaries ? .ToList ();
146
+ }
147
+ await this .GetSummaryKeysAsync ();
148
+ await this .dialog .ShowAsync ();
149
+ }
150
+ }
151
+
152
+ private async Task GetSummaryKeysAsync ()
153
+ {
154
+ if (currentColumn != null && currentColumn .HasSummary )
155
+ {
156
+ summaries = await JS .InvokeAsync <Dictionary <string , string >>(" getSummaries" , currentColumn .Field );
157
+ StateHasChanged ();
158
+ }
159
+ }
160
+
161
+ public async Task ToggleSummary (IgbCheckboxChangeEventArgs eventArgs )
162
+ {
163
+ if (currentColumn != null && currentColumn .HasSummary )
164
+ {
165
+ string summaryKey = eventArgs .Detail .Value ;
166
+ if (eventArgs .Detail .Checked && ! currentColDisabledSummaries .Contains (summaryKey ))
167
+ {
168
+ currentColDisabledSummaries .Add (summaryKey );
169
+ }
170
+ else if (! eventArgs .Detail .Checked && currentColDisabledSummaries .Contains (summaryKey ))
171
+ {
172
+ currentColDisabledSummaries .Remove (eventArgs .Detail .Value );
173
+ }
174
+ currentColumn .DisabledSummaries = currentColDisabledSummaries .ToArray ();
175
+ }
176
+ }
177
+
178
+ public async Task ToggleAllSummaries (bool enable )
179
+ {
180
+ if (currentColumn != null && currentColumn .HasSummary )
181
+ {
182
+ if (enable )
183
+ {
184
+ currentColDisabledSummaries .Clear ();
185
+ }
186
+ else
187
+ {
188
+ currentColDisabledSummaries = summaries .Keys .ToList ();
189
+ }
190
+ currentColumn .DisabledSummaries = currentColDisabledSummaries .ToArray ();
191
+ }
192
+ }
193
+ }
0 commit comments