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

De-select a row

4 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Cole
Top achievements
Rank 1
Adam Cole asked on 26 Aug 2008, 04:11 PM
Hi,
  I am using GridClientSelectColumn to let the user select a row in my grid.

AllowMultiRowSelection is set to false, because I don't want user to select multiple rows.

  My question is after a row is selected, is there a way to de-select the row?  I noticed use can uncheck a selected row if AllowMultiRowSelection is set to true, but it doesn't work if AllowMultiRowSelection  is false.  The user should be click on a checked checkbox again to uncheck it.

  I am still check your forum to find a solution and it will be great if you can give me a quick solution.

thanks.

4 Answers, 1 is accepted

Sort by
0
Adam Cole
Top achievements
Rank 1
answered on 26 Aug 2008, 04:19 PM
Ctrl + "mouse click" doesn't unselect the row.
0
Vlad
Telerik team
answered on 27 Aug 2008, 05:35 AM
Hello Adam,

Here is an example how to achieve this:

Here is an example how to use CTRL + click to get this working:

        function rowSelecting(sender, args)
        {
            if (args.get_domEvent().ctrlKey)
            {
                args.set_cancel(true);
            }
        }

where rowSelecting is the event handler for OnRowSelecting client-side event.

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 27 Aug 2008, 10:14 AM
Hi Adam,

You can also try the following code snippet.

ASPX:
<ClientSettings> 
    <ClientEvents OnRowClick="OnRowClick" OnRowSelecting="RowSelecting" OnRowDeselecting="RowDeselecting"  /> 
   <Selecting AllowRowSelect="true"  /> 
 </ClientSettings> 

JS:
<script type="text/javascript" language="javascript" > 
         
         var clickedItemIndex; 
          var deselected;  
          var selected;   
          function OnRowClick(sender, args) 
          { 
                var master = $find('<%= RadGrid1.ClientID %>').get_masterTableView();  
                var index = args.get_itemIndexHierarchical();  
               master.get_dataItems()[index].set_selected(!master.get_dataItems()[index].get_selected());  
             clickedItemIndex = index;  
      
             if(master.get_dataItems()[index].get_selected())  
                selected = true;  
             else  
                selected = false;  
           
                  
          } 
           
          function RowDeselecting(sender, args) //Attach to the OnRowDeselecting client event  
          {  
               if(clickedItemIndex != args.get_itemIndexHierarchical())  
                   args.set_cancel(true);  
              else if(selected)  
                 deselected = false;  
               else  
                deselected = true;  
          }  
  
        function RowSelecting(sender, args)  //Attach to the OnRowSelecting client event  
          {  
             if(clickedItemIndex == args.get_itemIndexHierarchical() && deselected)  
               args.set_cancel(true);  
             else  
           deselected = false;  
          }  
        
     </script> 


Thanks
Princy.
0
Adam Cole
Top achievements
Rank 1
answered on 27 Aug 2008, 02:43 PM
Thank you guys.  After testing all your suggestions, I found my own solution.  Let me share it.

Put this into the grid:
<ClientSettings>
                        <ClientEvents OnRowDeselecting="rowDeselecting1" OnRowSelecting="rowSelecting1" />
                        <Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>

Add this in the <head>
var selectedIndex1;
    var cancelSelect1;
        
    function rowDeselecting1(sender, eventargs)
    {
        var index = eventargs.get_itemIndexHierarchical();
       
        if (selectedIndex1 == index)
            cancelSelect1 = 1;
        else
            cancelSelect1 = 0;
    }

    function rowSelecting1(sender, eventargs)
    {
        if (cancelSelect1 == 1)
        {
            cancelSelect1 = 0;
            args.set_cancel(true);
        }
        var index = eventargs.get_itemIndexHierarchical();
        selectedIndex1 = eventargs.get_itemIndexHierarchical(); 
    }
Tags
Grid
Asked by
Adam Cole
Top achievements
Rank 1
Answers by
Adam Cole
Top achievements
Rank 1
Vlad
Telerik team
Princy
Top achievements
Rank 2
Share this question
or