2016-07-25 105 views
0

我试着在网站上查看是否曾询问过此问题,但似乎无法找到任何相关信息。所以我使用mvc并有一个控制器页面,用于读取从sqlserver数据库中的数据,以便在包含jqgrid的视图中显示它们。如果是特定日期,请将日期设置为待定

我的问题是,你如何获取特定的日期时间值“1900-01-01 00:00:00:00”并将其显示为tbd?

这是我的两个datetime列代码:

schedule.EstimatedQAStartDate = (!reader.IsDBNull(4)) ? reader.GetDateTime(4) : (DateTime?)null; 
schedule.EstimatedorProjectedReleaseDate = (!reader.IsDBNull(5)) ? reader.GetDateTime(5) : (DateTime?)null; 

回答

0

的jqGrid的解决方案,这将是有一个格式化的日期列如下

这里也是一个jsfiddle样品我创建为你。

function formatDate(cellValue, options, rowObject) { 
     if(cellValue=="1900-01-01 00:00:00.00") 
       return "tbd"; 
       else 
       return cellValue; 
      }; 

      "use strict"; 
      var mydata = [ 
        {id:"1", DocGroupName: "2", Date: "1900-01-01 00:00:00.00", Mandatory: "Yes"}, 
        {id:"2", DocGroupName: "6", Date: "2005-03-02 05:00:00.00", Mandatory: "No"}, 
        {id:"3", DocGroupName: "6", Date: "2016-08-05 08:40:00.00", Mandatory: "No"}, 
       ]; 
      $("#list").jqGrid({ 


       //url:'php.scripts/customers.get.php', 
       //datatype: 'xml', 
       //mtype: 'POST', 
       datatype: "local", 
       data: mydata, 
       height: "auto", 

       colModel :[ 
        {name:'id', index:'id', width:55}, 
        {name:'DocGroupName', width:90}, 
        {name:'Date', formatter:formatDate, width:90, editable: true }, 
        {name:'Mandatory', index:'Mandatory', width:90, editable: true} 

       ], 
       pager: '#pager', 
       rowNum:10, 
       rowList:[10,20,30], 
       sortname: 'idcustomers', 
       sortorder: 'asc', 
       viewrecords: true, 
       gridview: true, 
       caption: 'Customers', 
       cellEdit: true, 
       cellsubmit: 'clientArray', 
       afterSaveCell: function(rowid,name,val,iRow,iCol) { 
        if(name=='DocGroupName') 
        { 
        var row = $('#list').jqGrid('getRowData',currentRow);  
        row.DocList=''; 
        var row = $('#list').jqGrid('setRowData',currentRow,row);  
        } 
       }, 
       beforeSaveCell: function(rowid,name,val,iRow,iCol) { 
       // var row = $("#list").getRowData(rowid); 
        var row = $('#list').jqGrid('getRowData',rowid); 
        currentRow= rowid; 

       }, 

      });