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

Client-side multi-row select behavior in conjunction with a RadContextMenu

1 Answer 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frank Klassen
Top achievements
Rank 1
Frank Klassen asked on 23 Oct 2008, 03:18 PM

I'm adding a RadContextMenu to a grid with:

  • ClientSettings-AllowRowSelect=true
  • AllowMultiRowSelection=true.

I'm trying to control the behavior of the selected state of the rows in the following way:

  1. If the context menu is activated over a row that was previously selected, then that row and any other selected row should remain selected.
    This works fine.
  2. If the context menu is activated over a row that was not previously selected, then select the row and deselect all others.
    This is the problem I'm having: If I right click on a grid row that is not selected, it selects that row and leaves all others selected. In the client-side context menu script, I'm trying to deselect all rows and then reselect the clicked row. Is this possible? I can't seem to figure out how to identify the row that was "right-clicked".

Thanks!

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 27 Oct 2008, 10:00 AM
Hello Frank Klassen,

The requested functionality can be achieved with few lines of javascript. Inside RowContextMenu event's handler you should check if the current item is selected and if it is not then temporary disable the MultiRowSelection and select the item. Similar to the following:

<script type="text/javascript">  
            function onRowContextMenu(sender, args) {  
                //this will create the dataItems client object  
                args.get_tableView().get_dataItems();  
 
                //check if current item is selected  
                if ($find(args.get_id()) && !$find(args.get_id()).get_selected()) {  
                    //temporary disable the multirowselection  
                    args.get_tableView().get_owner().AllowMultiRowSelection = false;  
                    //select the item  
                    args.get_tableView().selectItem($get(args.get_id()));  
                    //allow the multirowselection  
                    args.get_tableView().get_owner().AllowMultiRowSelection = true;  
                }  
                $find('<%=RadContextMenu1.ClientID %>').show(args.get_domEvent());  
            }  
        </script> 
 
        <asp:ScriptManager runat="server" ID="ScriptManager1">  
        </asp:ScriptManager> 
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowMultiRowSelection="true" OnNeedDataSource="RadGrid1_NeedDataSource">  
            <ClientSettings> 
                <Selecting AllowRowSelect="true" /> 
                <ClientEvents OnRowContextMenu="onRowContextMenu" /> 
            </ClientSettings> 
        </telerik:RadGrid> 
        <telerik:RadContextMenu runat="server" ID="RadContextMenu1">  
            <Items> 
                <telerik:RadMenuItem Text="Item1" /> 
                <telerik:RadMenuItem Text="Item2" /> 
            </Items> 
        </telerik:RadContextMenu> 

Please give it a try and let us know if this helps.
 
Kind regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Frank Klassen
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or