How to convert datetime format in DataTables ? /Date(1445706000000)/

How to convert datetime format in DataTables ? /Date(1445706000000)/

WatcharaWatchara Posts: 30Questions: 5Answers: 1

Here's my code js file

$(document).ready(function () {

$('#datatab tfoot th').each(function () {
    $(this).html('<input type="text" />');
});

var oTable = $('#datatab').DataTable({
    "serverSide": true,
    "ajax": {
        "type": "POST",
        "url": '/Brand/DataHandler',
        "contentType": 'application/json',
        'data': function (data) { return data = JSON.stringify(data); }
    },
    "dom": 'frtiS',
    "scrollY": 500,
    "scrollX": true,
    "scrollCollapse": true,
    "scroller": {
        loadingIndicator: false
    },
    "processing": true,
    "paging": true,
    "deferRender": true,
    "columns": [
   { "data": "BrandName" },
   { "data": "CreateBy" },
   { "data": "UpdateBy" },
   { "data": "DateCreate",type: 'date-dd-mmm-yyyy', targets: 0 },
   { "data": "DateUpdate" },
   {
     data: "BrandID", "bSearchable": false,
     bSortable: false,
     mRender: function (data, type, full) {
     return '<a href="Brand/Edit/' + data + '"" class="openDialog btn btn-default btn-warning"  >Edit</a> &nbsp;&nbsp;'
            + '<a href="Brand/Delete/' + data + '"" Class="deleteDialog btn btn-default btn-danger " >Delete</a>&nbsp;&nbsp;'
                                           }
    }
    ],
    "order": [0, "asc"]
});

oTable.columns().every(function () {
    var that = this;

    $('input', this.footer()).on('keyup change', function () {
        that
            .search(this.value)
            .draw();
    });
});

});

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    You could try using MomentJS - you'll need to use a renderer. Or, convert it on the server-side before it is being sent to DataTables.

    Allan

  • WatcharaWatchara Posts: 30Questions: 5Answers: 1

    Thanks a lot
    Mr. Allan.

    and I try to follow by the example of datatables pattern from url

    https://editor.datatables.net/examples/advanced/multiItem.html

    but it's not working. no data render on screen.

    what's wrong with me?

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    I'm not sure why it isn't working. Can you give me a link to the page so I can take a look and see why it isn't please.

    Allan

  • WatcharaWatchara Posts: 30Questions: 5Answers: 1
    edited July 2016
    <script>
            $(function () {
                var dataTable = $("table#dados1").dataTable({
                    "sPaginationType": "full_numbers",
                    "aoColumns": [
                        { "mDataProp": "IPAddress" },
                        { "mDataProp": "Type" },
                        { "mDataProp": "ModelName" },
                        { "mDataProp": "BrandName" },
                        { "mDataProp": "DateCreate" },
                        { "mDataProp": "MachineName" },
                    ]
                });
    
                $("button.busca").click(function () {
    
                    $.post("/Dashboard/GetDados", { profissao: $("#ddlProfissao").val() }, function (json) {
    
                        dataTable.fnClearTable();
                        dataTable.fnAddData(json);
                    }, 'json');
    
                });
    
                //busca inicial
                $("button.busca").click();
    
            });
        </script>
    

    Here is my code. How to convert DateTime Format at { "mDataProp": "DateCreate" }

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Thanks for the code, however I don't see the issue from that I'm afraid. Can you give me a link to a page showing the issue, as I requested above, so I can offer some assistance.

    Allan

  • WatcharaWatchara Posts: 30Questions: 5Answers: 1

    Here is my result DateTime shown /Date(1433869200000)/. you can see as a picture

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    That's a .NET datetime object as a string. You have two options:

    • Convert it to be a readable format on the server-side (what I would recommend)
    • Convert it to be a readable format on the client-side using a renderer.

    Allan

  • WatcharaWatchara Posts: 30Questions: 5Answers: 1

    Thank you, Allan

    I can adapt it with function and now I need to be put edit button to my datatables

    How to do? in the same code on above.

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin
    edited July 2016

    Editor is the officially supported method for editing DataTables. If you use editor, I would suggest using its GetFormatter and SetFormatter for date time fields. The .NET package includes examples of that.

    Allan

  • WatcharaWatchara Posts: 30Questions: 5Answers: 1
    edited July 2016

    your suggestion page is 404 page not found.

    I need to create datatables like attached picture.

    how to change my code?

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Sorry - I've corrected the link now - it just had a trailing ).

    Allan

  • RasikaRasika Posts: 2Questions: 0Answers: 0

    Hello

  • RasikaRasika Posts: 2Questions: 0Answers: 0

    I want to convert this date format /Date(1433869200000)/

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Per my post above:

    That's a .NET datetime object as a string. You have two options:

    • Convert it to be a readable format on the server-side (what I would recommend)
    • Convert it to be a readable format on the client-side using a renderer.
This discussion has been closed.