我已按照以下链接获取数据表。
http://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way
当前,当我使用静态列时,它工作正常。
我的要求:-
我要在数据表中动态列
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 4,
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'http://localhost/api/listregister.php',
dataTablesParameters, {}
).subscribe(resp => {
that.persons = resp.data;
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: []
});
});
},
/this place i want to dynamic column/ columns: : [{ data: 'id' }, { data: 'firstName' }, { data: 'lastName' }]
};
}
答案 0 :(得分:0)
当我做控制台时 显示数组:-
现在显示此数组时,它工作正常
console.log(this.test)显示
0: {data: "id", mData: "id"}
1: {data: "firstname", mData: "firstname"}
2: {data: "lastname", mData: "lastname"}
ngOnInit(): void {
const that = this;
const columns_data = this.getContacts();
this.test = this.persons;
console.log(this.persons);
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 4,
serverSide: true,
processing: true,
searching: false,
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'http://localhost/api/listregister.php',
dataTablesParameters, {}
).subscribe(resp => {
that.persons = resp.data;
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: []
});
});
},
columns: this.test
};
}
getContacts(): void {
this.personService.getregistercolumns()
.subscribe(
persons => {
persons.forEach((line, index) => {
this.persons.push(line);
});
});
}
}