ngOnInit() {
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 2
};
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 2
};
this.allservice.getUrl(this.listUserUrl)
.subscribe(data=>{
this.listUser=data.responseContents
});
}
## angular.json:
"styles": [
"src/styles.css",
"node_modules/datatables.net-dt/css/jquery.dataTables.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/datatables.net/js/jquery.dataTables.js"
]
<table datatable [dtOptions]="dtOptions" class="row-border hover">
<thead>
<tr>
<th class="text-center width-10"> Name
</th>
<th class="text-center"> User Name
</th>
</tr>
</thead>
<tbody>
<tr *ngFor = "let i = index ; let x of listUser ">
<td class="text-center">{{x.name}}</td>
<td>{{x.username}}</td>
</tr>
</tbody>
</table>
在这个Iam尝试在第一次加载时使用datatable我在表中获取数据但是如果我做任何排序r过滤器,它显示没有数据Foundnation.I不在哪里我犯错误可以任何人帮助解决这个问题。
即使在该消息上方加载了行,我也没有找到任何数据。我用dtTrigger解决了它,如下所述。
确保将[dtTrigger]="dtTrigger"
放在模板中的表格标签中。 dtTrigger: Subject<any> = new Subject();
作为组件属性。在调用服务之后将this.dtTrigger.next();
放到tigger数据表渲染中。