Php 如何在datatable中显示动态列?

Php 如何在datatable中显示动态列?,php,mysql,angular7,Php,Mysql,Angular7,我按照这些链接查找数据表 目前,当我使用静态列时,它工作正常 我的要求:- 我想在数据表中创建动态列 this.dtOptions = { pagingType: 'full_numbers', pageLength: 4, serverSide: true, processing: true, ajax: (dataTablesParameters: any, callback) => { that.http .pos

我按照这些链接查找数据表

目前,当我使用静态列时,它工作正常

我的要求:-

我想在数据表中创建动态列

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' }]
  };
}
this.dtOptions={
pagingType:“完整编号”,
页长:4,
服务器端:是的,
处理:对,
ajax:(dataTablesParameters:any,callback)=>{
那是http
.邮政(
'http://localhost/api/listregister.php',
dataTablesParameters,{}
).订阅(resp=>{
即:人员=相应数据;
回拨({
recordsTotal:resp.recordsTotal,
过滤记录:分别过滤记录,
数据:[]
});
});
},
/这个地方我想动态列::[{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);
          });
      });
  }

}
0:{data:“id”,mData:“id”}
1:{data:“firstname”,mData:“firstname”}
2:{data:“lastname”,mData:“lastname”}
ngOnInit():void{
常数=this;
const columns_data=this.getContacts();
this.test=this.persons;
console.log(this.persons);
此.dtOptions={
pagingType:“完整编号”,
页长:4,
服务器端:是的,
处理:对,
搜索:假,
ajax:(dataTablesParameters:any,callback)=>{
那是http
.邮政(
'http://localhost/api/listregister.php',
dataTablesParameters,{}
).订阅(resp=>{
即:人员=相应数据;
回拨({
recordsTotal:resp.recordsTotal,
过滤记录:分别过滤记录,
数据:[]
});
});
},
列:this.test
};
}
getContacts():void{
this.personService.getregistercolumns()
.订阅(
个人=>{
persons.forEach((行、索引)=>{
这个。人。推(线);
});
});
}
}