This is a migrated thread and some comments may be shown as answers.

Group by questions

3 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 08 Jul 2010, 03:25 PM
Hi there,

Please see the attached image.  I am grouping my data, but I need some questions answered.

I want "Type:" not to display.  There should be just "Achievers" or "Ongoing".

Next to "Achievers" and "Ongoing" I need the group total to display, just above the item count.  So to the right of "Achievers" I need the value to be 5.

I had a look at the samples online, and the forum.  I think there were 2 posts in the forum.

Here is my code:

<telerik:RadGrid
  AllowPaging="false"
  AutoGenerateColumns="false"
  GridLines="None"
  ID="rgNominationsReportSummary"
  runat="server"
  ShowHeader="false"
  Width="450">
  <MasterTableView Name="NominationsSumary">
    <GroupByExpressions>
      <telerik:GridGroupByExpression>
        <SelectFields>
          <telerik:GridGroupByField FieldName="NominationTypeName" FieldAlias="Type" />
        </SelectFields>
        <GroupByFields>
          <telerik:GridGroupByField FieldName="NominationTypeName" />
        </GroupByFields>
      </telerik:GridGroupByExpression>
    </GroupByExpressions>
    <Columns>
      <telerik:GridBoundColumn DataField="NominationStatusName" HeaderText="Status">
        <ItemStyle Width="88%" />
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="NominationCount" HeaderText="Count">
        <HeaderStyle HorizontalAlign="Right" />
        <ItemStyle HorizontalAlign="Right" Width="12%" />
      </telerik:GridBoundColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

Thanks
Brendan

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jul 2010, 12:17 PM
Hello Brendan,


In order to achieve this, calculate the total count of each GroupHeaderItem and then assign it to GroupHeader.Datacell.Text (which gives you the complete text shown in the group header). Check out the following code snippet.

C#:
      int count;
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
       foreach (GridGroupHeaderItem groupHeader in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
        {
            GridItem[] children = groupHeader.GetChildItems();
            foreach (GridDataItem child in children)
            {
                GridDataItem childItem = child as GridDataItem;
                string v = childItem["NominationCount"].Text;
                count= count+ Convert.ToInt16(v);
            }
            groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1].ToString() + ", Total Count: " + count;
            count = 0;
        }
    }

Take a look at the following documentation which expalins how to customize GridGroupHeaderItem.
Customizing GridGroupHeaderItem

Hope this helps,
Princy.
0
Brendan Vogt
Top achievements
Rank 1
answered on 14 Jul 2010, 09:38 AM
Hi Princy,

Thanks for the answer, but it is not 100% what I am looking for,  I what the 2 items to split.  Nomination type on the left and the count to the right.  How do I do this?  I changed my grid like this:

<telerik:GridGroupByField FieldName="NominationTypeName" />
<telerik:GridGroupByField FieldName="NominationCount" Aggregate="Sum" />

It calculates correctly, but I need it to be split.  Here is my code:

protected void rgNominationsReportSummary_ItemDataBound(object sender, GridItemEventArgs e)
{
   switch (e.Item.OwnerTableView.Name)
   {
      case "NominationsSumary":

         if (e.Item is GridGroupHeaderItem)
         {
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

            foreach (DataColumn column in groupDataRow.DataView.Table.Columns)
            {
               if (column.ColumnName == "NominationTypeName")
               {
                  item.DataCell.Text = groupDataRow["NominationTypeName"].ToString();
               }
               if (column.ColumnName == "NominationCount")
               {
                  item.DataCell.Text = groupDataRow["NominationCount"].ToString();
               }
            }
         }

         break;
   }
}

I thought that by using this code it will modify the data cell beneath the column.  But I see that item.DataCell is the whole header part.

How would I do this?

Thanks
Brendan

0
Brendan Vogt
Top achievements
Rank 1
answered on 14 Jul 2010, 10:23 AM
Hi,

How do I get rid of the expand button?
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Brendan Vogt
Top achievements
Rank 1
Share this question
or