Setting row as readonly depending on a column value

Posted by: tedin_uriburu on 24 October 2019, 7:21 pm EST

  • Posted 24 October 2019, 7:21 pm EST

    Hi,

    is there a way to set the isReadOnly property for each row depending on a value on the row itself? I have a field indicating if the row should be read only or not. I can add an event handler for StartEditing, but I want to know if there is a way to manage this when the datasource is set and every row gets data., like an event “onRowGetFilled”.

    Thanks,

  • Posted 25 October 2019, 5:11 am EST

    Hi,

    We are sorry but there is no direct method/property available to directly bind the dataSource. We would recommend use to use protection options, first set the isProtected option to false and the then unlock the editable rows, please refer to the following code snippet:

    sheet.suspendPaint();
        sheet.options.isProtected = true;
        for(var i = 0; i < sheet.getRowCount(); i++){
          let item = sheet.getDataItem(i);
          // unlock editable rows
          if(item.isEditable){
            sheet.getRange(i, -1, 1, -1).locked(false);
          }
        }
        sheet.resumePaint();
    

    Regards

    Sharad

  • Posted 25 October 2019, 2:05 pm EST

    Hi,

    I tried just this to lock the entire sheet but it doesn’t work:

    sheet.options.isProtected = true;

    any idea what I am missing?

    Also, I have this code and even so it allows me to edit a cell:

    var protectOption = {

    allowFilter: true,

    allowSort: true,

    allowResizeRows: false,

    allowResizeColumns: true,

    allowEditObjects: false

    };

    sheet.options.protectionOptions = protectOption;

    sheet.options.isProtected = true;

    what is wrong here?

  • Posted 28 October 2019, 3:19 am EST

    Everything in the code snippet seems fine, We created a sample based on the code snippet and everything seems to be working fine as expected, please have a look at the following sample and let us know if anything is missing from the sample to replicate the issue: https://codesandbox.io/s/spread-js-starter-h9ei1

    If the issue persists please share a small sample replicating the issue so that we could further investigate it.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels