Search code examples
javascriptjqueryjquery-pluginshandsontable

Sets cell to be readonly


I am using jquery-handsontable to create a data-grid.

If I make

$("#example1grid").handsontable('setDataAtCell', 0, 0,"test")
$("#example1grid").handsontable("setCellReadOnly", 0, 0);

It changes the text but then when I click I can edit it. Why?

Here is the test http://jsfiddle.net/z9fYC/59/.
Anyway what about if I want to make all the column number 0 read-only? ​


Solution

  • It does look like a bug. According to the documentation, what you did should work.

    Anyways, to workaround, you can define the readonly behavior in a cell by cell basis, like this:

    $("#example1grid").handsontable({
        rows: 5,
        cols: 6,
        minSpareCols: 1,
        //always keep at least 1 spare row at the right
        minSpareRows: 1,
        //always keep at least 1 spare row at the bottom
        contextMenu: true,
        cells: function(r,c, prop) {
            var cellProperties = {};
            if (r===0 && c===0) cellProperties.readOnly = true;
            return cellProperties;        
        }
    });