$('#dg1').datagrid({
url : 'XXAction_WorkingItem',
loadFilter : pagerFilter,
rownumbers : true,
singleSelect : true,
pageSize : 20,
pagination : true,
multiSort : true,
fit : true,
collapsible : true,
onLoadSuccess:function(data){
$("a[name='opera']").linkbutton({text:'添加',plain:true,iconCls:'icon-add'});
},
columns : [ [
{
checkbox : true
},
{
field : 'ord_id',
title : '配方编号',
width : $(this).width() * 0.2,
sortable : true
},
{
field : 'ord_date',
title : '下单时间',
width : $(this).width() * 0.2,
sortable : true
},
{
field : 'pstatus',
title : '配方状况',
width : $(this).width() * 0.2,
sortable : true,
formatter:function(value, row, index){
return value=="2"?"已完成":"正在进行";
}
}, { field:'operate',title:'添加药方',align:'center',width:$(this).width()*0.3,
formatter:function(value, row, index){
var str = '';
return str;
}},
] ]
});
JSONObject json = JSONObject.fromObject(map, jsonConfig);
public String jsonstr(List>list,String s){
Map map = new HashMap();
map.put("total", list.size());
map.put("rows", list);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Timestamp.class, new DateJsonValueProcessor());
jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);//该句和以下一句,可防止存在外键时的无法转化的问题
jsonConfig.setExcludes(new String[] {s});
JSONObject json = JSONObject.fromObject(map, jsonConfig);
return json.toString();
}
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;
/**
* 转换工具类,可转换date,时间戳
*
*/
public class DateJsonValueProcessor implements JsonValueProcessor
{
private String format = "yyyy-MM-dd HH:mm:ss";
public DateJsonValueProcessor()
{
}
public DateJsonValueProcessor(String format)
{
this.format = format;
}
public Object processArrayValue(Object value, JsonConfig jsonConfig)
{
String[] obj = {};
if (value instanceof Date[])
{
SimpleDateFormat sf = new SimpleDateFormat(format);
Date[] dates = (Date[]) value;
obj = new String[dates.length];
for (int i = 0; i < dates.length; i++)
{
obj[i] = sf.format(dates[i]);
}
}
return obj;
}
public Object processObjectValue(String key, Object value, JsonConfig jsonConfig)
{
if (value instanceof Date)
{
String str = new SimpleDateFormat(format).format((Date) value);
return str;
}
if (value instanceof Timestamp)
{
String str = new SimpleDateFormat(format).format((Date) value);
}
return value;
}
public String getFormat()
{
return format;
}
public void setFormat(String format)
{
this.format = format;
}
}