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

How to set fixed column widths

3 Answers 222 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
jlj30
Top achievements
Rank 2
jlj30 asked on 30 Nov 2012, 07:02 PM
Hi,

I am liking this new control, but I have one challenge.
My data has a variable number of columns returned.
I would like to set the column widths (beyond the 1st one) to a fixed size.
However, the column widths appear to be adjusted to fill up the available space.

Any thoughts?

Jim

<telerik:RadPivotGrid ID="grdRACI" runat="server" AllowFiltering="False" DataSourceID="sqlRACI" ClientSettings-Scrolling-AllowVerticalScroll="false"
                        TotalsSettings-GrandTotalsVisibility="None" Skin="Vista" AggregatesLevel="-1" ColumnHeaderCellStyle-Width="100px" RowHeaderCellStyle-Width="400px"
                        AggregatesPosition="Columns" OnCellDataBound="grdRACI_CellDataBound" IsFilterCommandInProgress="False" DataCellStyle-Width="100px" RowHeaderTableLayout="Fixed" ColumnHeaderTableLayout="Fixed"
                        ShowColumnHeaderZone="False" ShowDataHeaderZone="False" ShowFilterHeaderZone="False">
                        <Fields>
                            <telerik:PivotGridRowField DataField="Task" UniqueName="column">
                            </telerik:PivotGridRowField>
                            <telerik:PivotGridColumnField DataField="RoleName" UniqueName="column1">
                            </telerik:PivotGridColumnField>
                            <telerik:PivotGridAggregateField DataField="RACI" Aggregate="Max" GrandTotalAggregateFormatString=""
                                UniqueName="column2">
                            </telerik:PivotGridAggregateField>
                        </Fields>
                        <TotalsSettings GrandTotalsVisibility="None" />
                        <ConfigurationPanelSettings Position="FieldsWindow" />
                    </telerik:RadPivotGrid>
 
    protected void grdRACI_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
    {
        if (e.Cell is PivotGridColumnHeaderCell)
        {
            PivotGridColumnHeaderCell cell = e.Cell as PivotGridColumnHeaderCell;
            cell.HorizontalAlign = HorizontalAlign.Center;
            cell.Wrap = true;
        }
 
        if (e.Cell is PivotGridDataCell)
        {
            Color CFFD_Highlight = Color.Beige;
 
            PivotGridDataCell dataCell = e.Cell as PivotGridDataCell;
            if (dataCell != null)
            {
                switch (dataCell.Text)
                {
                    case ("1"):
                        dataCell.Text = "R";
                        break;
                    case ("2"):
                        dataCell.Text = "A";
                        break;
                    case ("3"):
                        dataCell.Text = "C";
                        break;
                    case ("4"):
                        dataCell.Text = "I";
                        break;
                    case ("5"):
                        dataCell.Text = "R/A";
                        break;
                    case ("10"):
                        dataCell.Text = "R";
                        dataCell.BackColor = CFFD_Highlight;
                        break;
                    case ("20"):
                        dataCell.Text = "A";
                        dataCell.BackColor = CFFD_Highlight;
                        break;
                    case ("30"):
                        dataCell.Text = "C";
                        dataCell.BackColor = CFFD_Highlight;
                        break;
                    case ("40"):
                        dataCell.Text = "I";
                        dataCell.BackColor = CFFD_Highlight;
                        break;
                    case ("50"):
                        dataCell.Text = "R/A";
                        dataCell.BackColor = CFFD_Highlight;
                        break;
                }
                dataCell.HorizontalAlign = HorizontalAlign.Center;
            }
        }
    }

3 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 05 Dec 2012, 11:09 AM
Hello Jim,

In order to achieve your scenario you could set the RadPivotGrid.ColumHeaderCellStyle which will force the column cells to be with the specified width.
<ColumnHeaderCellStyle Width="50px" />


Kind regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
jlj30
Top achievements
Rank 2
answered on 05 Dec 2012, 03:17 PM
Hi,

Your suggestion did not work.
What I see (and I thought I used to be able to provide attachments in these forums) is the following:
  • The "content' of each column appears to be the requested width and is centered horizontally (per my code behind), but
  • The "content" is placed within the left side of a much wider column

In other words, the columns appear to have their widths adjusted to fill up the width of my screen.

Here's my grid declaration now:

<telerik:RadPivotGrid ID="grdRACI" runat="server" AllowFiltering="False" DataSourceID="sqlRACI"
                            ClientSettings-Scrolling-AllowVerticalScroll="false" TotalsSettings-GrandTotalsVisibility="None"
                            Skin="Vista" AggregatesLevel="-1" AggregatesPosition="Columns" OnCellDataBound="grdRACI_CellDataBound"
                            IsFilterCommandInProgress="False" ShowColumnHeaderZone="False" ShowDataHeaderZone="False"
                            ShowFilterHeaderZone="False" ClientSettings-Scrolling-ScrollHeight="600">
                            <Fields>
                                <telerik:PivotGridRowField DataField="Task" UniqueName="column">
                                </telerik:PivotGridRowField>
                                <telerik:PivotGridColumnField DataField="RoleName" UniqueName="column1">
                                </telerik:PivotGridColumnField>
                                <telerik:PivotGridAggregateField DataField="RACI" Aggregate="Max" GrandTotalAggregateFormatString=""
                                    UniqueName="column2">
                                </telerik:PivotGridAggregateField>
                            </Fields>
                            <TotalsSettings GrandTotalsVisibility="None" />
                            <ConfigurationPanelSettings Position="FieldsWindow" />
                            <DataCellStyle Width="100px" />
                            <ColumnHeaderCellStyle Width="100px" />
                            <RowHeaderCellStyle Width="350px" />
                        </telerik:RadPivotGrid>

The RowHeaderCellStyle appears to be working as desired.

Any ideas on what to try next?

Thanks

Jim

0
Antonio Stoilkov
Telerik team
answered on 07 Dec 2012, 09:03 AM
Hello Jim,

Based on your description it is hard to determine the cause of the issue. You could try the RowHeaderTableLayout property and change its value. Additionally, you could take a look at the demo below and try different RowTableLayouts.

If you issue still persists you could open a formal ticket uploading a sample project showing the unwanted behavior so we could be able to investigate it and advise you with the best possible solution.

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
PivotGrid
Asked by
jlj30
Top achievements
Rank 2
Answers by
Antonio Stoilkov
Telerik team
jlj30
Top achievements
Rank 2
Share this question
or