0

I am having jqGrid with following ColModel definition

colModel: [
        .
        .
        .
        {
            name: 'ReadingTransferTime', index: 'ReadingTransferTime', width: 78, formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' },
            sorttype: 'date', fixed: true, align: 'center'
        },
        .
        .
        .
        {
            name: 'CPAPStatus', index: 'CPAPStatus', sortable: false, align: 'center', formatter: LoadCPAPFollowUpDialog, width: 100, fixed: true,
            cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal!important;' }
        },            
        { name: 'CPAPDeliveryReason', hidden: true },
        { name: 'CPAPDeliveredDate', hidden: true },
        { name: 'CPAPDeliveryStatus', hidden: true }
        ],

The custom formatter LoadCPAPFollowUpDialog is as follows

function LoadCPAPFollowUpDialog(cellvalue, options, rowObject) {        
var paramList = JSON.stringify({
    ReadingID: rowObject.ReadingID,
    TransferTime:rowObject.ReadingTransferTime,
    PatientName: rowObject.PatientFullName,
    PAPDeliveredDate: rowObject.CPAPDeliveredDate,
    NonDeliveryReason: rowObject.CPAPDeliveryReason,
    GridID: "HSTCandidatesDtls"
});

return "<img src='../Content/images/icons/edit.gif' title='" + "@VirtuOxAdmin.SleepStudyDetails_Image_CPAPStatus" + "' \
onClick='openDialog(\"SleepStudyDtlsDialog\",\"" + "@VirtuOxAdmin.SleepStudyDetails_Dialog_CPAPStatus" + "\",\"CPAPDelivery\"," + paramList + ",\"500\",\"auto\")'>" + "<span>" + rowObject.CPAPDeliveryStatus + "</span>";

}

In this formatter for column value ReadingTransferTime & CPAPDeliveredDate I am getting string value like /Date(1380565800000)/ instead of datetime object. This is creating problem for my action method CPAPDelivery accepting wrong parameter value. How to resolve this problem?

I have taken 1 solution from here & formed my paramList json object as

var paramList = JSON.stringify({
    ReadingID: rowObject.ReadingID,
    TransferTime:new Date(rowObject.ReadingTransferTime.match(/\d+/)[0]*1),
    PatientName: rowObject.PatientFullName,
    PAPDeliveredDate: (rowObject.CPAPDeliveredDate!=null? new Date(rowObject.CPAPDeliveredDate.match(/\d+/)[0]*1):null),
    NonDeliveryReason: rowObject.CPAPDeliveryReason,
    GridID: "HSTCandidatesDtls"
});

Is this right way of resolving the stated problem; or jqGrid has some inbuilt functionality to deal with it.

Community
  • 1
  • 1
Shaggy
  • 315
  • 2
  • 9
  • 23

1 Answers1

0

Try this,

 string jsonDate = "/Date(1380565800000)/";
 jsonDate = jsonDate.Replace("/Date(", string.Empty); 
 jsonDate = jsonDate.Replace(")/", string.Empty);

 var date = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(long.Parse(jsonDate));
 date = date.AddDays(1);

Hope this Helps.

AthibaN
  • 2,087
  • 1
  • 15
  • 22
  • Hi, thanks for your suggestion & help. The way I used to resolve my problem is working fine; but I m not sure that my way of parsing string to date will not cause any problem in some situation. If you know some situations where my date parsing can fail then please tell me about the same. – Shaggy Oct 11 '13 at 05:38