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

Getting at the GridCommandItem via the client-side API

4 Answers 262 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 12 Mar 2012, 01:00 PM
Normally, if I need a client-side reference to the grid's CommandItem, I wire up the Toolbar's OnClientLoad command and save the reference when that fires. Either that or use $find(...).

However, I find myself updating a page that used multiple instances of a user control that has a grid in it and i need to access the CommandItem for a grid when a row on the grid is selected, but for the life of me I can't find anything in the API that allows me to get at the CommandItem from, say, the OnRowSelecting event.

Is this possible?

--
Stuart

4 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 14 Mar 2012, 04:17 PM
Stuart:

I'm not sure I totally understand your requirement, but the code provided in this CodeLibrary may provide some assistance:

Client-side calculations (reflected in RadGrid's command item) for selected rows

"The example illustrates how to update a label residing in the command item template of RadGrid purely client-side to reflect the cumulative unit price from the selected records in the table. For this purpose we intercept the OnRowSelected and OnRowDeselected events of the control to increment/decrement the current sum..."

Hope it helps!
0
Stuart Hemming
Top achievements
Rank 2
answered on 15 Mar 2012, 01:55 AM
Jumpstart,

Thanks for looking at this, sadly, I don't think that's going to help me.

I'll try explaining the situation a bit better.

I have a UserControl. The UserControl contains a RadGrid and the RadGrid has a CommandItem Template that includes a RadToolBar.

I need to access one or more of the buttons in the RadToolBar when the user clicks on a row in the grid.

Normally, this wouldn't be an issue. I would wire up the OnClientLoad event of the RadToolBar and, when it fires, store a reference to it where I can access it in Javascript later on...

function OnGridRowSelecting(sender, e)
{
  //gridCommandItem is a variable that I populate during the
  // RadToolBar's OnClientLoad event
  var buttons = gridCommandItem.get_items();
  // ...
}

in this specific case, however, I have multiple instances of my UserControl on the page, so, ideally, what I'd like to do is something like this...
function OnGridRowSelecting(sender, e)
{
  var commandItem = sender.get_someCleverMethodThatAllowsMeToAccessTheComamndItem()
  var toolbar = $telerik.findControl(commandItem, "RadToolBar1");
  var buttons = toolbar.get_items();
  // ...
}

Does that make any clearer what it is I'm trying to do?

0
Accepted
Martin
Telerik team
answered on 19 Mar 2012, 09:59 AM
Hello Stuart,

The approach you have followed (using the Telerik static client library) is correct. Unfortunately, RadGrid's client side object does not provide API for the command item template. When rendered on the page this item is just a table row element that has "rgCommandRow" class attribute. You can use jQuery for example to find this element on the page. My suggestion however, is to pass the master table view element to the findControl method instead:

function OnGridRowSelecting(sender, e)
{
  //var commandItem = sender.get_someCleverMethodThatAllowsMeToAccessTheComamndItem()
  var toolbar = $telerik.findControl(sender.get_masterTableView().get_element(), "RadToolBar1");
  var buttons = toolbar.get_items();
  // ...
}

I hope this helps.

Greetings,
Martin
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
Stuart Hemming
Top achievements
Rank 2
answered on 19 Mar 2012, 10:09 AM
Nice one.

Thanks martin.

--
Stuart
Tags
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 1
Stuart Hemming
Top achievements
Rank 2
Martin
Telerik team
Share this question
or