Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
600
Editable grid with certain rows not editable based on value in cell
posted

Hi,

I have an editable grid, however, depending on a hidden field value I would like particular rows not to be editable. 

Please see the attached sample.

If the value in the Exempt field = "yes" I would like this particular row not to be editable (not to respond to mouse clicks).

Also, as the grid is loading, if the value in the Exempt field is true, instead of displaying a numeric value in the score column I instead would like to display the string "Exempt".

In summary, if the value in the (hidden) Exempt field = "yes", display the word "Exempt" instead of a numeric score and prevent the row from being edited.

And one more wrinkle...

There is an "Apply Defaults to All" button at the top that updates all the rows with default values.  I similarly need the "exempt" rows not to be editable by this action.

Many Thanks.

UneditableRows.zip
Parents
No Data
Reply
  • 15320
    Offline posted

    Hello Rick,

    In order to make the rows that contain "Yes" value read-only, you may handle editRowStarting event and cancel it, for instance:

    editRowStarting: function(evt,ui){
        var rowId=ui.rowID;
        var exemptColVal=$("#grid").igGrid("getCellValue", rowId, "exempt");
        if(exemptColVal=="Yes")
         evt.preventDefault(); 
        }

    For changing the value in "Scope" column based on the value in "Exempt" column you may use rowsRendered event (if you want it to be changed initially):

      rowsRendered: function(evt, ui) {
      for(var i = 0; i < ui.owner.rows().length; i++){
       var record = $("#grid").data("igGrid").options.dataSource[i];
       if(record.exempt=="Yes"){
        var rowId = $(ui.owner.rowAt(i)).attr("data-id");
        $("#grid").igGridUpdating("setCellValue", parseInt(rowId,10), "score", "Exempt");
       }
      }
      }

    Regarding your last requirement, I believe that my first suggestion resolves it.

    I'm attaching a sample for your reference.

    If you need further assistance, please let me know.

    Regards,

    Tsanna

    UneditableRows.zip
Children