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

[Solved] Grouping and Context menu

1 Answer 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt Place
Top achievements
Rank 1
Matt Place asked on 16 Jul 2009, 04:00 PM
I have a grid with grouping enabled and also integrates a context menu to access editing and deleting of items.  However, when the records are grouped, the index being returned is incorrect as it takes into account the grouping header rows.  After a lot of research, I notice that all the examples in the forums use a different javascript method for the context menu than what is given in the Q1 2009 ASP.NET AJAX examples.  The biggest difference is that the row index is retrieved using eventargs.get_itemIndexHierarchial();  So, I tried to implement this method to no avail.  When implemented, that line of code actually errors and kicks the user out of the method.

Function RowContextMenu(sender, e)    
      var index = e.get_itemIndexHierarchical(); 
      document.getElementById("hdnGridClickedRowIndex").value = index; 
                                 
      var menu = <%= rmuContextMenu.ClientID %>;                   
                 
      menu.Show(e);    
                    
      e.cancelBubble = true;    
      e.returnValue = false;    
   
      if (e.stopPropagation)    
      {    
            e.stopPropagation();    
            e.preventDefault();    
      }    
      this.SelectRow(this.Rows[index].Control, true);    

I'm getting a bit frustrated by this and would love anyone's help.

Thanks

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 22 Jul 2009, 08:50 AM
Hello Matt,

Inside the OnRowContextMenu client event (or other row-related client events of the control) you can get direct reference to the respective GridDataItem client object in the following manner:

function RowContextMenu(sender, eventArgs)
{
  var row = eventArgs.get_gridDataItem();
}


Thus you can ensure that you will reference valid data item and extract its id for example to pass it on the server and identify the right-clicked record to process some operation.

Note that the get_gridDataItem() object will be initialized if you wire the OnRowCreated client event of the grid (with an empty handler for example). This is done due to performance reasons (to create client objects of grid items only when necessary).

Another method would be to set ClientDataKeyNames for the master table in order to extract the key values on the client at a later stage (as shown on this online demo). Then inside the OnRowContextMenu client event you can get reference to the right-clicked grid item using:

eventArgs.getDataKeyValue("<MyIdFieldName>")

where <MyIdFieldName> is the name of the key field you specified through the ClientDataKeyNames array.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Matt Place
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or