We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Make certain cells in a grid row read only based on the value of a cell in the row

I'm trying make certain cells in a grid row read only(non editable) based on the value of a cell in that row.  I'm using the following script and it seems to set the property to true but it still allows me to edit those cells.

function RowDataBound(args)
{
    var IsHostRep = args.data["IsHost"];
    var currentrow = args.model.currentIndex;
    if (args.data.IsHost == 1)
    {
        args.row[currentrow].cells[1].disabled = true;
    }
}

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team October 3, 2016 12:14 PM UTC

Hi Jason, 
  
Thanks for contacting Syncfusion support. 
  
To make a cell non-editable based on its value, use actionComplete event of ejGrid. The actionComplete event triggered for every grid action success event. In actionComplete event, we check the condition with the requestType and disable the EmployeeID cell by adding disabled attribute and disable class when it has a value of 5. 
  
Find the code example and sample: 
  
  
@(Html.EJ().Grid<object>("FlatGrid") 
       .Datasource((IEnumerable<object>)ViewBag.datasource) 
       .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
       .AllowPaging() 
       .ToolbarSettings(toolbar => 
         { 
           toolbar.ShowToolbar().ToolbarItems(items => 
             { 
               items.AddTool(ToolBarItems.Add); 
               items.AddTool(ToolBarItems.Edit); 
               items.AddTool(ToolBarItems.Delete); 
               items.AddTool(ToolBarItems.Update); 
               items.AddTool(ToolBarItems.Cancel); 
             }); 
         }) 
       .Columns(col => 
        { 
          --------------------------- 
        }) 
       .ClientSideEvents(eve => { eve.BeginEdit("beginEdit"); }) 
    ) 
  
<script> 
    function beginEdit(args) { 
if(args.requestType == "beginedit") { 
        var data = args.row.find("input"); 
        for (var i = 0 ; i < data.length ; i++) { 
            if (data[i].name == "EmployeeID" && parseInt($(data[i]).attr("value")) == 5) { 
                $(data[i]).addClass("e-disable").attr("disabled","disabled"); 
            } 
        } 
      }    } 
</script> 
  
  
  
Refer to the Help document for the actionComplete event. 
  
  
Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Live Chat Icon For mobile
Up arrow icon