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

Aligning items in group headers

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 07 Jul 2015, 07:28 PM

Hello,

 

I am attempting to display aggregate sums of groups in group headers in my RadGrid. I have attempted to use the instructions in the following article: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/grouping/how-to/aligning-items-in-groupheader

My issue is due to the fact that I am using multiple levels of grouping. I am not sure why, but when I use the code in the article mentioned above, the entries in my group headers become misaligned as shown in the attached image. In the picture shown, my goal is to have the 10,000's be lined up no matter which level of grouping they are in, and to have the product names behave as they would be normally. Is there any easier way to display group totals for each column in the group headers? If not, is there some modification that can be made to the code in the help article that will ensure that the header items are aligned in each level of group headers? Thanks

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 10 Jul 2015, 11:32 AM
Hi Lukas,

In order to align the headers as per the requirement you can modify the code of the article as demonstrated below.

C#:
void Item_PreRender(object sender, EventArgs e)
{
    string text = ((GridGroupHeaderItem)sender).DataCell.Text;
    int calculateStartIndex = 3+((GridGroupHeaderItem)sender).GroupIndex.Count(f => f == '_');
    for (int i = calculateStartIndex; i < ((GridGroupHeaderItem)sender).OwnerTableView.RenderColumns.Length; i++)
    {
        TableCell cell = new TableCell();
        string headerText = ((GridGroupHeaderItem)sender).OwnerTableView.RenderColumns[i].HeaderText;
        if (text.Contains(headerText) && headerText!=string.Empty)
        {
            cell.Text = text;
        }
        ((GridGroupHeaderItem)sender).Cells.Add(cell);
    }
}
The idea here is that the column header text is contained in the cell text and you can use it as an indicator when to display the text.

Regards,
Angel Petrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Lukas
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or