我正在尝试从大量数据中加载一些行,但是我无法做到这一点。 我尝试了各种形式的deferloading和deferrender。 请帮助我
$(document).ready(function() {
$('#example').DataTable( {
// responsive: true,
// "stateSave": true,
// "dom": '<"top"flip>rt<"bottom"ip><"clear">',
"bProcessing": true,
"serverSide": true,
"deferLoading": 5,
"ajax": {
url:"themes/garland/server-processing.php",
type:"POST"
},
select: true
});
});
答案 0 :(得分:1)
尝试下面的代码来加载某些数据集,单击 Load More 按钮后,将插入另一组行。
$(document).ready(function (){
var table = $('#example').DataTable({
dom: 'frt',
ajax: 'https://api.myjson.com/bins/qgcu',
drawCallback: function(){
// If there is some more data
if($('#btn-example-load-more').is(':visible')){
// Scroll to the "Load more" button
$('html, body').animate({
scrollTop: $('#btn-example-load-more').offset().top
}, 1000);
}
// Show or hide "Load more" button based on whether there is more data available
$('#btn-example-load-more').toggle(this.api().page.hasMore());
}
});
// Handle click on "Load more" button
$('#btn-example-load-more').on('click', function(){
// Load more data
table.page.loadMore();
});
});
.dt-more-container {
text-align:center;
margin:2em 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js"></script>
<script src="https://gyrocode.github.io/jquery-datatables-pageLoadMore/1.0.0/js/dataTables.pageLoadMore.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css"/>
<h3><a href="https://www.gyrocode.com/articles/jquery-datatables-load-more-button/" target="_blank">jQuery DataTables: "Load more" button</a></h3>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>
<div class="dt-more-container">
<button id="btn-example-load-more" style="display:none">Load More</button>
</div>