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

How to get column name while double clicking on the column & Change the color of the Column header

1 Answer 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kaushal
Top achievements
Rank 1
Kaushal asked on 21 Oct 2010, 07:43 AM

Hi,

I want to get column name while user double clicking on the column header & Change the color of the Column header just to indicate that the currenet selected column.
I have to remove the selected column from the grid.

Thanks & Regards
Kaushal.

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 Oct 2010, 10:58 AM
Hello Kaushal,

To achieve the desired functionality you could try using the following approach:
On client side OnColumnDblClick you could get the column unique name and change the cssClass of the column's header:
ASPX
<telerik:RadGrid runat="server" ID="RadGrid1">
  <ClientSettings>
    <ClientEvents OnColumnDblClick="OnColumnDblClick" OnColumnClick="OnColumnClick" />
  </ClientSettings>
</telerik:RadGrid>

JavaScript
function OnColumnDblClick(sender, eventArgs)
{
     var columnUniqueName = eventArgs.get_gridColumn().get_uniqueName();
     alert(columnUniqueName);
     var oldClass = eventArgs.get_gridColumn().get_element().className;
     eventArgs.get_gridColumn().get_element().className = oldClass + " doubleClickedColumnHeader";
}
CSS
<style>
 .doubleClickedColumnHeader
 {
    background-color: Red !important;
    background-image: none !important;
 }
</style>

On OnColumnClick you could revert the background color of the header:
JavaScript
function OnColumnClick(sender, eventArgs)
{
    eventArgs.get_gridColumn().get_element().className = eventArgs.get_gridColumn().get_element().className.replace(" doubleClickedColumnHeader", "");
}

Also you could fire grid's command from client and on server in RadGrid1_ItemCommand you could hide the column by its unique name:
JavaScript
$find("<%= RadGrid1.ClientID %>").get_masterTableView().fireCommand("customCommand",columnUniqueName);

ASPX.CS
void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "customCommand")
        {
            foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
            {
                if (column.UniqueName.ToString() == e.CommandArgument.ToString())
                {
                    column.Visible = false;
                }
            }
        }
    }

Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

Regards,
Radoslav
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Kaushal
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or