Aligning items in group headers

2 posts, 0 answers
  1. Lukas
    Lukas avatar
    5 posts
    Member since:
    Jun 2015

    Posted 07 Jul 2015 Link to this post

    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

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1095 posts

    Posted 10 Jul 2015 Link to this post

    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
Back to Top