Chinaunix首页 | 论坛 | 博客
  • 博客访问: 262392
  • 博文数量: 34
  • 博客积分: 569
  • 博客等级: 中士
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-10 14:10
文章分类

全部博文(34)

文章存档

2016年(6)

2014年(1)

2013年(5)

2012年(22)

我的朋友

分类: Java

2012-08-02 11:55:48

场景说明

使用afterEditCell,用于触发检测输入的数据,并改变其他单元格的数据

解决方法

点击(此处)折叠或打开

  1. $("#incomegrid").jqGrid({
  2.      url : "",
  3.      datatype : "local",
  4.      colNames : ["id","收款方式","账单号",
  5.      "金额","手续费","小计","操作"],
  6.      colModel : [
  7.      {name : "id",
  8.          index : "id",
  9.          jsonmap : "ID",
  10.          hidden:true,
  11.          editable:true},//ID

  12.      {name : "mode",
  13.              index : "mode",
  14.              jsonmap : "MODE",
  15.              width:80,
  16.              align:"left",
  17.              editable:true},//收款方式

  18.      {name : "billno",
  19.                      index : "billno",
  20.                      jsonmap : "BILLNO",
  21.                      width:100,
  22.                      align:"left",
  23.                      editable:true},//账单号

  24.      {name : "amt",
  25.                  index : "amt",
  26.                  jsonmap : "AMT",
  27.                  width : 80,
  28.                  align : "right",
  29.                  formatter:"currency",
  30.                  formatoptions:{thousandsSeparator: ","},
  31.                  editable:true},//金额

  32.      {name : "fee",
  33.                  index : "fee",
  34.                  jsonmap : "FEE",
  35.                  width:60,
  36.                  align:"right",
  37.                  formatter:"currency",
  38.                  formatoptions:{thousandsSeparator: ","},
  39.                  editable:true},//费

  40.      {name : "total",
  41.                      index : "total",
  42.                      jsonmap : "TOTAL",
  43.                      width:80,
  44.                      align:"right",
  45.                      formatter:"currency",
  46.                      formatoptions:{thousandsSeparator: ","},
  47.                      editable:true,
  48.                      editoptions:{readonly:true}},//小计

  49.      {name : "actions",
  50.                      index : "actions",
  51.                      width:40,
  52.                      align:"center"}//操作

  53.      ],
  54.      rownumbers: true,
  55.      pager : "#incomediv",
  56.      viewrecords: true,
  57.      autowidth:false,
  58.      jsonReader: { repeatitems : false},
  59.      cellEdit:true,
  60.      cellsubmit:"clientArray",
  61.      gridComplete:function(){
  62.      var ids = $("#incomegrid").jqGrid("getDataIDs");
  63.      for(var i=0;i < ids.length;i++){
  64.      var cl = ids[i];
  65.      var rowdata = $("#incomegrid").jqGrid("getRowData",cl);
  66.      if(i==0){
  67.      ac = "+cl+"');\">新增";
  68.      }else{
  69.      ac = "+cl+"');\">删除";
  70.      }
  71.      $("#incomegrid").jqGrid("setRowData",cl,{actions:ac});
  72.      }
  73.      },
  74.      afterEditCell:function(rowid,name,val,iRow,iCol){
  75.      var rowdata = $("#incomegrid").jqGrid("getRowData",rowid);
  76.      var id=rowid+"_"+name;
  77.      if(name=="amt"){
  78.      $("#"+id).keyup(function(e){
  79.      var amt = $(this).val();
  80.      var fee = rowdata["fee"];
  81.      var total = parseFloat(amt) + parseFloat(fee);
  82.      $("#incomegrid").jqGrid("setRowData",rowid,{"total":total});
  83.      });
  84.      }
  85.      }
  86.      });
  87.      var length = $("#incomegrid").jqGrid("getDataIDs").length;
  88.      if(length ==0 ){
  89.      var rowdata = {"ID":0,
  90.              "NAME":"",
  91.              "MODE":"",
  92.              "AMT":0,
  93.              "FEE":0,
  94.              "TOTAL":0};
  95.      $("#incomegrid").addRowData(1,rowdata);
  96.      }


 

使用afterEditCell事件时 1、设置cellEdit:true;2、去掉onSelectRow:function(rowid){} 事件,而且也没有必要使用该事件;3、去掉$("#grid").editRow(id, true);

 

因为没有操作2、3,编辑单元格事件一直不成功,郁闷惨了

阅读(18145) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~