[英]Calling angular-datatable ajax call on other api response
I am using angular-datatable ( http://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way ).我正在使用角度数据表( http://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way )。
Instead on assigning to this.dtOptions in ngOnInit, I want to do it in the response of another api, but the ajax call is not going through.而不是在ngOnInit中分配给this.dtOptions,我想在另一个api的响应中执行它,但是ajax调用没有通过。
My code:-我的代码:-
ngOnInit(){
this.firstCall();
}
firstCall(){
this.api.serviceMethod().subscribe((data : model1) => {
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: data.pageLength,
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'api.com/api',
dataTablesParameters, data.req_body, {}
).subscribe(resp => {
that.persons = resp.data;
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: []
});
});
},
columns: [{ data: 'id' }, { data: 'firstName' }, { data: 'lastName' }]
};
})
}
When I am putting the dtOptions assignment in ngOnInit, it is getting called, what am I missing here.当我将 dtOptions 赋值放在 ngOnInit 中时,它会被调用,我在这里缺少什么。
Thank you in advance.先感谢您。
You must set a check in super tag (like: tbody or table when you loop in tr tag).您必须在超级标签中设置检查(例如:在 tr 标签中循环时的 tbody 或 table)。
component.html组件.html
<table *ngIf="!loading" ...>
...
...
...
component.ts组件.ts
loading = true;....subscribe(resp => { that.persons = resp.data; loading = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.