Leonel Matias Domingos
Leonel Matias Domingos

Reputation: 2040

datatables can't get right Json

I have a problem with datatables and Json data. Json seems ok , is validated but cant get datatables to work with. Get no errors, nada... enter image description here

<table id="dtable3">
<thead>
<tr>
    <th></th>
    <th>Listing Id</th>
    <th>Listing title</th>
    <th>Calendar Id</th>
    <th>Calendar Title</th>

</tr>
</thead>

<tfoot>
<tr>
    <th></th>
    <th>Listing Id</th>
    <th>Listing title</th>
    <th>Calendar Id</th>
    <th>Calendar Title</th>

</tr>
</tfoot>

$(document).ready(function () {
    var dt=<?php echo $jsonList?>;

     $('#dtable3').DataTable({

        "pageLength": 10,
        data: dt,
        // data:dat,
        columns: [
            {
                "className": 'details-control',
                "orderable": false,
                data: null,
                "defaultContent": "<span class='showBookings glyphicon glyphicon-list'></span><span class='editCal glyphicon glyphicon-pencil'></span>"
            },
            {data: 'listing_id'},
            {data: 'title_1'},
            {data: 'calendar_id'},
            {data: 'calendar_title'},
        ],
    });

Cant figure whats wrong with this json or code cause i dont get errors or anything else... Thanks for your time , apreciate very much your help.

Upvotes: 0

Views: 36

Answers (1)

davidkonrad
davidkonrad

Reputation: 85518

Since the code is working OK - http://jsfiddle.net/Lz6u5t1s/1/ - the reason is that you need to parse the string that is echoed out via PHP :

var dt = JSON.parse(<?php echo $jsonList ?>);

Upvotes: 1

Related Questions