1

I have a method that runs a post to get users and I am using datable that consumes a web api in net core. But the post method is never executed. It doesn't even print the console.log ('executing ...');. What could be happening? (Datatable without server side works perfectly)

Html

 <table id="tableList" datatable [dtOptions]="dtOptions"  class="table table-bordered table-hover table-striped" *ngIf="elementList!=null">

Component

dtOptions: DataTables.Settings = {};

ngOnInit() {
const that = this;
const headers = new HttpHeaders({
  'Content-Type': 'application/json',
  'x-api-key': environment.apiKey,
  CustomToken: localStorage.getItem('customToken')
});
const options = { headers };
that.dtOptions = {
  pagingType: 'full_numbers',
  pageLength: 2,
  serverSide: true,
  processing: true,
  ajax: (dataTablesParameters: any, callback) => {
    console.log('executing....');
    that.http
      .post<DataTablesResponse>(
        'http://localhost:5000/api/Users/GetList',
        null, options
      ).subscribe(resp => {
        that.elementList = resp.data;

        callback({
          recordsTotal: resp.recordsTotal,
          recordsFiltered: resp.recordsFiltered,
          data: []
        });
      });
  },
 // columns: [{ data: 'id' }, { data: 'firstName' }, { data: 'lastName' }]
};

}

1
  • why do you call it that.dtOptions? Commented Oct 7, 2019 at 15:19

1 Answer 1

1

you should name it as this.dtOptions instead of that.dtoptions.

example here

Sign up to request clarification or add additional context in comments.

1 Comment

Your help was very useful. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.