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

Radgrid- Custom selection of ROws/ Disabling selection of rows /client side implementation

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dinesh
Top achievements
Rank 1
Dinesh asked on 11 Sep 2013, 06:57 AM
Hello,
We are trying Radgrid for our project requirements we have a specific requirement to disable selection of certain rows based on "True/False" values returned from a column in database. We want to have functionality to disable those rows for which a specific column is returning "False" and we want to enable this feature with hierarchy .
We tried going for Template field, GridSelectColumn and tried using "Selectable.Mode to None" but we were not able to achieve the results and we need a client side solution /using some inbuilt property for our problem as our grid would hold around 1 million records so handling such scenario on server side/codebehind is the scenario we want to avoid.
Kindly reply to suggest some ways /features we can achieve our requirement. We have enquired for professional license so we will be getting professional license this week , so please help us on achieving this requirement.


Thanks& Regards,
-Dinesh Kotwani

 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Sep 2013, 11:16 AM
Hello,

Please try with the below code snippet.

<script type="text/javascript">
          
            function RowSelecting(sender, args) {
                var UsingKey = args.getDataKeyValue("IsAllowSelect"); // ClientDataKey
                var UsingColumn = args.get_gridDataItem().get_cell("IsAllowSelect").innerHTML; // Column UniqueName
 
                if (UsingKey == 'False') {
                    args.set_cancel(true);
                }
 
                //or
                if (UsingColumn == 'False') {
                    args.set_cancel(true);
                }
            }
        </script>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
       <MasterTableView CommandItemDisplay="Top" ClientDataKeyNames="IsAllowSelect">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="IsAllowSelect" UniqueName="IsAllowSelect" HeaderText="IsAllowSelect">
               </telerik:GridBoundColumn>
               <telerik:GridEditCommandColumn>
               </telerik:GridEditCommandColumn>
           </Columns>
       </MasterTableView>
       <ClientSettings>
           <Selecting AllowRowSelect="true" />
           <ClientEvents OnRowSelecting="RowSelecting" />
       </ClientSettings>
   </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data1 = new[] {
              new { ID = 1, Name ="Name_1",IsAllowSelect = true},
              new { ID = 2, Name = "Name_2",IsAllowSelect = false},
              new { ID = 3, Name = "Name_3",IsAllowSelect = false},
              new { ID = 4, Name = "Name_4",IsAllowSelect = true},
              new { ID = 5, Name = "Name_5",IsAllowSelect = true}
          };
 
       RadGrid1.DataSource = data1;
   }

Note : In this demo if IsAllowSelect is true then and only then user is able to select the row.

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Dinesh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or