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

getting column header text client side

5 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Murray
Top achievements
Rank 1
Murray asked on 21 Jan 2010, 03:35 PM
I have a function that is called on Column context menu:
function ColumnContextMenu(sender, eventArgs)
{
    var e = eventArgs.get_domEvent();
    var gridCol = eventArgs.get_gridColumn();
    var gridColElm = gridCol.get_element();
    var colIndex = gridColElm.cellIndex;
    var colName = gridCol.get_uniqueName();

    // get col header text
    var colhdrTxt;

    // firefox colhdrTxt = gridColElm.textContent
    // ie colhdrTxt = gridColElm.innerText
    if(gridColElm.textContent)
        colhdrTxt = gridColElm.textContent;
    else
        colhdrTxt = gridColElm.innerText;    
    ...
}
I don't like using browser dependent code. Do you have an existing function/property to get column header text?


5 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 Jan 2010, 12:40 PM
Hello Murray,

You could use innerHTML instead of textContent or innerText. innerHTML is a valid property for all browsers.
So your code snippet could be changed like that:
function ColumnContextMenu(sender, eventArgs)
{
    var e = eventArgs.get_domEvent();
    var gridCol = eventArgs.get_gridColumn();
    var gridColElm = gridCol.get_element();
    var colIndex = gridColElm.cellIndex;
    var colName = gridCol.get_uniqueName();
 
    // get col header text
    var colhdrTxt = gridColElm.innerHTML;
}

I hope this helps.

Kind regards,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Edward Wallander
Top achievements
Rank 1
answered on 04 Sep 2012, 06:55 AM
Is it possible to change the HeaderText and HeaderTooltip of the GridTemplateColumn in client side? The data has been bound to grid using web methods at client side only.
0
Radoslav
Telerik team
answered on 04 Sep 2012, 08:25 AM
Hi Edward,

You could achieve the desired functionality by using the following code snippet:
// Change header text and tooltip message
var column = tableView.getColumnByUniqueName("ColumnUniqueName");
column.get_element().childNodes[0].innerHTML = "Changed Last Name";
column.get_element().childNodes[0].title = "Changed title";
Additionally I am sending you a simple example which demonstrates the described approach. I hope this helps.

Regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Stalin
Top achievements
Rank 1
answered on 04 Sep 2012, 09:06 AM
Thanks very much. It works fine for HeadText change. But tool tip is not working as how it works for other template columns which has the static tool tip sets using HeaderTooltip. Please check my screenshot.
0
Radoslav
Telerik team
answered on 06 Sep 2012, 07:16 AM
Hello Stalin,

Based on the provided information it is hard to say why the tooltip is not changed. Could you please post your aspx markup with the related code behind file? Thus we will be able to get more information about your scenario and provide you more to the point answer. Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Murray
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Edward Wallander
Top achievements
Rank 1
Stalin
Top achievements
Rank 1
Share this question
or