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

Setting grid caption client-side

6 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 16 May 2012, 09:53 PM
I know a grid's "caption" property can be set server-side by,

grid.MasterTableView.Caption = "my caption";

But is it also possible to set this client-side via javascript?  I tried the following but no luck,

masterTableView = grid.get_masterTableView();
masterTableView.Caption = "my caption";

Thanks in advance.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 May 2012, 06:27 AM
Hello David,

Try the following javascript to set caption from client side.
JS:
function pageLoad()
{
  var grid = $find("<%=RadGrid1.ClientID %>");
  grid.get_masterTableView().get_element().caption.innerHTML = "your text";
}

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 17 May 2012, 05:12 PM
Thanks Shinu.  I added your code but now I'm getting the following javascript error,

    Microsoft JScript runtime error: 'viewGrid.get_masterTableView().get_element().caption' is null or not an object

I initially set the grid's caption property server-side when loading the data (the caption displays the # of rows added to the grid),

    ViewGrid.MasterTableView.Caption = caption;

Everything up to that point works fine...the caption I set server-side appears in the grid on postback.  But what I want to do is clear that caption client-side whenever the user starts entering something in a particular textbox.  I just don't understand why "get_element().caption" would be null when I can clearly see the caption being displayed??
0
Shinu
Top achievements
Rank 2
answered on 18 May 2012, 05:47 AM
Hello David,

Unfortunately I couldn't replicate the issue. I was able to clear the caption that is set from server side using the following code.
C#:
RadGrid1.MasterTableView.Caption = "text";
JS:
var grid = $find("<%=RadGrid1.ClientID %>");
grid.get_masterTableView().get_element().caption.innerHTML = "";
Hope this helps.

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 18 May 2012, 10:37 PM
Thanks again Shinu.  I finally got it working, but only if I use "get_masterTableViewHeader", as in,

    viewGrid.get_masterTableViewHeader().get_element().caption.innerHTML = "my caption";

Using "get_masterTableView().get_element().caption" returns a null for some reason??

0
Hus Damen
Top achievements
Rank 1
answered on 24 May 2012, 07:35 AM
Hi,

Are you using static headers? As far as I remember grid have different rendering when static headers are on:

http://www.telerik.com/help/aspnet-ajax/grid-appearance-creating-new-skins.html

Thanks
Hus
0
David
Top achievements
Rank 1
answered on 24 May 2012, 05:27 PM
Thanks Hus...that's the problem...I'm using StaticHeaders.  If I set it to "false", the caption appears in "get_masterTableView()".
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Hus Damen
Top achievements
Rank 1
Share this question
or