是否有任何解决方法可以userData
在 jqGrid 中添加自定义“格式化程序”?我发现了这个问题,它对我有很大帮助。下面是我用来填充 jqGrid 的代码。请注意,我userData
在其中填充了一个自定义对象jsonReader
并将其设置为网格,loadComplete
我需要将单独的“格式化程序”添加到总列中。请让我知道是否有办法。提前致谢。
var userDataTotals;
jq("#testGrid").jqGrid({
url:'local',
datatype: 'local',
mtype: 'GET',
colNames:[
'rowId','unitId',
'<fmt:message key="report.col1"/>',
'<fmt:message key="report.col2"/>',
],
colModel :[
{name:'rowId', index:'rowId',hidden: true,sortable: true,key:true},
{name:'unitId', index:'unitId',hidden: true,sortable: true,key:true},
{name:'outboundReadyDate', index:'outboundReadyDate', width:80,align:"center",sorttype:'integer',formatter:dateOnlyFmatter,datefmt:'Y M d'},
{name:'outboundDate', index:'outboundDate', width:80,align:"center",sorttype:'integer',formatter:dateOnlyFmatter,datefmt:'Y M d'},
],
// this will enable the footer row to display totals
footerrow : true,
//userDataOnFooter : true,
altRows : true,
//to hide pager buttons
pgbuttons:false,
recordtext:'',
pgtext:'',
gridview: true,
height:270,
loadonce: true,
sortname: 'rowId',
sortorder: 'asc',
viewrecords: true,
rowNum:30000,
loadComplete: function() {
// This will increase the column header height ( to show two rows in the header)
jq(".ui-jqgrid-sortable").css('white-space', 'normal');
jq(".ui-jqgrid-sortable").css('height', 'auto');
//Set the total values after load complete,otherwise
// custom formatter will format the total value as well.
jq("#mainReportGrid").jqGrid("footerData","set",userDataTotals,false);
//check the data type to avoid this code to execute when the pageload
var checkDatatype = myGrid.jqGrid("getGridParam","datatype");
if(checkDatatype =='json' && myGrid.getGridParam('records') == 0){
// when no records are displaying alert it to the user
alert(noRecordsMsg);
}
},
jsonReader : {
root: "dtos",
records: "records",
repeatitems: false,
cell: "cell",
id: "rowId",
userdata :function(obj) {
userDataTotals = {"outboundReadyDate":obj.totalOutBounded,
"outboundDate":obj.totalOutBoundReady};
}
},
//This will format the date of the grid (without displaying time)
function dateOnlyFmatter (cellvalue, options, rowObject){
var opts = options.colModel.formatoptions;
if(cellvalue==null || cellvalue=='undefined'){
return '-';
}else{
if(opts != undefined && rowObject.projectTypeName =='IOD'){
return 'N/A';
}
var now = new Date(cellvalue);
return now.format('M j, Y');
}
}
我使用自定义dateFormat.js
来格式化日期。
json响应是-
{
"dtos": [
{
"unitId": 1068,
"outboundDate": null,
"outboundReadyDate": 1317619303000,
"rowId": 13,
},
{
"unitId": 1105,
"outboundDate": 1317616970000,
"outboundReadyDate": 1317617213000,
"rowId": 14,
}
],
"totalOutBounded": 0,
"totalOutBoundReady": 4,
"rowTotal": 15,
"returnCode": 0,
"msg": ""
}
我使用sortType
asinteger
因为从服务器我将“java”Date
对象直接传递给网格。为了对其进行排序,我需要设置sortType
为integer
我遇到的基本问题是在 IE8 中我看不到“userData”总值。但在其他浏览器中我可以看到它。我需要将userData
总值格式化为“超链接”。
没有userData
格式化我可以看到 IE8 中的总数。所以我认为不使用列'formatter'
将自定义格式化程序添加到总值(userData
)。