I'm creating an Angular 6 app with Angular datatables (https://l-lin.github.io/angular-datatables/#/welcome). This is my component code:
import { Component, OnInit, ViewChild } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { DataTableDirective } from 'angular-datatables';
@Component({
selector: 'app-mainmenu',
templateUrl: './mainmenu.component.html',
styleUrls: ['./mainmenu.component.css']
})
export class MainmenuComponent implements OnInit {
@ViewChild(DataTableDirective)
datatableElement: DataTableDirective;
dtOptions: DataTables.Settings = {};
learningPaths: LearningPath[];
constructor(private http: HttpClient) { }
ngOnInit(): void {
const that = this;
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 10,
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'http://localhost:4154/api/LP?p=1'
,
dataTablesParameters, {}
).subscribe(resp => {
that.learningPaths = resp.data;
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: []
});
});
},
columns: [{ data: 'icon', orderable: false }, { data: 'name' }, { data: 'description' }],
order: [[ 1, "asc" ]]
};
}
}
I want to be able to pass current page index to the server side api. Can anyone point me into right direction? I'm able to display current page index like this:
{{ (datatableElement.dtInstance | async)?.table().page.info().page }}
but I have no idea how to access page info before the ajax call is being made.