我遇到了日期格式的列和datepicker作为Free jQgrid中的编辑器的问题 我定义了一个带有一些日期格式列的网格,并在我的数据中包含了Java-Date-objects。
colModel:[
{name:"reminderFrom", label:"Reminder",
formatter:"date",
formatoptions:{srcformat:'ISO8601Long', newformat:'d.m.Y'},
editoptions:{size:20, dataInit:function(el)
{$(el).datepicker({dateFormat:'dd.mm.yy'});},
defaultValue: function($this) { return this.value; }},},
....
],
当我读取整个网格数据时
var fulldata = g.jqGrid('getRowData');
manipulate it (not the datestrings!) and then want to reuse it in the grid
g.jqGrid('setGridParam', {datatype: 'local', data: fulldata });
g.trigger("reloadGrid");
g.jqGrid('setGridParam', { datatype: "json"});
日期会改变。
如何使用dateformatter重新格式化datetrings以便在网格中重用?
答案 0 :(得分:1)
@Oleg 我知道jsfiddle,但我无法建立样本......
这是一些伪代码 - 应用程序基于struts并与ajax和json一起使用
Java - Serverside:
class MyDataBO {
private String myKey;
private java.util.Date myDate;
//...setter/getter
}
class MyGridAction {
List< MyDataBO> gridDataList;
public String prepareList(){
//fill the list with MyDataBO
return SHOW; //struts based
}
public List< MyDataBO> getGridDataList() {
return gridDataList;
}
}
JSP -Clientside
<table id="grid"></table>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#grid").jqGrid({
datatype: "json",
mtype: "POST",
url: "MyGridAction.getGridDataList",
jsonReader: {root: "gridDataList"},
colModel:[
{name:"myKey", label:"key", key:true},
{name:"myDate", label:"date", formatter:"date", formatoptions:{srcformat:'ISO8601Long', newformat:'d.m.Y'}
]
});
</script>
问题出现在这里
<script type="text/javascript">
var g = jQuery("#grid");
var fulldata = g.jqGrid('getRowData');
// do some work on the array
g.jqGrid('setGridParam', {datatype: 'local', data: fulldata });
g.trigger("reloadGrid");
g.jqGrid('setGridParam', { datatype: "json"});
</script>
在reloadGrid之后,日期会发生变化......