Date fields changing to epoch time format after edit

Date fields changing to epoch time format after edit

alanz303alanz303 Posts: 1Questions: 1Answers: 0

We're using the Editor with multi line editing on a VS 2015 MVC with .NET 4.5.1. Our data has 2 date columns. The first attempt at multi line editing works fine. Any second and subsequent attempts to edit the same row results in the error "Conversion failed when converting date and/or time from character string". Interrogating the Request.Form data in the ajax method shows the date is somehow getting converted to the epoch format. This is what's breaking it. After the first edit the date field looks like

CertEffDate%5d=11%2f2%2f2016+10%3a49%3a00+AM&data%5b440311%5d%5b

This is "11/2/2016 10:49:00 AM" html encoded

This is what it should look like. The second and subsequent times it looks like this:

CertEffDate%5d=%2fDate(1478098140000)%2f&data%5brow_440311%5d%5b

This is "/Date(1478098140000)/" " html encoded

These date fields are somehow getting clobbered after an edit, changing from "11/2/2016 10:49:00 AM" to "/Date(1478098140000)/". Can someone please help me with correcting this. I have spent much time and effort to no avail. The 2 date fields are CertExpDate and CertEffDate. My code follows (note I am changing the date formats to YYYY-MM-DD hh:mm) in an mRender statement:


var myTable; var editor; $(window).on("load", function () { editor = new $.fn.dataTable.Editor({ ajax: "@Url.Action("UpdateDB", "Certs")", table: "#indextable", fields: [ { label: "Request ID", name: "RequestID" }, { label: "Requester Name", name: "RequesterName" }, { label: "Cert Template Name", name: "CertTemplateName" }, { label: "Common Name", name: "CommonName" }, { label: "Cert Eff Date", name: "CertEffDate", type: "datetime" }, { label: "Cert Exp Date", name: "CertExpDate", type: "datetime" }, { label: "Owner Name", name: "OwnerName" }, { label: "Owner Email", name: "OwnerEmail" }, { label: "Server Applied To", name: "ServerAppliedTo" }, { label: "Supporting Service", name: "SupportingService" }, { type: "select", options: [ { label: "False", value: 0 }, { label: "True", value: 1 } ], label: "Not in Use", name: "NotInUse" } ] }); editor.on('open', function (e, json, data) { //hide non owner fields so they cannot be edited editor.hide('RequestID'); editor.hide('RequesterName'); editor.hide('CertTemplateName'); editor.hide('CommonName'); editor.hide('CertEffDate'); editor.hide('CertExpDate'); }); //editor.on('close', function () { // $('#row_440174 td:third').val() = '2011-01-02'; //}); myTable = $('#indextable').DataTable({ @*ajax: { url: "@Url.Action("UpdateDB", "Certs")", type: "POST" },*@ "bProcessing": true, "bPaginate": true, "sPaginationType": "full_numbers", "iDisplayLength": 25, "aaSorting": [[5, "asc"]], "autoWidth": false, "aoColumnDefs": [ { "bSearchable": true, "bSortable": true, "aTargets": [0] } ], dom: 'B<"AddWhiteSpace"l>frtip', columns: [ { data: "RequestID" }, { data: "RequesterName" }, { data: "CertTemplateName" }, { data: "CommonName" }, { data: "CertEffDate", mRender: function (data) { return (moment(data).format("YYYY-MM-DD hh:mm")); }, }, { data: "CertExpDate", mRender: function (data) { return (moment(data).format("YYYY-MM-DD hh:mm")); }, }, { data: "OwnerName" }, { data: "OwnerEmail" }, { data: "ServerAppliedTo" }, { data: "SupportingService" }, { data: "NotInUse" } ], select: true, buttons: [ { extend: 'edit', editor: editor }, 'copy', 'csv', 'excel', { extend: 'excel', text: 'Export current page', exportOptions: { modifier: { page: 'current' } } }, ] }); });

Thank you.

Answers

  • allanallan Posts: 61,938Questions: 1Answers: 10,157 Site admin

    Are you using some custom code at the server-side, or the Editor .NET libraries? If using the Editor libraries, could you use a the date time formatter.

    It sounds like the server is possibly returning an epoch format in the JSON data which we want to avoid. Ideally the client-side should only see the format it is expecting to use and you would need to use the moment renderers for the columns.

    Allan

This discussion has been closed.