Hello All ,
I have grid where i am using the Template for the Header columns For ex :
<
telerikGridView:GridViewDataColumn IsGroupable="True" IsSortable="True" SortMemberPath="IdentifiedSE" GroupMemberPath="IdentifiedSE"
HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" DataMemberBinding="{Binding IdentifiedSE}" IsFilterable="True">
<telerikGridView:GridViewDataColumn.Header >
<TextBlock Text="TR" TextDecorations="Underline" Foreground="#FF004083" />
</telerikGridView:GridViewDataColumn.Header>
<telerikGridView:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding IdentifiedSE}"/>
</DataTemplate>
</telerikGridView:GridViewDataColumn.CellTemplate>
So when i am exporting the Grid . This Header Column which i mentioned is exported as "System.Window.Controls.TextBlock"
I want the Header name to be exported insted of the Control type and another thing is i want to chnage the back ground of the header . can some one please post me the code for this
Regards,
Phani
7 Answers, 1 is accepted
In case you insert a custom UIElement in the header of a GridViewColumn, you will need to handle the ElementExporting event on RadGridView, check if the exported element is a header cell and set the appropriate value, as there is no way for the RadGridView to know the meaningful value of a UIElement.
You can find a demo that shows how to customize the appearance of the elements of the exported table here. Please be aware that such customization is only available when exporting to HTML.
Greetings,
Yavor Georgiev
the Telerik team
Do you have a quick sample how to handle the custom headers in the ElementExporting event?
In my case, I have three textblock controls in a DataTemplate Header as:
<
telerik:GridViewDataColumn.Header
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Text
=
"1st Input"
Grid.ColumnSpan
=
"2"
HorizontalAlignment
=
"Center"
TextAlignment
=
"Center"
TextWrapping
=
"Wrap"
Margin
=
"0,2"
/>
<
TextBlock
Text
=
"Second Input"
Grid.Column
=
"0"
Grid.Row
=
"1"
HorizontalAlignment
=
"Left"
Margin
=
"4,2"
/>
<
TextBlock
Text
=
"Actual Input"
Grid.Column
=
"1"
Grid.Row
=
"1"
HorizontalAlignment
=
"Center"
Margin
=
"4,2"
/>
</
Grid
>
</
telerik:GridViewDataColumn.Header
>
Thank you,
What you can do is handle the ElementExporting event and replace the Value property of the event args object with a meaningful string representation of the column header. However, if you'd like to insert HTML code, you'll need to handle the ElementExported event and use the ExportWriter object exposed in the event args to write the HTML code to the underlying export stream. In this case, don't forget to set the exporting value to null in the ElementExporting event beforehand, as you'll end up with both the Grid.ToString() output and the HTML code you wrote to the stream.
Best wishes,
Yavor Georgiev
the Telerik team
I have the same doubt that John. I have put the ElementExporting and ElementExported.
But I could not create the division in the header it put \< insted <
and I don't know the property to identify the column that has to be split.
could you help me?
You may download a runnable project, which demonstrates how to export column headers, following this link.
Vanya Pavlova
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
I have resolved the problem with the header in this way:
private
void RadGridEnrollmentDetail_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
if (e.Element == ExportElement.HeaderCell)
{
if (e.Value.ToString() == "Telerik.Windows.Controls.GridView.GridViewCellBase")
{
e.ShouldEncodeValue =
false;
e.Value =
"<table><tr><td colspan=\"3\">Lessons</td></tr><tr><td>Authorized</td><td>Taken</td><td>Remaining</td></tr></table>";
}
if (e.Value.ToString() == "System.Windows.Controls.Grid")
{
e.Value =
"Country";
}
}
}
Now I need to export the 3 columns according the header I am using
void RadGridEnrollmentDetail_ElementExporting(object sender, GridViewElementExportingEventArgs e)
but I can not use the example that is available in the samples. It retreives a completed row I just need retrieve the 3 field on the cell .
<
telerik:GridViewDataColumn DataMemberBinding="{Binding LessonsEnrollment}" IsReadOnly="True" Width="210" HeaderCellStyle="{StaticResource GridHeaderColumn}">
<telerik:GridViewDataColumn.Header>
<telerik:GridViewCellBase>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="3" Style="{StaticResource GridHeaderGroupBackground}">
<TextBlock Margin="2" Text="Lessons" Style="{StaticResource GridHeaderGroupForeground}"/>
</Border>
<TextBlock Margin="2" Text="Authorized" Grid.Row="1" Width="70" />
<TextBlock Margin="2" Text="Taken" Grid.Row="1" Grid.Column="1" Width="70" />
<TextBlock Margin="2" Text="Remaining" Grid.Row="1" Grid.Column="2" Width="70"/>
</Grid>
</telerik:GridViewCellBase>
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Width="70">
<TextBlock Margin="2" Text="{Binding LessonsEnrollment.Authorized, StringFormat='{}{0:N0}'}" TextAlignment="Right" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Width="70">
<!--<TextBlock Margin="2" Text="FirstName: " FontWeight="Bold" />-->
<TextBlock Margin="2" Text="{Binding LessonsEnrollment.Taken, StringFormat='{}{0:N0}'}" TextAlignment="Right"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" Width="70">
<!--<TextBlock Margin="2" Text="LastName: " FontWeight="Bold" />-->
<TextBlock Margin="2" Text="{Binding LessonsEnrollment.Remaining, StringFormat='{}{0:N0}'}" TextAlignment="Right"/>
</StackPanel>
</Grid>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
So I want to filter it using the example
CustomFilterDescriptor
I think this method needs tobe changed
private
IFilterDescriptor CreateFilterForColumn(GridViewDataColumn column)
{
FilterOperator filterOperator = GetFilterOperatorForType(column.DataType);
FilterDescriptor descriptor = new FilterDescriptor(column.UniqueName, filterOperator, this.filterValue);
descriptor.MemberType = column.DataType;
return descriptor;
}
Somebody can help me in order to search the text into the Lessons objec
class Lessons
{
public int taken
{
get;
set;
}
public int Authorized
{
get;
set;
}
}
Thanks in advance for any help