场景说明
使用afterEditCell,用于触发检测输入的数据,并改变其他单元格的数据
解决方法
- $("#incomegrid").jqGrid({
- url : "",
- datatype : "local",
- colNames : ["id","收款方式","账单号",
- "金额","手续费","小计","操作"],
- colModel : [
- {name : "id",
- index : "id",
- jsonmap : "ID",
- hidden:true,
- editable:true},//ID
- {name : "mode",
- index : "mode",
- jsonmap : "MODE",
- width:80,
- align:"left",
- editable:true},//收款方式
- {name : "billno",
- index : "billno",
- jsonmap : "BILLNO",
- width:100,
- align:"left",
- editable:true},//账单号
- {name : "amt",
- index : "amt",
- jsonmap : "AMT",
- width : 80,
- align : "right",
- formatter:"currency",
- formatoptions:{thousandsSeparator: ","},
- editable:true},//金额
- {name : "fee",
- index : "fee",
- jsonmap : "FEE",
- width:60,
- align:"right",
- formatter:"currency",
- formatoptions:{thousandsSeparator: ","},
- editable:true},//费
- {name : "total",
- index : "total",
- jsonmap : "TOTAL",
- width:80,
- align:"right",
- formatter:"currency",
- formatoptions:{thousandsSeparator: ","},
- editable:true,
- editoptions:{readonly:true}},//小计
- {name : "actions",
- index : "actions",
- width:40,
- align:"center"}//操作
- ],
- rownumbers: true,
- pager : "#incomediv",
- viewrecords: true,
- autowidth:false,
- jsonReader: { repeatitems : false},
- cellEdit:true,
- cellsubmit:"clientArray",
- gridComplete:function(){
- var ids = $("#incomegrid").jqGrid("getDataIDs");
- for(var i=0;i < ids.length;i++){
- var cl = ids[i];
- var rowdata = $("#incomegrid").jqGrid("getRowData",cl);
- if(i==0){
- ac = "+cl+"');\">新增";
- }else{
- ac = "+cl+"');\">删除";
- }
- $("#incomegrid").jqGrid("setRowData",cl,{actions:ac});
- }
- },
- afterEditCell:function(rowid,name,val,iRow,iCol){
- var rowdata = $("#incomegrid").jqGrid("getRowData",rowid);
- var id=rowid+"_"+name;
- if(name=="amt"){
- $("#"+id).keyup(function(e){
- var amt = $(this).val();
- var fee = rowdata["fee"];
- var total = parseFloat(amt) + parseFloat(fee);
- $("#incomegrid").jqGrid("setRowData",rowid,{"total":total});
- });
- }
- }
- });
- var length = $("#incomegrid").jqGrid("getDataIDs").length;
- if(length ==0 ){
- var rowdata = {"ID":0,
- "NAME":"",
- "MODE":"",
- "AMT":0,
- "FEE":0,
- "TOTAL":0};
- $("#incomegrid").addRowData(1,rowdata);
- }
使用afterEditCell事件时 1、设置cellEdit:true;2、去掉onSelectRow:function(rowid){} 事件,而且也没有必要使用该事件;3、去掉$("#grid").editRow(id, true);
因为没有操作2、3,编辑单元格事件一直不成功,郁闷惨了
阅读(18226) | 评论(0) | 转发(0) |