easyui datagrid数据可编辑

时间:2022-11-18 15:01:26

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}]);
}