在html中添加的一个 datagrid 表格,其中editor=“text” 这个属性要有,不然不能生效,不一定是text,可以使用的类型有:text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree。
// 节选一个表格
<div style="margin-top: 50px;" id="ss"></div>
// 下面是针对这个表格的数据获取和编辑的逻辑
$('#ss').datagrid({
url: BASE + "/CreateTask/importFilterData",
nowrap: false, // 设置为true,当数据长度超出列宽时将会自动截取。
striped: true,
singleSelect: true,
loadMsg: '正在加载数据...',
pagination: true,
columns: [[{
field: 'op', align: "center", title: "批次", width: "15%"},
{
field: 'insert_num', align: "center", title: "数量", width: "15%", editor: {
type: 'text'}},
{
field: 'opera',
align: "center",
title: "开始导入",
width: "25%",
formatter: function (value, row, index) {
var operateHtml = "";
operateHtml += "<a title=\"导入\" href=\"javascript:insertFilterData("+index+");\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">导入</i></a>";
return operateHtml;
}
}]],
onDblClickCell: function (rowIndex, field, value) {
$('#ss').datagrid("beginEdit", rowIndex);
},
onAfterEdit: function (index, row, changes) {
var updated = $('#ss').datagrid('getChanges', 'updated');
if (updated.length < 1) {
editRow = undefined;
$('#ss').datagrid('unselectAll');
return;
} else {
$('#ss').datagrid('acceptChanges');
// 传值,可做在线编辑功能
/*submitForm(index, row, changes);*/
}
},
onClickCell: function (rowIndex, field, value) {
if (rowIndex == undefined) {
return true
}
if ($('#ss').datagrid('validateRow', rowIndex)) {
$('#ss').datagrid('endEdit', rowIndex);
rowIndex = undefined;
return true;
} else {
return false;
}
},
});