Dynamically Attach Client Event

5 posts, 1 answers
  1. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 07 Jun 2011 Link to this post

    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.
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 09 Jun 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 09 Jun 2011 Link to this post

    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.
  5. Answer
    Mira
    Admin
    Mira avatar
    1124 posts

    Posted 13 Jun 2011 Link to this post

    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.

  6. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 13 Jun 2011 Link to this post

    Many thanks for the detailed response.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017