easyUI datagrid 单元格数据的修改,保存,json 数据的转化

参考网址:http://www.jeasyuicn.com/easyui-datagrid-batch-edit-and-submit.html

参考资料:easyui demo,json.js

$("#list-csData").datagrid({
			width:'100%',
			nowrap: false,
			autoRowHeight: true,
			striped: true,
			collapsible:false,
			noheader:true,
			fitColumns:true,
			loadMsg:"正在加载......",
			url:"accept.lawcase?method=selApproval",
			singleSelect:true,
			columns:[[
		     {title:"措施编号",field:'csbh',width:150,align:'center'},
		     {title:"姓名",field:'csdx',width:100,align:'center'},
		     {title:"性别",field:'xb',width:50,align:'center'},
		     {title:"出生日期",field:'csrq',width:100,align:'center'},
		     {title:"决定结果",field:'jdjg',width:150,align:'center',
		    	 editor:{
                     type:'combobox',
                     options:{
                    	 valueField:'jdjg',
                         textField:'jgname',
                         data:[
                               {jdjg:'1001',jgname:'拘传'},
                               {jdjg:'1002',jgname:'不拘传'}
                               ],
                         required:true
                     }
		     	}
		     },
		     {title:"决定金额(元)",field:'jdje',width:100,align:'center',
		    	 editor:{
		    		 type:'numberbox',
		    		 options:{precision:1}}
					},
		     {title:"决定期限",field:'jdqx',width:150,align:'center',
						editor:{
		                     type:'combobox',
		                     options:{
		                         valueField:'jdqx',
		                         textField:'qxname',
		                         data:[
										{jdqx:'1001',qxname:'一天'},
										{jdqx:'1002',qxname:'三天'},
										{jdqx:'1003',qxname:'十天'},
										{jdqx:'1004',qxname:'三十天'}
		                               ],
		                         required:true
		                     }
				     	}			
		     	}
		    ]],
		   queryParams:{ajbh:$("#ajbh").val(),csbh:'${csbh}'},
			rownumbers:true,
			/*双击事件*/
			onClickRow:function(rowIndex,rowData){
				$('#list-csData').datagrid('selectRow', rowIndex).datagrid('beginEdit', rowIndex);
				//ajxx(rowData);
			}}
		);
	}


function spaj(){
		endEdit();
		$("#list-csData").datagrid({url:''});
		 var updated = $("#list-csData").datagrid('getChanges', "updated");
		 var f = s[typeof updated];
		 var effectRow = (f(updated));
		  $.post("approval.lawcase?method=saveMeasureResult&data="+effectRow, effectRow, function(rsp) {
			                              if('1' == rsp){
			                                  $.messager.alert("提示", "提交成功!");
			                                  $("#list-csData").datagrid('acceptChanges');
			                              }
			                          }, "JSON").error(function() {
			                              $.messager.alert("提示", "提交错误了!");
			                          });
	}


function endEdit(){
		            var rows = $("#list-csData").datagrid('getRows');
		            for ( var i = 0; i < rows.length; i++) {
		            	$("#list-csData").datagrid('endEdit', i);
		            }
		        }
	
	
	s = {
            'boolean': function (x) {
                return String(x);
            },
            number: function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            string: function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            },
            object: function (x) {
                if (x) {
                    var a = [], b, f, i, l, v;
                    if (x instanceof Array) {
                        a[0] = '[';
                        l = x.length;
                        for (i = 0; i < l; i += 1) {
                            v = x[i];
                            f = s[typeof v];
                            if (f) {
                                v = f(v);
                                if (typeof v == 'string') {
                                    if (b) {
                                        a[a.length] = ',';
                                    }
                                    a[a.length] = v;
                                    b = true;
                                }
                            }
                        }
                        a[a.length] = ']';
                    } else if (x instanceof Object) {
                        a[0] = '{';
                        for (i in x) {
                            v = x[i];
                            f = s[typeof v];
                            if (f) {
                                v = f(v);
                                if (typeof v == 'string') {
                                    if (b) {
                                        a[a.length] = ',';
                                    }
                                    a.push(s.string(i), ':', v);
                                    b = true;
                                }
                            }
                        }
                        a[a.length] = '}';
                    } else {
                        return;
                    }
                    return a.join('');
                }
                return 'null';
            }
        };


 
  

//Java 端代码

public void saveMeasureResult(HttpServletRequest request,HttpServletResponse response){
		String data = request.getParameter("data");
		PrintWriter out = null;
		try{
			out = response.getWriter();
			List chm = com.alibaba.fastjson.JSON.parseArray(data, CaseHandledMeasureInfo.class);
			ExcuteResult er = cas.saveAppMeaResult(chm.get(0));
			if(1==er.getReturnCode()){
				out.print("1");
			}else{
				out.print("0");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}


 
 

你可能感兴趣的:(jquery)