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

Custom Text for ContexHeaderMenu

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Viviane
Top achievements
Rank 1
Viviane asked on 01 Mar 2016, 05:19 PM

Hello,

I need to change the text inside the ContextHeaderMenu in  a radgrid.

I have the following code on my Page_Load:

AddHandler RadGridTransmission.HeaderContextMenu.ItemCreated, AddressOf Me.ContextHeaderMenu_ItemCreated

And the following code to change text in the context menu:

Protected Sub ContextHeaderMenu_ItemCreated(ByVal sender As Object, _
ByVal e As RadMenuEventArgs)

If (e.Item.Value = "ColumnsContainer") Then
e.Item.Text = "Show/Hide columns"

ElseIf (e.Item.Level = 2) AndAlso (TryCast(e.Item.Parent, RadMenuItem).Value = "ColumnsContainer") Then
If (e.Item.Value.EndsWith("ReceiverID")) Then
  e.Item.Text = "Source Receiver ID"
End If

End Sub

 

The part that changes the text to "Show/Hide columns" works but the one to change the text for items in "ColumnsContainer" doesn't.

It finds the item, sets the text but does not change when I run the code.

Any idea?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Mar 2016, 01:23 PM
Hello Viviane,

The column names in the menu are generated on client-side based on the HeaderText of a given column. Therefore, we will need to change the text on the client using script logic or modify the HeaderText property of the column.

One approach to achieve this requirement is using this approach:
Copy Code
protected void RadGrid1_DataBound(object sender, EventArgs e)
{
    GridColumn col = RadGrid1.MasterTableView.GetColumn("ShipName");
    col.HeaderText = "Source Ship Name";
    GridHeaderItem item = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
    item[col.UniqueName].Text = "Ship Name";
}

Alternatively, you can use the following solution:
Copy Code
<HeaderContextMenu OnClientLoad="headerContextMenuLoad">
</HeaderContextMenu>
JavaScript:
Copy Code
function headerContextMenuLoad(sender, args) {
    var item = sender.findItemByText("ShipName");
    if (item) {
        $(item.get_element()).find("label").text("Source Ship Name");
    }
}

I've prepared a sample RadGrid web site to demonstrate that these suggestions work as expected. I'm also sending another application to demonstrate a more advanced scenario.

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Viviane
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or