ハンズオンテーブルに列を動的に追加しようとしています。サンプルはどこにも見当たりませんし、APIでそうするためのメソッドも見当たりません。誰かがこれを克服する方法を考え出したか、私が見ることができるいくつかのサンプルコードが役立つでしょう。
ありがとうございました。
ハンズオンテーブルに列を動的に追加しようとしています。サンプルはどこにも見当たりませんし、APIでそうするためのメソッドも見当たりません。誰かがこれを克服する方法を考え出したか、私が見ることができるいくつかのサンプルコードが役立つでしょう。
ありがとうございました。
handsontable('alter', 'insert_col', index, amount)
使用方法は試しましたか?alter
メソッドを使用して、列と行を追加および削除できます。handontable プロジェクトのドキュメント ページを参照してください。
一時的な解決策は、データ テーブルを動的に維持することです。新しい列が必要な場合は、データ構造を更新し、テーブル全体を再開します。次のスニペットが役に立つかもしれません。
(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);
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);
}