//标题 var haedgen = ["計上日", "伝票摘要", "貸借区分 *", "勘定科目-補助科目コード *"];
//给个初期值默认值 空,
var data = [["", "", "", ""]];
//背景色
var backRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.backgroundColor = '#ADADAD';
};
//设置字段类型 date 日期 text 文本 select 列表
var columngen = [{ type: 'date', dateFormat: 'YYYY/MM/DD' },//計上日
{ type: 'text' },//伝票摘要
{ editor: 'select', selectOptions: ["借方", "貸方"]},//貸借区分
{ type: 'text', allowEmpty: true, DefaultValue: false}//勘定科目-補助科目コード
]
$(function () {
//初始化
var $container = $("#datatable");
hot1 = $container.handsontable({
data: data,
colHeaders: haedgen,
minSpareRows: 1,
width: "100%",
height: 500,
columns: columngen,
rowHeaders: true,
//manualColumnFreeze: true,
contextMenu: true,
//这一块是我追加的 一个技能 输入 勘定科目-補助科目コード 出名用的,, 代码有所删减,, 所以这块就不用看了。。
afterChange: function (changes, source) {
if (source == "loadData") {
}
else if (source == "edit" || source == "paste" || source == "autofill") {
for (var i = 0; i < changes.length; i++) {
//勘定コード
if (changes[i][1] == 3) {
var AccountName = AccountSelect(changes[i][3]);
var $container = $("#datatable");
$container.handsontable('setDataAtCell', changes[i][0], 4, AccountName);
}
//従業員 取引先
if (changes[i][1] == 6) {
var VenEmpName = VenEmpSelect(changes[i][3]);
var $container = $("#datatable");
$container.handsontable('setDataAtCell', changes[i][0], 7, VenEmpName);
}
//組織
if (changes[i][1] == 10) {
var OrgName = OrgSelect(changes[i][3]);
var $container = $("#datatable");
$container.handsontable('setDataAtCell', changes[i][0], 11, OrgName);
}
}
}
},
});
获取 handsontable的值
var handsontable = $container.data('handsontable');
var data = handsontable.getData();
用ajax 往 controller传值
$.ajax({
type: "post",
url: "/BatchMain/Select",
dataType: "json",
data: { "data": json, "selectvalue": selectjson },
success: function (jsonResult) {
if (jsonResult == "0") {
alert("データ作成しました。");
return 0;
}
}
});
删除行
$container.handsontable('alter', 'remove_row', i);
http://past.handsontable.com/demo/contextmenu.html
https://docs.handsontable.com/0.25.0/tutorial-data-sources.html?_ga=1.120691531.215382175.1465181891