Table is loaded with data but after some miliseconds datatable cleared the loaded data and a row comes with message "No matching records found"

HTML Code
<table id="table">
<thead>
<tr>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
</tr>
</thead>
<tbody>
<?php get_data_from_db(); ?>
</tbody>
Where get_data_from_db(); is afunction which is returning the rows in form of below.
$record = <<<DELIMETER
<tr> // Repeated with data </tr>
DELIMETER;
echo $record;
Here is the Javascript Code
$('#table').DataTable();
Link DataTable files
<!-- Datatable css -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.bootstrap4.min.css">
<!-- Datatable JS-->
<script src="http://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="http://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/buttons.bootstrap4.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js"></script>
$.DataTable()tries to initiate before the dom ready state. It needs to have the html rendered in order to work properly.$(document).ready(function(){});