datetime render on column not columnDefs

datetime render on column not columnDefs

tonyaldotonyaldo Posts: 13Questions: 2Answers: 0

Hi,
All examples in datetime.js suggest that rendering should be on columnDefs. Is this really the case ?

I am trying to combine datetime plugin with the example in Child rows (show extra / detailed information)

but see** no impact on** datetime format server-side is sending e.g 2017-09-03T06:42:29.871Z

there is no errors

Any tips?
Thanks

        <script>
            /* Formatting function for row details */
            function format(d) {
                var childTable = '<table class="table table-sm">';
                // `d` is the original data object for the row
                Object.getOwnPropertyNames(d.details).forEach(
                    function (val, idx, array) {
                        childTable = childTable + '<tr>' + '<td>' + val + '</td><td>' + d.details[val] + '</td></tr>';
                    }
                );

                childTable = childTable + '</table>';
                console.log(childTable);
                return childTable;
            }

            $(document).ready(function () {

                var visitsAPIURL = '/api/visits/' + '<%= user.id %>' + '/' + '<%= QS.d %>' + '/?filter=none';
                var table = $('#visitHistory').DataTable({
                    "ajax": {
                        "url": visitsAPIURL,
                        "dataSrc": ""
                    },
                    deferRender: true,
                    dom: 'Bfrtip',
                    columns: [
                        {
                            className: 'details-control',
                            orderable: false,
                            data: null,
                            defaultContent: ''
                        },
                        {
                            data: "details.dateTimeIn",
                            render: $.fn.dataTable.moment('Do MMM YYYYY')
                        },
                        { data: "details.firstName" },
                        { data: "details.lastName" },
                        { data: "details.host" }
                    ],
                    "order": [[1, 'desc']]
                });

                table.buttons().action(function (e, dt, button, config) {
                    console.log('Button ' + this.text() + ' activated');
                    this.disable();
                });

                // Add event listener for opening and closing details
                $('#visitHistory tbody').on('click', 'td.details-control', function () {
                    var tr = $(this).closest('tr');
                    var row = table.row(tr);

                    if (row.child.isShown()) {
                        // This row is already open - close it
                        row.child.hide();
                        tr.removeClass('shown');
                    }
                    else {
                        // Open this row
                        row.child(format(row.data())).show();
                        tr.addClass('shown');
                    }
                });
            });
        </script>

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.