2016-11-03 15 views
1

私はhandsontableに以下のデータを持ちます。レンダリング後のJQuery handsontableは、他のセルの値に対してセルを読み込みません。

var data = [ 
    ["2008", 10, 11, 12, 1], 
    ["2009", 20, 11, 14, 0], 
    ["2010", 30, 15, 12, 1] 
    ]; 

リンク:FIDDLE

私は値が0の場合は最後の列に想定必要なもの、私は、行の二番目と3番目の列を含む対応する列を必要と読み取り専用にします。

詳細については、以下の画像の点に注意してください。

enter image description here

Handontableレンダラの方法は、使用するために必要なものです。私が使用していることは、次のとおりです。

Handsontable.hooks.add('afterRender', function() { 
var a = $('.htCore').find('tbody tr td:nth-child(2)'); 
var b = $('.htCore').find('tbody tr td:nth-child(3)'); 
var g = $('.htCore').find('tbody tr td:nth-child(4)'); 

g.each(function (i, v) { 
if (parseFloat(g.eq(i).text()) == 0)) { 
    a.eq(i).attr('readonly',true); 
    b.eq(i).attr('readonly',true); 
}); 

しかし、私を導いてください動作していない....

+0

@ZekeDroidバディを助けてください – Santhucool

答えて

1

あなたがreadonly属性を更新するためにjQueryのを使用する必要はありません。

あなたは私の例のように、セルのプロパティを作成する必要があります。

http://jsfiddle.net/vgaybtvp/

cells: function (row, col, prop) { 
    var cellProperties = {}; 
    var hot = this.instance; 

    if((col == 2 || col == 3) && hot.getDataAtCell(row, hot.colToProp(4)) == 0) { 
     cellProperties.readOnly = true; 
    } else { 
     cellProperties.readOnly = false; 
    } 

    return cellProperties; 
} 

よろしくあなたが使用することができますどのような

+0

ありがとうございました。それは良いハックです! – Santhucool

1

は、プロパティはすでにHandsontableに含ま読み込まれます。 テーブルが初期化されるときに、私が呼び出す機能の下を参照してください、と変更後:

function updateTableReadOnly() { 
    var cellPropertiesID; 
    for (var i = 0; i < $("#example1grid").handsontable('getData').length; i++) { 
    if ($("#example1grid").handsontable('getData')[i][4] === '0') { 
     updateCellReadOnly(i,2,true) 
     updateCellReadOnly(i,3,true) 
    } else { 
     updateCellReadOnly(i,2,false) 
     updateCellReadOnly(i,3,false) 
    } 
    } 
    $("#example1grid").handsontable('render'); 
} 

function updateCellReadOnly(i,j,value) { 
    cellPropertiesID = $("#example1grid").handsontable('getCellMeta',i,j); 
    cellPropertiesID.readOnly = value; 
} 

私の働い例えばyour fiddle updatedを参照してください。

文字列の値で状態を確認するようにデータを変更しました。

var data = [ 
    ["2008", "10", "11", "12", "1"], 
    ["2009", "20", "11", "14", "0"], 
    ["2010", "30", "15", "12", "1"] 
], 

理由は、テーブル内のデータを直接変更する必要がある場合、あなたが入ります新しい値が文字列になりますです。このように列日産トヨタは、値ホンダに応じてプロパティを動的に変更します。あなたがここで達成したかったと思います。

関連する問題