Column width

How to set the column width of the Pdfexport when exported already in A4 paper size?Screenshot (452).png


2 Replies

BC Belle Cruz December 3, 2021 01:57 AM UTC

Is there any update about my query?



RN Rahul Narayanasamy Syncfusion Team December 3, 2021 03:46 AM UTC

Hi Belle, 

Greetings from Syncfusion. 

We have validated your query and we suspect that you want to set different width to the Grid columns while exporting PDF document. You can achieve your requirement by using ExportProperties. DisableAutoFitWidth property of PdfExportProperties has to be enabled to achieve your requirement. Find the below code snippets for your reference. 

 
<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" AllowPaging="true"> 
    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    private SfGrid<Order> DefaultGrid; 
    public List<Order> Orders { get; set; } 
 
    public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
    { 
        if (args.Item.Id == "Grid_pdfexport"//Id is combination of Grid's ID and itemname 
        { 
            PdfExportProperties ExportProperties = new PdfExportProperties(); 
            ExportProperties.PageSize = PdfPageSize.A4; 
            ExportProperties.DisableAutoFitWidth = true; 
            List<GridColumn> ExportColumns = new List<GridColumn>(); 
#pragma warning disable BL0005 
            ExportColumns.Add(new GridColumn() { Field = "CustomerID", HeaderText = "Customer Name", Width = "140" }); 
            ExportColumns.Add(new GridColumn() { Field = "OrderDate", HeaderText = "Date", Width = "80", Format = "d" }); 
            ExportColumns.Add(new GridColumn() { Field = "Freight", HeaderText = "Freight", Width = "40", Format = "C2", TextAlign = TextAlign.Right }); 
#pragma warning restore BL0005 
            ExportProperties.Columns = ExportColumns; 
 
            await this.DefaultGrid.PdfExport(ExportProperties); 
        } 
    } 
    . . .  
} 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Loader.
Up arrow icon