JqGrid datetime column returns string value like /Date(1380565800000) instead of DateTime object
我正在使用具有以下colmodel定义的jqgrid
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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 } ], |
自定义格式化程序loadcapfollowupdialog如下所示
1 2 3 4 5 6 7 8 9 10 11 12 | 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>"; |
号
}
在此列值的格式化程序readingTransferTime&cpapDeliveredDate中,我得到的是/date(1380565800000)/这样的字符串值,而不是datetime对象。这为我的操作方法cpapdelivery接受错误的参数值创建了问题。如何解决这个问题?
我从这里取了1个溶液&将我的ParamList JSON对象格式化为(amp;F)
1 2 3 4 5 6 7 8 | 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" }); |
这是解决所述问题的正确方法吗;或者JQGrid有一些内置的功能来处理它。
试试这个,
1 2 3 4 5 6 | 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); |
希望这有帮助。