jqgrid colModel 中formatter的用法

var historys = function()
{
 function format(cellvalue){ //cellvalue表示当前单元格的值
  var str = "";
        var hour = 0;
        var minute = 0;
        var second = 0;

        second = cellvalue / 1000;

        if (second > 60) {
            minute = second / 60;
            second = second % 60;
        }
        if (minute > 60) {
            hour = minute / 60;
            minute = minute % 60;
        }
       
        var strHour = parseInt(hour);
        var strMinute = parseInt(minute); 
        var strSecond = parseInt(second);
       
        return (strHour + "小时" + strMinute + "分钟"
                + strSecond + "秒");
 }
 
 
 /**加载数据列表*/
 /**加载数据列表*/
 this.load_processHistories_list=function()
 {
  $("#historyProcess").jqGrid({ 
   url:'upload!showHistories.action',
   mtype:"post",
   datatype:"json",         
   height:250,width:850,
   colNames:['Key','ProcessID','InstanceID','state','startTime','endTime','Duration','endActivityName'],
   colModel:[
       {name:'key',index:'key',width:50,sorttype:'Long',sortable:true,editable:true},
       {name:'processDefinitionId',index:'processDefinitionId',width:100,editable:true},
       {name:'processInstanceId',index:'processInstanceId',width:100,align:'center',editable:true},
       {name:'state',index:'state',width:50,sortable:false,align:'center',editable:true},
       {name:'startTime',index:'startTime',width:100,align:'center',editable:true},
       {name:'endTime',index:'endTime',width:100,sortable:false,align:'center',editable:true},
       {name:'duration',index:'duration',width:100,align:'center',editable:true,formatter:format},
       {name:'endActivityName',index:'endActivityName',width:150,sortable:false,align:'center',editable:true}
      ],
   pager:'#page',
   rowNum:10,
   rowList:[10,15,20,30],
   viewrecords: true,
   multiselect:true,
   sortname:'imId',
   sortorder:'desc',
   editurl:'eidt.do',
   caption:'  流程管理',
   jsonReader: {
    root: "histories",
    records: "records",
    page: "page",
    total: "total",
    repeatitems: false,
    id: "imId"
   },
   toolbar: [true,"top"],
    
  });

   
   $("#t_historyProcess")
   .css("padding-top","5px")
   .css("padding-bottom","10px")
   .css("border-top","none")
   .css("background","#eee")
   .css("text-align","left");
   
   $("#t_historyProcess").append($('#toolbar').html());

   jQuery("#historyProcess") .navGrid('#page',{edit:false,add:false,del:false,search:false});

 
 }
 /**open the search window*/
 this.search_openwindow=function()
 {  
  $('#searchProcess').window('open');
 }

 /**close the search window*/
 this.search_closewindow=function()
 {  
  $('#searchProcess').window('close');
 }
  //载入
  return {
  init: function()
  {
   //加载数据列表
          load_processHistories_list();
          $('#link_search_ok').click(search_openwindow);
    $('#link_search_cancel').click(search_closewindow); 
  }
 }
 
}();

 

//载入
$(document).ready(function()
{
 historys.init();
});

你可能感兴趣的:(jquery,json,list,function,upload,search)