6

ハンズオンテーブルに列を動的に追加しようとしています。サンプルはどこにも見当たりませんし、APIでそうするためのメソッドも見当たりません。誰かがこれを克服する方法を考え出したか、私が見ることができるいくつかのサンプルコードが役立つでしょう。

ありがとうございました。

4

5 に答える 5

10

handsontable('alter', 'insert_col', index, amount)使用方法は試しましたか?alterメソッドを使用して、列と行を追加および削除できます。handontable プロジェクトのドキュメント ページを参照してください。

于 2013-04-28T23:49:05.177 に答える
3

一時的な解決策は、データ テーブルを動的に維持することです。新しい列が必要な場合は、データ構造を更新し、テーブル全体を再開します。次のスニペットが役に立つかもしれません。

(function($) {
$(function() {
    var data = [['a', 'b', 'c', 'd'], [1, 1, 1, 1], [2, 2, 2, 2]];
    $('#a-div').handsontable({data: data});

    /* add a new column */
    data[0].push('e');
    var len = data.length;
    for (var i = 1; i < len; i++) {
        data[i].push(i);
    }
    $('#a-div').handsontable({data: data});

    /* if new column isn't at the tail */
    data[0].splice(idx, 0, "f");
});})(jQuery);
于 2013-03-24T14:43:38.977 に答える
0

列設定を定義すると、これを修正するために列ランタイムが追加されません。Handsontable の動的列を作成する方法のリンクを参照してください。

于 2013-07-23T10:16:08.567 に答える
0

alter関数を使用する必要があります

2x3 のテーブルがあり、5x5 にしたいとします。

curRows = myTable.countRows() //curRows = 2
curCols = myTable.countCols() //curCols = 3
var newRows = 5
var newCols = 5

if(newRows > curRows){
   myTable.alter('insert_row',curRows ,newRows - curRows); 
}
else if (newRows < curRows){
    myTable.alter('remove_row', curRows,curRows - newRows );
}
if(newCols > curCols){
    myTable.alter('insert_col',curCols, newCols - curCols); 
}
else if (newCols < curCols){
    myTable.alter('remove_col',curCols, curCols - newCols);
}
于 2016-10-05T20:56:33.937 に答える