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

[Solved] Hiding rows in Biff excel export

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 16 Aug 2013, 04:30 PM
I have a grid where I hide rows on the client side based on a combobox selection.  Something like this:

var grid = $find('<%=MyGrid.ClientID %>');
var masterTableView = grid.get_masterTableView();
 
// iterate through the rows and then use the
masterTableView.showItem();
//and
masterTableView.hideItem()
//methods

When I do a biff export, all the data is exported, regardless of the visibility I just set on the rows client-side.

My goal is to keep the same rows hidden for the export.

My idea was to use the grid's BiffExporting event to manipulate the ExportInfrastructure.Table object, and hide the same rows.  Is this possible?  Or am I going about this the wrong way?  I'm not even sure the visibility of the rows is available to me server side since I set them on the client side...

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2013, 01:00 PM
Hi Steve,

I'm afraid it not possible to hide a row on export using ClientSide events,because the values of the RadComboBox is not persisted when on export due to page being loaded again.Please try the below code snippet to access the values of RadComboBox and hide a row from ServerSide,and hide it even in the export.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCommand="RadGrid1_ItemCommand"
 onitemcreated="RadGrid1_ItemCreated">
    <ExportSettings ExportOnlyData="true" Excel-Format="Biff" IgnorePaging="true">
    </ExportSettings>
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="OrderID" >
        <CommandItemSettings ShowExportToExcelButton="true" />
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridTemplateColumn HeaderText="ShipVia" UniqueName="ShipVia" >
                <ItemTemplate>
                 <telerik:RadComboBox ID="RadCombobox1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="ShipVia" SelectedValue='<%# Bind("ShipVia") %>'  DataValueField="ShipVia" OnSelectedIndexChanged="RadCombobox1_SelectedIndexChanged">
                    </telerik:RadComboBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
bool isExport = false;
static string key = string.Empty;
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        isExport = true;          
    }
}
 
protected void RadCombobox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{      
    RadComboBox combo = sender as RadComboBox;
    GridDataItem item = (GridDataItem)combo.NamingContainer;     
    if (combo.SelectedValue == "1")
        {         
            item.Visible = false;
            key = ditem.GetDataKeyValue("OrderID").ToString();         
        }
    
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{      
        foreach (GridDataItem data in RadGrid1.MasterTableView.Items)
        {
            if ((isExport == true) && (data.GetDataKeyValue("OrderID").ToString() == key))
            {
                data.Visible = false;
                isExport = false;
            }
        }              
}

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