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