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

RadGrid, Export To PDF trouble

4 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kiwi
Top achievements
Rank 1
Kiwi asked on 22 Dec 2013, 08:18 PM
Hello.
When exporting to PDF first column of the table is too narrow. How to set the width of it? use MasterTableView.GetColumn("").HeaderWidht does not help.
Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Dec 2013, 05:01 AM
Hi Kiwi,

You can set the HeaderStyle-Width property of the column as shown below. If this doesn't help, please provide your code snippet.

ASPX:
<telerik:GridBoundColumn DataField="ID" HeaderText="OrderID" HeaderStyle-Width="200px">
</telerik:GridBoundColumn>

Thanks,
Princy
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Dec 2013, 05:14 AM
Hello,

If you want to set width only export time then.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToPdfCommandName)
        {
            RadGrid1.MasterTableView.GetColumn("ID").HeaderStyle.Width = Unit.Pixel(100);
            RadGrid1.MasterTableView.GetColumn("ID").ItemStyle.Width = Unit.Pixel(100);
        }
    }
<Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
               </Columns>


Thanks,
Jayesh Goyani
0
Kiwi
Top achievements
Rank 1
answered on 23 Dec 2013, 06:55 PM
Jayesh Goyani, the problem is that it sets the specified width next column. For example, if a column "ID" to specify the width 300px, these will be applied 300px to the next colimn "name"..
0
Princy
Top achievements
Rank 2
answered on 24 Dec 2013, 07:31 AM
Hi Kiwi,

Below is a sample code snippet that i tried and the header width is set correctly. Please try it, if this doesn't help, provide your code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True"
    PageSize="5" AllowSorting="True" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnItemCommand="RadGrid1_ItemCommand">
    <ExportSettings IgnorePaging="true" ExportOnlyData="true">
    </ExportSettings>
    <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToPdfButton="true" />
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" SortExpression="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" SortExpression="Name">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
  
            new { ID = 1, Name ="Name1"},
            new { ID = 2, Name = "Name2"},
            new { ID = 3, Name = "Name3"},
            new { ID = 4, Name = "Name4"},
            new { ID = 5, Name = "Name5"},
            new { ID = 6, Name ="Name6"},
            new { ID = 7, Name = "Name7"},
            new { ID = 8, Name = "Name8"},
            new { ID = 9, Name = "Name9"},
            new { ID = 10, Name ="Name10"},
            new { ID = 11, Name ="Name11"},
            new { ID = 12, Name = "Name12"},
            new { ID = 13, Name = "Name13"},
            new { ID = 14, Name = "Name14"},
            new { ID = 15, Name = "Name15"}
        };
 
    RadGrid1.DataSource = data;
}
    
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        RadGrid1.MasterTableView.GetColumn("ID").HeaderStyle.Width = Unit.Pixel(50);
    }
}

Thanks,
Princy
Tags
Grid
Asked by
Kiwi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Kiwi
Top achievements
Rank 1
Share this question
or