Formatting date text outside of columns in expandable accordion (details)

Formatting date text outside of columns in expandable accordion (details)

peter-werkpeter-werk Posts: 8Questions: 4Answers: 0
edited September 2022 in Free community support

Hello, I have a problem formatting the date in the expandable details that is not defined in the column defection as this is formed before table.

Here is the code

$(document).ready(function() {
    var clipboard = new ClipboardJS('.btn');

    function format(d) {
        return '<div class="row"> 'Last Updated: ' + {data: d.UpdatedAt, render: $.fn.dataTable.render.moment("YYYY-MM-DDTHH:mm:ss.SSSZ",'Do MMM YY' )} + '<br>' +
            '</div>';
    }

Date format in the table is UpdatedAt: "2022-09-17T10:00:32.595Z"

And I'm getting - Last Updated: [object Object]

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

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    This won't work:

    + {data: d.UpdatedAt, render: $.fn.dataTable.render.moment("YYYY-MM-DDTHH:mm:ss.SSSZ",'Do MMM YY' )} +
    

    Basically you are trying to display an object. Just use moment to display the date. See if this works:

        function format(d) {
            return '<div class="row"> 'Last Updated: ' + moment(d.UpdatedAt).format("YYYY-MM-DDTHH:mm:ss.SSSZ",'Do MMM YY' )}+ '<br>' +
                '</div>';
        }
    

    The syntax might not be correct but it should get you going in the right direction.

    Kevin

Sign In or Register to comment.