[英]On demand data load using Scrolling in AngularJS datatable
I have used angular datatable in my application. 我在应用程序中使用了角度数据表。 I applied the options as given below,
我应用了下面给出的选项,
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('responsive', true)
.withOption('bAutoWidth', false)
.withOption('paging', false)
.withOption('sorting', false)
.withOption('searching', false)
.withOption('info', false)
.withDOM('frtip');
And I set the column definition as follows, 我将列定义设置如下,
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).notSortable(),
DTColumnDefBuilder.newColumnDef(1).notSortable(),
DTColumnDefBuilder.newColumnDef(2).notSortable(),
DTColumnDefBuilder.newColumnDef(3).notSortable(),
DTColumnDefBuilder.newColumnDef(4).notSortable(),
DTColumnDefBuilder.newColumnDef(5).notSortable(),
DTColumnDefBuilder.newColumnDef(6).notSortable(),
DTColumnDefBuilder.newColumnDef(7).notSortable()
];
I html page I used the angular table as, 我在html页面中使用了角度表,
<table id="userTable" datatable="ng" dt-options="dtOptions" dt-column-defs="dtColumnDefs" class="table table-striped table-bordered dt-responsive nowrap res_table" cellspacing="0" width="100%">
I don't need the pagination of the datatable. 我不需要数据表的分页。 So I removed it.
所以我删除了它。 But I need to implement lazy loading in the table.
但是我需要在表中实现延迟加载。 I added scroll bar in the table by adding the following in the options,
我通过在选项中添加以下内容在表中添加了滚动条,
.withOption('scrollY', '48vh')
But I cannot catch the scroll event of the table. 但是我无法捕获表的滚动事件。 How can I identify the scroll reaches the end of table?
如何识别滚动到达表格末尾? So I can fetch next set of data from server and append to the table.
因此,我可以从服务器获取下一组数据并将其追加到表中。 Please help me.
请帮我。
When you are using scrolling with a specified scroll height, dataTables divides the content of the table into two different sections : .dataTables_scrollHead
, an element holding a table with the original headers, and .dataTables_scrollBody
- the table with hidden headers (height set to 0) wrapped into a scrollable element. 当使用具有指定滚动高度的滚动时,dataTables将表的内容分为两个不同的部分:
.dataTables_scrollHead
(一个包含具有原始标题的表的元素)和.dataTables_scrollBody
具有隐藏标题的表(高度设置为0 )包装为可滚动元素。 So you must listen to the onscroll
event on the .dataTables_scrollBody
element : 因此,您必须侦听
.dataTables_scrollBody
元素上的onscroll
事件:
angular.element(document).on('init.dt', function() {
document.querySelector('.dataTables_scrollBody').onscroll = function(e) {
if ((e.target.clientHeight + e.target.scrollTop) > e.target.scrollHeight-30) {
console.log('we are near the bottom')
}
}
})
Angular dataTables demo with an AJAX source and most settings from the question -> Angular dataTables演示,带有AJAX源和问题中的大多数设置->
http://plnkr.co/edit/CvdCTtwdRNuk74DtjB3O?p=preview http://plnkr.co/edit/CvdCTtwdRNuk74DtjB3O?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.