How to make a row 'Unselectable'?

6 posts, 1 answers
  1. Brindavan
    Brindavan avatar
    12 posts
    Member since:
    Feb 2009

    Posted 18 Mar 2009 Link to this post

    Hi,

    I have a grid in which I have to restrict the user from selecting few rows based on some column value.
    I am allowing the users to select the rows by clicking on them currently.

    How can I make some rows unselectable on click?


    Brindavan
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Mar 2009 Link to this post

    Hello Brindavan,

    Try the following client side code for preventing row selection based on value. Attach the handler to OnRowSelecting client side event of Radgrid.

    ASPX:
    <ClientSettings> 
        <Selecting AllowRowSelect="True"></Selecting> 
        <ClientEvents OnRowSelecting="RowSelecting" /> 
    </ClientSettings> 

    JavaScript:
    <script type="text/javascript"
    function RowSelecting(sender, eventArgs) 
    {  
       var dataItem = $get(eventArgs.get_id()); 
       var grid = sender; 
       var MasterTable = grid.get_masterTableView(); 
       var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
       var cell = MasterTable.getCellByColumnUniqueName(row, "CategoryID"); 
       if(cell.innerHTML == 5) //Check for the condition, here cell.innerHTML holds the value of the cell 
       { 
            eventArgs.set_cancel(true); // Cancel the event 
            alert ("cannot select this row"); 
       } 
    </script> 

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 26 Jun 2012 Link to this post

    How to make a detail table row unselectable?
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 26 Jun 2012 Link to this post

    Hello,

    function RowSelecting(sender, args) {
                   if (args.get_tableView().get_name() == "Child") {
                       args.set_cancel(true)
                   }
     
               }
    <telerik:RadGrid ID="RadGrid1" runat="server">
               <MasterTableView Name="Parent">
                   <Columns>
                       .....................
                      ................
                   </Columns>
                   <DetailTables>
                       <telerik:GridTableView Name="Child" >
                           <Columns>
                               .............
                              .................
                           </Columns>
                       </telerik:GridTableView>
                   </DetailTables>
               </MasterTableView>
               <ClientSettings>
               <Selecting AllowRowSelect="true" />
                   <ClientEvents OnRowSelecting="RowSelecting" />
               </ClientSettings>
           </telerik:RadGrid>


    Thanks,
    Jayesh Goyani
  6. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 26 Jun 2012 Link to this post

    that doesnt allow me to make a certain detail table row unselectable...

    I have a column in the detail table called "Valid" if that is "False" I do not want that row to be selectable.
  7. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 26 Jun 2012 Link to this post

    Hello,

    By dataKey.
    <DetailTables>
                      <telerik:GridTableView Name="Child" DataKeyNames="ID" ClientDataKeyNames="ID">
                          <Columns>
                            ..................
                            .................
                          </Columns>
                      </telerik:GridTableView>
                  </DetailTables>
    function RowSelecting(sender, args) {
               
                if (args.get_tableView().get_name() == "Child" && args.getDataKeyValue("ID") == "YourcomparedValue") {
                    args.set_cancel(true)
                }
     
            }


    By Column

    function RowSelecting(sender, args) {
                
                 if (args.get_tableView().get_name() == "Child" && args.get_gridDataItem().get_cell("Name1").innerHTML == "YourcomparedValue") {
                     args.set_cancel(true)
                 }
     
             }
    <DetailTables>
                     <telerik:GridTableView Name="Child">
                         <Columns>
                             <telerik:GridBoundColumn HeaderText="Name1" DataField="Name" UniqueName="Name1">
                             </telerik:GridBoundColumn>
                         </Columns>
                     </telerik:GridTableView>
                 </DetailTables>


    Thanks,
    Jayesh Goyani
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017