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

Dynamically Attach Client Event

4 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LeBear
Top achievements
Rank 1
LeBear asked on 07 Jun 2011, 10:57 PM
Hello,

I'm looking to create a JavaScript object that will accept as an argument a RadGrid.  From within the JavaScript object, I want to attach a function within the JavaScript object to an event within the RadGrid.  Specifically, I want to attach a function to the OnRowContextMenu.

To demonstrate this conceptually...

MyController = function (KeyID_ast, Grid_aob, ContextMenu_aob) {
 
    var _KeyVal_ain;
 
    Grid_aob.ClientSettings.ClientEvents.OnRowContextMenu = function (sender, args) {
        args.get_tableView().selectItem($get(args.get_id()));
        ContextMenu_aob.show(args.get_domEvent());
        _KeyVal_ain = args.getDataKeyValue(KeyID_ast);
    }
 
}
.
The "Grid_aob.ClientSettings.ClientEvents.OnRowContextMenu" assignment is a guess at what I could potentially do, but when I review the RadGrid documentation, there is no such capability.

As a comparison, I was looking at the RadMenu and RadContextMenu methods to add an event handler (e.g., menu.add_itemClicked(myItemClickedHandler)), but there is no reference in the documentation to a similar capability for the RadGrid.

Of course, I would try this, but I'm a fair bit off from getting to that point in my system, and I'd appreciate a sanity check before moving on.

Thank you for your assistance.

4 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 09 Jun 2011, 01:01 PM
Hello LeBear,

The desired functionality can be implemented with the RadGrid in the same way as with the RadMenu:
grid.add_rowContextMenu(onRowContextMenu);          
 
function onRowContextMenu(sender, args) {
   //...
}

I hope this helps.

Kind regards,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
LeBear
Top achievements
Rank 1
answered on 09 Jun 2011, 01:33 PM
That's excellent.  Thank you.

I couldn't find that in the documentation.  Did I miss it, and can you point me to it?  If it's not there, can you post a list of the methods for adding each of the events?

Thank you.
0
Accepted
Mira
Telerik team
answered on 13 Jun 2011, 09:56 AM
Hello LeBear,

You can attach handlers dynamically with the following code:
grid.add_eventName(eventHandler);         
 
function eventHandler(sender, args) {
   //...
}
Here eventName is formed from the names in the table in this help topic by removing On and starting with a small letter.
Please note that the grid and its structure should be created when the event handlers are attached. That is why you cannot attach handlers for the OnXXXCreating and OnXXXCreated events dynamically.

I have notified our help team that this information is missing in the online help and they will add it.

I hope this helps.

Best wishes,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
LeBear
Top achievements
Rank 1
answered on 13 Jun 2011, 12:10 PM
Many thanks for the detailed response.
Tags
Grid
Asked by
LeBear
Top achievements
Rank 1
Answers by
Mira
Telerik team
LeBear
Top achievements
Rank 1
Share this question
or