Dates can't be display + empty entries

Dates can't be display + empty entries

mh90mh90 Posts: 1Questions: 1Answers: 0

Hey,

I'm new to DataTables, so please don't laugh about my questions ;) Hopefully you can help me, i would be very thankful:

Only the "ID" is show in the DataTable, then it at "date" stops.

If I run without the column "date" everthing works fine.

Date format on SQL Server: YYYY-MM-DD 00:00:00.000

And the second problem is, that if there are empty entries the DataTable stops too.

Test machine: IIS, PHP 5,5, MSSQL 2014

index.php:

<?php
$query = "SELECT ID, number, date, name FROM dbo.test";

$_res = sqlsrv_query($con, $query, array(), array('Scrollable' => SQLSRV_CURSOR_KEYSET ));

<?php
>
?>


<table id="test-datatable">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>number</th>
                        <th>date</th>
                        <th>name</th>
                    </tr>
                </thead>
                <tbody>
                    <?php while ($zeile = sqlsrv_fetch_array( $_res,  SQLSRV_FETCH_ASSOC))
                { ?>
                    <tr>
                        <td><?=$zeile['ID']?></td>
                        <td><?=$zeile['number']?></td>
                        <td><?=$zeile['date']?></td>
                        <td><?=$zeile['name']?></td>
                    </tr>
                    <?php } ?>
                </tbody>
</table>

<script src="js/pages/datatables.js"></script>
<script>$(function(){ datatables.init(); });</script>

datatables.js:

var datatables = function() {

    return {
        init: function() {
            App.datatables();
            $('#test-datatable').dataTable({
                columnDefs: [{ type:"de_datetime", targets: [3,4] } ],
                pageLength: 20,
                lengthMenu: [[10, 20, 30, -1], [10, 20, 30, 'All']]
            });
            $('.dataTables_filter input').attr('placeholder', 'Suche');
        }
    };
}();
This discussion has been closed.