easyui datagrid数据可编辑

function onClickCell(index, field){
if (editIndex != index){
if (endEditing()) {
$("#saPayTable").datagrid("selectRow", index).datagrid('beginEdit', index);
//获取编辑行
var editors = $("#saPayTable").datagrid("getEditors", index);
var sfgzEditor = editors[0];
//绑定失焦事件并取消可编辑状态
sfgzEditor.target.bind("blur", function () {
accept();
});
$(document).keydown(function(e){
if(e.keyCode==13){
accept();
};
});
editIndex = index;
} else {
$("#saPayTable").datagrid("selectRow", editIndex);
}
}
}

//编辑更改
function accept(){
if (endEditing()){
$("#saPayTable").datagrid("acceptChanges");
sumTotal();
}
}

//表格数据被修改后,重新计算总和
function sumTotal(){
var rows = $("#saPayTable").datagrid("getRows");
var totalPay = 0;
for(var i = 0; i < rows.length; i++){
totalPay += parseFloat(rows[i].payTotal);
}
$("#saPayTable").datagrid('reloadFooter', [{"seq":"合计","payTotal": totalPay}]);
}

原文地址:https://www.cnblogs.com/yuner-angel/p/7875005.html