Center dynamic crosstab in report

3 posts, 0 answers
  1. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 04 Aug 2010 Link to this post

    I have a crosstab that may be 2 columns or 20 columns and all rows and columns are set to canshrink and cangrow.  How can I display the crosstab so it is always centered within detailscection1? A 3 inch square crosstab looks looks quite odd left aligned in landscape.   If I center it, it seems to only grow to the right, causing it to page break for 1/2 the columns, while the left 1/2 of detail section is blank.
  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 06 Aug 2010 Link to this post

    Hi Joel,

    The default behavior for the Crosstab/Table/List/Subreport items is to grow on right. Our suggestion is not to center the Crosstab and avoid any whitespace. This way as the Crosstab grows so will its parent report section. Check out our Crosstab demo that came with your installation of Telerik Reporting that has a Crosstab with a dynamic rows and columns count.

    All the best,
    Peter
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Pavel
    Pavel avatar
    5 posts
    Member since:
    Jun 2012

    Posted 27 Jun 2012 Link to this post

    Hi Joel, 

    it seems I found a workaround for your issue. I am not sure if it is working in all cases but at least for my simple crosstab is working fine. It should work for table as well.

    Because I wanted to be as "dynamic" as possible I use it with Style.TextAlign option to find item I want to center.

    Example of usage:

               
    var items = report.Items
        .Flatten()
        .Where(i => i is Crosstab)
        .Where(i => i.Style.TextAlign == HorizontalAlign.Center)
        .Cast<Crosstab>();
     
    foreach (var item in items)
    {
        item.Center();
    }



    Extensions:

    using System.Collections.Generic;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
     
    public static class ReportExtensions
    {
        public static IEnumerable<ReportItemBase> Flatten(this ReportItemBase.ItemCollection items)
        {
            foreach (var item in items)
            {
                yield return item;
            }
     
            foreach (var item in items)
            {
                foreach (var childItem in item.Items.Flatten())
                {
                    yield return childItem;
                }
            }
        }
     
        public static void Center(this ReportItem item)
        {
            if (item is Crosstab || item is Table)
            {
                item.ItemDataBound +=
                    (sender, args) =>
                        {
                            var table = (Telerik.Reporting.Processing.Table) sender;
                            var width = Unit.Zero;
                            foreach (var col in table.Columns)
                            {
                                width += col.GetCell(0).Item.Width;
                            }
                            table.Left = (table.Report.Width - width)/2;
                        };
            }
        }
         
    }

    Regards,

    Pavel
Back to Top