I have a DataTable that I am trying to load the data via and ajax call but the first line of data always says:
"No data available in table"
But under it the loaded ajax data is included. How do I remove the No data line and have the ajax data load into that spot?
Code Below:
<div class="box-body">
<table id="changeTicketsTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Ticket Number</th>
<th>Description</th>
<th>Risk</th>
<th>Primary CI</th>
<th>State</th>
<th>Planned Start Date</th>
<th>Actual Start Date</th>
<th>Actual End Date</th>
<th>Affected Partners</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Ticket Number</th>
<th>Description</th>
<th>Risk</th>
<th>Primary CI</th>
<th>State</th>
<th>Planned Start Date</th>
<th>Actual Start Date</th>
<th>Actual End Date</th>
<th>Affected Partners</th>
</tr>
</tfoot>
</table>
</div>
Implementation of DataTable:
<script>
getChangeTicketInformation();
$('#changeTicketsTable').DataTable({
"pageLength": 5,
'paging' : true,
'lengthChange': true,
'searching' : false,
'ordering' : true,
'info' : true,
'autoWidth' : false
});
})
</script>
Javascript used to make Ajax call:
function getChangeTicketInformation(){
$.ajax({
type: "GET",
url: "../../get_change_ticket_info",
success: function(data) {
$.each(data, function (i, item) {
$('#changeTicketsTable').find('tbody').append(
'<tr>' +
'<td>' + item.number + '</td>' +
'<td>' + item.short_description + '</td>' +
'<td>' + item.risk + '</td>' +
'<td>' + item.cmdb_ci_display_value + '</td>' +
'<td>' + item.state + '</td>' +
'<td>' + item.start_date + '</td>' +
'<td>' + item.work_start + '</td>' +
'<td>' + item.work_end + '</td>' +
'<td>' + 'FILL IN' + '</td>'
+ '</tr>');
});
}
});
}
Open the Developer tools in Chrome and type JUST the jquery (also below) into your page and see what happens. then check the html and see if this is updated as expected - it might be there, but might be hidden.
But a better approach would actually be to use DataTable's built in ajax functionality: https://datatables.net/examples/ajax/simple.html
$('#changeTicketsTable').find('tbody').append(
'<tr>' +
'<td>' + item.number + '</td>' +
'<td>' + item.short_description + '</td>' +
'<td>' + item.risk + '</td>' +
'<td>' + item.cmdb_ci_display_value + '</td>' +
'<td>' + item.state + '</td>' +
'<td>' + item.start_date + '</td>' +
'<td>' + item.work_start + '</td>' +
'<td>' + item.work_end + '</td>' +
'<td>' + 'FILL IN' + '</td>'
+ '</tr>');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With