Goal
My goal is to create a full-sized scrollable HTML table in which rows are lazy-loaded from a MySQL database.
What I tried
I am using DataTables based on this example:
Scrollable extension - Server-side processing
- on this page, the table data in this are generated by javascript
The content of my Data Table is loaded from a MySQL database:
- Data sources - Server-side processing
- lazy loading is important in this case
Result
Although the linked DetaTables guides working properly itself. When I combine the Scrollable extension, Server-side processing (lazy loading), and 100% height table, the result is inappropriate:
- Only the first ajax element is loaded into the table, the other parts will remain unfilled. The ajax data is also not loaded as a result of scrolling.
- Code snippet attached below
Another attempt - Bootstrap
I tried to use the example about Scrolling and Bootstrap tab
- In this case, all of the rows are loaded by a single huge AJAX request and the client is overloaded (lazy loading not working).
Code Snippet
$(document).ready( function () {
var table = $('#example').DataTable( {
processing: true,
serverSide: true,
ajax: "server_processing.php", //source: https://datatables.net/examples/data_sources/server_side.html
serverSide: true,
ordering: true,
searching: false,
scrollX: true,
scroller: {
loadingIndicator: true
}
} );
} );
<link href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/scroller/2.0.3/css/scroller.dataTables.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/scroller/2.0.3/js/dataTables.scroller.min.js"></script>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>