AUTHOR: Marin Bratanov
DATE POSTED: April 17, 2018
Hide (remove) the filter row from the excel export.
The filter row is rendered below the headers in the excel export. It is usually blank but if you use custom FilterTemplate logic, you will get its contents in the cells. Since those filters cannot work and the actual controls cannot be rendered, you will only have some text or HTML tags.
To do this, you need to use the PreRender event of the grid with its IsExporting flag, and the GetItems method. Then, just set the Visible property of the filter item to false. Here is an example:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(RadGrid1.IsExporting)
foreach
(GridFilteringItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
item.Visible =
false
;
}
RadGrid1_NeedDataSource(
sender, GridNeedDataSourceEventArgs e)
RadGrid1.DataSource = GetDummyData();
DataTable GetDummyData()
DataTable dt =
new
DataTable();
dt.Columns.Add(
"numbers"
,
typeof
(
decimal
));
"someField"
int
"someDate"
(DateTime));
dt.Rows.Add(1, 2,
DateTime(2011, 06, 12));
dt.Rows.Add(2, 3,
DateTime(2011, 12, 12));
dt.Rows.Add(3, 6,
DateTime(2012, 06, 17));
dt.Rows.Add(4, 4,
DateTime(2012, 09, 18));
dt.Rows.Add(5, 7,
DateTime(2013, 03, 18));
return
dt;
<
telerik:RadGrid
runat
=
"server"
ID
"RadGrid1"
OnPreRender
"RadGrid1_PreRender"
OnNeedDataSource
"RadGrid1_NeedDataSource"
AutoGenerateColumns
"false"
AllowFilteringByColumn
"true"
>
ExportSettings
Excel-Format
"Xlsx"
IgnorePaging
ExportOnlyData
OpenInNewWindow
</
MasterTableView
CommandItemDisplay
"Top"
CommandItemSettings
ShowExportToExcelButton
/>
Columns
telerik:GridBoundColumn
DataField
UniqueName
HeaderText
"large numbers"
DataType
"System.Decimal"
></
"someColumn"
"another column"
FilterTemplate
my custom filter template
telerik:GridDateTimeColumn
"dateColumn"
"the date"
Resources Buy Try