Cell Locking, JavaScript Programming Example of Cell Locking in SpreadSheet

JavaScript Programming Example of Cell Locking in SpreadSheet

Check out our programming example of how you can enable cell locking in SpreadSheet. Feel free to download this piece of code and apply it to your app.

JS Code

webix.ready(function(){

  function lock(){
    var ids = $$("ssheet").getSelectedId(true);
    if(!ids.length)
      $$("ssheet").alert({text: "A cell is not selected"});
    else{
      var state = $$("ssheet").isCellLocked(ids[0].row, ids[0].column);
      if(ids.length == 1) //lock a single cell
        $$("ssheet").lockCell(ids[0].row, ids[0].column, !state);
      else  //lock cell range
        $$("ssheet").lockCell(ids[0], ids[ids.length-1], !state);
    }
  }

  webix.ui({
    cols:[
      {
        width:200, padding:5, 
        rows:[
          { view:"button", label: "Lock / unlock cell",  click: lock},
          {}
        ]
      },
      {
        view:"spreadsheet",
        id:"ssheet",
        toolbar: "full",
        data:{
          data:[
            [3,2,"Webix"],
            [3,3,"SpreadSheet"]
          ]
        }
      }
    ]

  });
});

Would you like to be able to enable cell locking in your spreadsheet?