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

Center dynamic crosstab in report

2 Answers 229 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Joel asked on 04 Aug 2010, 03:07 PM
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 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 06 Aug 2010, 03:36 PM
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
0
Pavel
Top achievements
Rank 1
answered on 27 Jun 2012, 10:18 AM
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
Tags
General Discussions
Asked by
Joel
Top achievements
Rank 2
Answers by
Peter
Telerik team
Pavel
Top achievements
Rank 1
Share this question
or