How to dynamically bind columns in Angular datatable with API response

190 Views Asked by At

Angular datatable make columns dynamic

I have tried to setup datatable with options. the issue is I called api and bind data in table but I cant able to bind column in attribute "columns"

ts file

this.dtOptions = {
      columns: this.tableColumns1,
      // data: this.jsonData.data,
      ajax: (dataTablesParameters: any, callback) => {
        console.log(dataTablesParameters);
        this.http
          .get('https://64422d0d76540ce22585e471.mockapi.io/emp/emplist')
          .subscribe((response) => {
            callback({
              data: response, // <-- see here
            });
          });
      },
    }; 

HTML

<table *ngIf="dtRendered" datatable [dtOptions]="dtOptions" class="row-border hover">
0

There are 0 best solutions below