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

I have an issue about Group Footer.

3 Answers 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aminul
Top achievements
Rank 1
Aminul asked on 20 Aug 2014, 09:04 AM
Hello,

I want to set color in group header row and group footer row. I am able to set individual color for each group header row and its working ok.  
But I can’t do this for group footer row.  I have 3 fields for grouping also have 3 group header row and 3 group footer rows.
Header rows color is ok. But I can’t set color for group footer row for a specific group header row. (Example: GroupFooterRow1 for GroupHeaderRow1)

Please see in attached image. Yellow color mark have wrong footer color, this color should go under 2 rows.

protected void RadGrid1_OnPreRender(object sender, EventArgs e)
{
         var j = 0;
        foreach (GridGroupFooterItem footerItem in  RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter))
        {
            if (j == 0) { footerItem.Style.Add("background-color", "#23A323");}
            else if (j == 1) {footerItem.Style.Add("background-color", "Green");}
            if (j == 2){footerItem.Style.Add("background-color", "#035E03");}
           
           j++;
          if (j == 3)
               j = 0;
       }
}

Is it possible to get group footer row for a specific group header row? (Example: GroupFooterRow1 for GroupHeaderRow1, GroupFooterRow2 for GroupHeaderRow2)

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 20 Aug 2014, 09:49 AM
Hi Aminul,

Please try the following code snippet to set the color for GroupFooter and GroupHeader.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridGroupFooterItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter))
    {
        //set the colspan, so that the template cells are aligned with the grid columns
        for (int i = 0; i <= item.Cells.Count - 1; i++)
        {
            (item.Cells[i] as TableCell).ColumnSpan = 1;
                 
        }
        //color the footer labels based on the group index
        SetFooterLabelsColor(item);
    }
 
    foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
    {
        //color the header labels based on the group index
        SetHeaderLabelsColor(item);
    }
}
private void SetFooterLabelsColor(GridGroupFooterItem item)
{
    int index = item.GroupIndex.Split('_').Length;      
    switch (index)
    {
        case 1:
            item.BackColor = Color.Gold;
            break;
        case 2:
            item.BackColor = Color.White;            
            break;
        case 3:
            item.BackColor = Color.Turquoise;           
            break;
        case 4:
            item.BackColor = Color.Aqua;            
            break;
    }
}
 
private void SetHeaderLabelsColor(GridGroupHeaderItem item)
{
    int index = item.GroupIndex.Split('_').Length;     
    switch (index)
    {
        case 1:
            item.BackColor = Color.Red;             
            break;
 
        case 2:
            item.BackColor = Color.Blue;           
            break;
        case 3:
            item.BackColor = Color.Yellow;        
            break;
        case 4:
            item.BackColor = Color.Green;           
            break;
    }
}

Thanks,
Princy
0
Aminul
Top achievements
Rank 1
answered on 20 Aug 2014, 10:54 AM
Hi Princy,

Thanks for give me this code snippet. Its working.


Also I have another issue.
How can I make group footer row left-align same as group header row?


Thanks
aminul
0
Princy
Top achievements
Rank 1
answered on 21 Aug 2014, 05:05 AM
Hi Aminul,

Please add the following code in the PreRender event to align footer to left.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 foreach (GridGroupFooterItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter))
  {      
    item.HorizontalAlign = HorizontalAlign.Left;      
    SetFooterLabelsColor(item);
  }  
}

Thanks,
Princy
Tags
Grid
Asked by
Aminul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Aminul
Top achievements
Rank 1
Share this question
or