gpt4 book ai didi

php - 如何在数据表中显示动态列?

转载 作者:行者123 更新时间:2023-11-29 03:15:59 25 4
gpt4 key购买 nike

我已点击这些链接获取数据表。

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' }]
};
}

最佳答案

当我做控制台时显示数组:-

现在显示这个数组时它工作正常

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);
});
});
}

}

关于php - 如何在数据表中显示动态列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56439135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com