jeecg3.5中爲dgCol標籤增長自定義格式化列中的數值的功能

jeecg3.5中只有formatter屬性,只支持格式化時間格式的數據,不支持自定義格式化列中的值的功能,好比想把列中的的一個int或long型的值除以100轉成float或doulbe值,jeecg3.5版本就不支持相似customFormatter這樣屬性,本文爲jeecg3.5增長這個功能,主要修改的代碼以下:java

org.jeecgframework.tag.core.easyui.DataGridColumnTagapp

//51行 
private String customFormatter;
//190-192行
public void setCustomFormatter(String customFormatter) {
		this.customFormatter = customFormatter;
	}
//58行
parent.setColumn(title,field,width,rowspan,colspan,align,sortable,checkbox,formatter,hidden,replace,treefield,image,imageSize,query,url,funname,arg,queryMode, dictionary,frozenColumn,extend,style,downloadName,autocomplete,extendParams, customFormatter);

org.jeecgframework.tag.core.easyui.DataGridTag函數

//257行
String style,String downloadName,boolean isAuto,String extendParams, String customFormater) {
//285行
dataGridColumn.setCustomFormater(customFormater);
//1082-1087行
//自定義格式化數據函數
if (column.getCustomFormater() != null && column.getReplace() == null && column.getDictionary() == null) {
				//若是頁面上有replace或distionary屬性,則不單獨單重自定義函數.
				sb.append(",formatter:function(value,rec,index){");
				sb.append("return ").append(column.getCustomFormater()).append("(value, rec, index);");
				sb.append("}");
			}
//1101-1125行
if (column.getCustomFormater() == null) {
							for(int j = 0; j < value.length; j++){
								sb.append("if(valArray[k] == '" + value[j] + "'){ checkboxValue = checkboxValue + \'" + text[j] + "\' + ','}");
							}
						} else {
							for(int j = 0; j < value.length; j++){
								sb.append("if(valArray[k] == '" + value[j] + "'){ checkboxValue = checkboxValue + ");
								sb.append(column.getCustomFormater()).append("(\'").append(text[j]).append("\') + ','}");
							}
						}
						
						sb.append("}");
						sb.append("return checkboxValue.substring(0,checkboxValue.length-1);");
						sb.append("}");
						sb.append("else{");
						if (column.getCustomFormater() == null) {
							for (int j = 0; j < value.length; j++) {
								testString += "if(value=='" + value[j] + "'){return \'" + text[j] + "\'}";
							}
						} else {
							for (int j = 0; j < value.length; j++) {
								testString += "if(value=='" + value[j] + "'){return ";
								testString += column.getCustomFormater() + "(\'" + text[j] + "\')}";
							}
						}

org.jeecgframework.tag.vo.easyui.DataGridColumnui

//39行
private String customFormater;//自定義格式化數據函數
//253-259行
public String getCustomFormater() {
		return customFormater;
	}

	public void setCustomFormater(String customFormater) {
		this.customFormater = customFormater;
	}

WEB-INF/tld/easyui.tldthis

<!-- 334-338行-->
<attribute>
			<name>customFormatter</name>
			<rtexprvalue>true</rtexprvalue>
			<description>自定義格式分數據函數</description>
		</attribute>
相關文章
相關標籤/搜索