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

Radgrid Align columns seperately on pdf export

2 Answers 314 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leon
Top achievements
Rank 1
Leon asked on 15 Jan 2014, 02:01 PM
Hi.

I would like to align my pdf when exported in such a manner that all string columns are aligned left and numeric columns aligned right.  I have tried many different ways with no such result.  Below is a code snippet of what I am currently using.

private void ApplyStylesToPDFExport(GridItem item)
{
    if (item is GridHeaderItem)
        foreach (TableCell cell in item.Cells)
        {
            cell.Style["font-family"] = "Verdana";
            cell.Style["text-align"] = "Left";
            cell.Style["font-size"] = "12pt";
        }
 
    if (item is GridDataItem)
    {
        item.Style["font-size"] = "12px";
        item.Style["background-color"] = item.ItemType == GridItemType.AlternatingItem ? "#DDDDDD" : "#AAAAAA";
        item.Style["horizontal-align"] = "Right";
    }
 
}

The method is then called in the item_created event.  This code is being used to try align headings to left and data to right with not much success.

Any help would be greatly appreciated.

Kind regards.
Leon Havenga

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Jan 2014, 07:01 AM
Hi Leon,

Please try the following code snippet to align the columns:

C#:
private void ApplyStylesToPDFExport(GridItem item)
{
    if (item is GridHeaderItem)
        foreach (TableCell cell in item.Cells)
        {         
            cell.Style["text-align"] = "middle"; // Header Alignment
        }
    if (item is GridDataItem)
    {    
        GridDataItem dataItem = item as GridDataItem;
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
        {
            if (col.DataType == typeof(string))
                dataItem[col].Style["text-align"] = "left"; // String columns to left
            else
                dataItem[col].Style["text-align"] = "right"; // Other column's text to the left
        }          
    }
}

Thanks,
Princy
0
Leon
Top achievements
Rank 1
answered on 16 Jan 2014, 07:07 AM
Hi Princy.

That seemed to have worked, thank you so much for the help, I have been struggeling with this for 2 days now.

Have a good day.

Kind regards.
Leon Havenga
Tags
Grid
Asked by
Leon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Leon
Top achievements
Rank 1
Share this question
or