Hi,
We have upgraded from Infragistics 2011.1 to Infragistics 2014.1 and are trying to get familiar with the new controls.
I am showing Summary(Sum) of columns in WebDataGrid. The grid has AutoGenerateColumns="true" and I am adding the summary row in code behind. I was able to add the summary for all numeric columns but I need to add a text ("Grand Total:") to the summary for the first column which is a string type. In the old version, we simply used to set it as the footer text.
Please advise how to do this.
ASPX:
<igtbl:WebDataGrid ID="wdgRAWNAVReported" AutoGenerateColumns="true" runat="server" OnDataBound="wgRAWNAVReported_DataBound" Height="560px" Width="100%" EnableTheming="True" EnableDataViewState="true" OnPreRender="WebDataGrid_OnPreRender"> <Behaviors> <igtbl:SummaryRow Enabled="true" ShowSummariesButtons="false" EmptyFooterText=""> </igtbl:SummaryRow> </Behaviors></igtbl:WebDataGrid>
C#:
foreach (GridField gridField in fields){ var ufield = gridField as AutoGeneratedDataField;
if (ufield != null) { if (!ufield.Key.ToLower().Contains("portfolio")) { var csi = new ColumnSummaryInfo(); csi.ColumnKey = ufield.Key; csi.Summaries.Add(SummaryType.Sum);
var srs = new SummaryRowSetting(); srs.ColumnKey = ufield.Key; srs.FormatString = "{1}"; srs.ShowSummaryButton = false; wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSummaries.Add(csi); wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSettings.Add(srs); } }}
Thanks!
Hi Sumit,Thank you for contacting Infragistics!
The Columns collection contains only columns that you have added to the collection. It does not contain any autogenerated columns. You can scan your datasource and create the columns that you need.In your case:foreach (DataColumn dataColumn in ((DataTable) wdgRAWNAVReported.DataSource).Columns){if (!dataColumn.Name.ToLower().Contains("portfolio")){var csi = new ColumnSummaryInfo();csi.ColumnKey = dataColumn.Name;csi.Summaries.Add(SummaryType.Sum);var srs = new SummaryRowSetting();srs.ColumnKey = dataColumn.Name;srs.FormatString = "{1}";srs.ShowSummaryButton = false;
wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSummaries.Add(csi);wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSettings.Add(srs); }}
The other way to get columns is form the row items collection. In InitializeRow row event you can use this:protected void WebDataGrid_InitializeRow(object sender, RowEventArgs e) { if (e.Row.Index == 0) { foreach (GridRecordItem field in wdgRAWNAVReported.Rows[0].Items) {
GridField column = field.Column; if (!column.Key.Contains("portfolio")) { var csi = new ColumnSummaryInfo(); csi.ColumnKey = column.Key; csi.Summaries.Add(SummaryType.Count);
var srs = new SummaryRowSetting(); srs.ColumnKey = column.Key; srs.FormatString = "{1}"; srs.ShowSummaryButton = false;
wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSummaries.Add(csi); wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSettings.Add(srs); } } } }
Hi Nadia,
I think you understood my question incorrectly. I need to be able to show text in a summary row cell, when all the others cells in the summary row show SUM.
Here is a simple example that conveys what I am looking for (I need to show "Grand Total:" text in the first column summary and actual SUM in the rest of the columns summary) -
Hi Sumit,To do this in the WebDataGrid_InitializeRow you should this:
protected void WebDataGrid_InitializeRow(object sender, RowEventArgs e) { if (e.Row.Index == 0) { foreach (GridRecordItem field in wdgRAWNAVReported.Rows[0].Items) {
GridField column = field.Column; if (!column.Key.Contains("portfolio")) { var csi = new ColumnSummaryInfo(); csi.ColumnKey = column.Key; csi.Summaries.Add(SummaryType.Sum);
wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSummaries.Add(csi); wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSettings.Add(srs); } // If The column is portfolio the add summary Count, but in the FormatString add the text which you want else { var csi = new ColumnSummaryInfo(); csi.ColumnKey = column.Key; csi.Summaries.Add(SummaryType.Count);
var srs = new SummaryRowSetting(); srs.ColumnKey = column.Key; srs.FormatString = "Grand Total:"; srs.ShowSummaryButton = false; wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSummaries.Add(csi); wdgRAWNAVReported.Behaviors.SummaryRow.ColumnSettings.Add(srs); } } }
Let me know if I may be of further assistance.
Thanks! That works perfect!
I am glad that you consider my suggestions helpful.