`

ExtJs GridPanel展示Java返回的Date类型数据

阅读更多
后台Java返回时间对象格式:
"lastLoginTime":{"date":4,"day":3,"hours":12,"minutes":0,"month":6,"seconds":0,
   "time":1341374400000,"timezoneOffset":-480,"year":112}

前台处理:
ColumnModel中处理:
{header: "最后登录时间", sortable: true,
      renderer : Ext.util.Format.dateRenderer('Y-m-d H:i:s'),
      dataIndex: 'lastLoginTime'}

JsonStore中处理(注意加粗部分):
fields : ['depId','depName',{
name:'lastLoginTime',
type:'date',
mapping : 'lastLoginTime.time',
dateFormat : 'time'
},'mail','password','phone','status','userId', 'userName']
还需要注意一点,这个fields必须顺序匹配,如果没有特殊处理时间就不需要,现在特殊处理时间后,加了mapping,其他的就不知道怎么对应了,所以默认是按照返回的json顺序来,这里要对应。

但是当Java返回的Date为NULL值得时候,你会发现GridPanel压根就不显示数据了,解决办法如下(使用convert):

JsonStore中处理:
fields : ['depId','depName',{
name:'lastLoginTime',
type:'date',
mapping : 'lastLoginTime',
convert : function(v,f){
if(v == null){
return '';
}
var dt = new Date();
dt.setTime(v.time);
return Ext.util.Format.date(dt,'Y-m-d H:i:s');
},
// mapping : 'lastLoginTime.time',
dateFormat : 'time',
defaultValue : ''
},'mail','password','phone','status','userId', 'userName']
而ColumModel中就不需要特殊处理了,如下:
{header: "最后登录时间", sortable: true,dataIndex: 'lastLoginTime'}
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics