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

Master / Details Styling (Excel Export)

2 Answers 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 09 Jul 2014, 09:34 AM


Hi,

I have grid control that that has master / detail
setup.  I’m trying to get this to export
to excel (html) but I’m having trouble figuring out how to apply 1 type of
formatting to master data and another type of formatting to child data


So for example this code applies formatting to all rows


        
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    GridDataItem item = e.Cell.Parent as GridDataItem;
 
    if (item.ItemType == GridItemType.AlternatingItem)
        item.Style["background-color"] = "#359AFF";
    else
        item.Style["background-color"] = "#2D62FF";
 
}


 Any ideas how I accomplish separate formatting please?

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Jul 2014, 07:50 AM
Hello Andy,

For distinguishing the item's table view and determining whether the items is within the MasterTableView or within a DetailTable you could use the Name property of the TableView's and use that name for your condition.

For example, if you set the Name property of your MasterTableView to "MasterTable", you could modify your current code as shown bellow:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnExportCellFormatting="RadGrid1_ExportCellFormatting">
    <MasterTableView Name="MasterTable" AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemSettings-ShowExportToExcelButton="true">
    ....

And the code-behind:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    GridDataItem item = e.Cell.Parent as GridDataItem;
 
    if (item.OwnerTableView.Name == "MasterTable")
    {
        if (item.ItemType == GridItemType.AlternatingItem)
            item.Style["background-color"] = "#359AFF";
        else
            item.Style["background-color"] = "#2D62FF";
    }
    else
    {
        //apply different styles for nested TableViews
    }
}

Hope this helps.
 

Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Andy
Top achievements
Rank 1
answered on 16 Jul 2014, 07:44 AM
Many thanks.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Andy
Top achievements
Rank 1
Share this question
or