How to stop the first column to be editable

Hi,

My Grid is auto generated so the code looks like this


How can I stop column 1 from getting edited. I tried in the createEvent function

args.model.columns[0]['AllowEditing'] = false;
gridObj.columns(args.model.columns);

but this doesn't work ?




3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 26, 2018 05:24 AM UTC

Hi David, 

Thanks for contacting Syncfusion support. 

As per your given detail we suspect that you want to disable the editing for the first column in Grid when we are in auto generation for column. We can achieve your requirement by using the dataBound event of ejGrid control.  

Refer the below code example. 


<ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" AllowPaging="True" IsResponsive="true"> 
            <EditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></EditSettings> 
           <ToolbarSettings ShowToolbar="true" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> 
             
            <ClientSideEvents DataBound="onGridDataBoundEvent" /> 
             
        </ej:Grid> 
    </div> 
      
    <script type="text/javascript"> 
        function onGridDataBoundEvent(args) { 
 
            this.model.columns[1].allowEditing = false; 
            this.refreshContent(true); //Reflect the changes in grid 
 
        } 
    </script> 


Note: The editing operation works based on the PrimaryKey column value. So the values for the Primary Key column should be unique. Also we suspect that you have not enable isPrimaryKey for unique value column then we suggest you to set isPrimaryKey for the unique value column in Grid. If the PrimaryKey column and need to set allowEditing as false columns are same then we need to enable only isPrimaryKey for that column. By default when a record is editable state then the PrimaryKey column is disabled so we suggest you to remove the allowEditing as false for the primary key column. 

Refer the help documentation. 




Refer the knowledge base documentation. 



Regards, 
Thavasianand S. 



DP David Price October 26, 2018 01:35 PM UTC

How can I disable rows from being editable also ?

for example I don't want row 3 & 4 to be editable .




VN Vignesh Natarajan Syncfusion Team October 29, 2018 08:45 AM UTC

Hi David, 
 
 
Query: “How can I disable rows from being editable also ?” 
 
 
From your query, we understand that you want to certain row from editing. We have achieved your requirement using BeginEdit event of ejGrid. 
 
Refer the below code example 
 
 
<ej:Grid ID="FlatGrid" runat="server" AllowScrolling="True" AllowSorting="True" AllowPaging="True" IsResponsive="true">  
            <EditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></EditSettings>  
           <ToolbarSettings ShowToolbar="true" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>              
            <ClientSideEvents DataBound="onGridDataBoundEvent" BeginEdit="beginedit"/>     
           <ScrollSettings FrozenColumns="2" />          
        </ej:Grid>  
          <script type="text/javascript">  
              function onGridDataBoundEvent(args) { 
                  this.model.columns[0].isPrimaryKey = true; 
            this.model.columns[1].allowEditing = false;  
            this.refreshContent(true); //Reflect the changes in grid   
        } 
              function beginedit(args){ 
                  if (args.rowIndex == 3 || args.rowIndex == 4) 
                      args.cancel = true; 
} 
    </script> 
 
For your convenience we have prepared a sample which can be downloaded from below link 
 
 
 
 
Refer our API documentation for your reference 
 
 
 
 
Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon