Prevent edit fields in a row (Treegrid)

Hello syncfusion workers.  First of all, I want tho thank you for your support. 
Your team help me many times and I can continue with the work.

And now, I have a new question:

I have a TreeGrid  loaded without the hierachy (like a normal Grid) and functions very well. But, I need when the row pass to edit mode, some fields can not be edited by the user.

In the Treegrid, I use an option called "AllowEditing" with the value false in a field that the user never fill, while the rest are in edit form.

In summary: I want to disable certain fields in edit mode, but when a user adds a new row that fields can fill. (editmode is RowEditing).

Can you help me? Please, I try the solution in various links and they didn´t help me. 

Thank you so much, have a nice day.

Sincerely Cesar.

3 Replies

JR John Rajaram Syncfusion Team October 5, 2018 10:33 AM UTC

Hi Cesar, 
Thank you for contacting Syncfusion support. 
In TreeGrid when we set the AllowEditing value as “false” to any columns, it cannot be updated either through “Add” or “Edit” actions. This is the default behavior of the TreeGrid control. 
But as per your requirement, when adding the new record to TreeGrid control, we can allow the editing for disabled field columns by using ActionBegin, ActionComplete client side events with some work around. Please refer the below code snippet 
<ej:TreeGrid runat="server" ID="TreeGridSelfReference" ActionBegin="actionBegin" IdMapping="Id" ActionComplete="actionComplete" > 
       <Columns> 
               <ej:TreeGridColumn HeaderText="Task Id" Field="Id" Width="60" EditType="Numeric"  /> 
                <ej:TreeGridColumn HeaderText="Task Name" Field="Name" EditType="String" AllowEditing="false"/> 
                <ej:TreeGridColumn HeaderText="Start Date" Field="StartDate" EditType="Datepicker" /> 
                <ej:TreeGridColumn HeaderText="Duration" Field="Duration" EditType="Numeric" /> 
                <ej:TreeGridColumn HeaderText="Progress" Field="PercentDone" EditType="Numeric" AllowEditing="false" /> 
         </Columns>             
</ej:TreeGrid> 
 
  <script> 
            function actionComplete(args) { 
             if (args.requestType == "addNewRow") { 
                    args.model.columns[1].allowEditing = false; 
                    args.model.columns[4].allowEditing = false; 
                } 
            } 
            function actionBegin(args) { 
                if (args.requestType = "add") { 
                    args.model.columns[1].allowEditing = true; 
                    args.model.columns[4].allowEditing = true; 
                } 
            } 
           
        </script> 
We have prepared the sample for your reference, please find the sample link below 
Please let us know if you require further assistance on this. 
Regards, 
John R 



CA César Alejandro Guerrero Nava October 5, 2018 04:19 PM UTC

It works. Thank you so much.



JR John Rajaram Syncfusion Team October 8, 2018 05:00 AM UTC

Hi Cesar, 
Thank you for the update. Please let us know if you need any other assistance. 
Regards, 
John R 


Loader.
Up arrow icon