EasyUI-datagrid可编辑

 

 

记录第一次使用EasyUI可编辑输入框

1.HTML中table


    

2.初始化表格list是Java传递来的list

初始化年度下拉框yeardata:

var yeardata = [];//创建年度数组
	var thisYear=new Date().getUTCFullYear();//今年
	var endYear=thisYear+1;//结束年份
	for(var startYear=2014;startYear<=thisYear;startYear++){ 
		yeardata.push({"yeartime":startYear});
	};

 初始化datagrid

//初始化
function doInitList(list){
		$("#tt").datagrid({
			width:'100%',
			height:'auto',
			singleSelect:true,
			idField:'itemid',
			data:list,
			columns:[[
				{field:'yeartime',title:'年度',width:'25%',align:'center',
					formatter:function(value){
						for(var i=0; i

3.其他方法绑定数据到库

/**
	 * 添加。
	 */
	function doAdd(data,type)
	{
		//返回值。
		var returnValue = {};
		var requestData = DataForm.collectData();
		requestData.type = type;
		requestData.data = data;
		requestData.sid = "managePlatformTransactionRecodeService:addRapayInfo";
		ajaxBase.syncCall
		(
			requestData,
			function(data, textStatus, jqXHR)
		    {
		    	returnValue = data;
		    	doInitData();
		    	var replyMsg = data["replyMsg"];
				EasyUI.tipMessage(replyMsg, "提示");
		    },
			function(jqXHR, textStatus, errorThrown)
		    {
		    	returnValue = Constants.RESULT_FAILURE_JSON;
		    	var replyMsg = data["replyMsg"];
				EasyUI.tipMessage(replyMsg, "提示");
		    }
		 );
		return returnValue;
	}
	
	function deleteRow(row){
		var returnValue = {};
		var requestData = row;
		requestData.sid = "managePlatformTransactionRecodeService:deleteRapayInfo";
		ajaxBase.syncCall
		(
			requestData,
			function(data, textStatus, jqXHR)
		    {
		    	returnValue = data;
		    	doInitData();
		    },
			function(jqXHR, textStatus, errorThrown)
		    {
		    	returnValue = Constants.RESULT_FAILURE_JSON;
		    }
		);
		return returnValue;
	}

4.小结:

设置编辑时不可为空:required=true ,missingMessage=为空时自定义错误提示

editor:{type:'numberbox',options:{precision:2,required:true,missingMessage:"请输入年度代偿金额"}}

 

5.input输入框点击保存为文字,点击编辑为输入框

(1)input输入框

(2)转换方法

function editfun(id,status,editid,type){
	if(status == 1){//编辑
		var value = $("#"+id).text();
		document.getElementById(id).innerHTML = '';
		$("#"+editid).text("保存");			  
        $("#"+editid).attr("onclick","editfun(\""+id+"\",0,\""+editid+"\",\""+type+"\");");
  }else{//保存
      var value = $("#"+id).find("input").val();
      if($.isEmptyObject(value)){
        	EasyUI.tip(id+"_in","请填写内容", "2");
        	return;
      }
      document.getElementById(id).innerHTML= value;
      $("#"+editid).text("编辑");
      $("#"+editid).attr("onclick","editfun(\""+id+"\",1,\""+editid+"\",\""+type+"\");");
        	doAdd(value,type);
      }
	  DataForm.setRequiredFieldsBackgroundColor();//非空项提示
}

(3)限制输入框只能输入数字和小数点

function patternNum(obj){
		obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
	    obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
	    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value); 
	    } 
	}

 

你可能感兴趣的:(js插件)

累积代偿金额: 保存