如果日期是特定日期,请将日期设置为tbd

时间:2016-07-25 14:12:17

标签: c# asp.net-mvc datetime jqgrid

我试着浏览一下网站,看看之前是否有人问这个问题,但我似乎无法找到任何相关信息。所以我使用的是mvc并且有一个控制器页面,它从sqlserver数据库中读取数据,以便在包含jqgrid的视图中显示它们。

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

这是我的两个日期时间列的代码:

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

1 个答案:

答案 0 :(得分: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;

                },

            });