angular 7 datatables with observable data from server with pagination (not ajax)
angular 7 datatables with observable data from server with pagination (not ajax)

Hello,
I using Angular 7 and data-tables.
I want to use data-table with server-side and paging but use observable data that come from a service
For example:
the ajax call is used like that:
ngOnInit(): void {
const that = this;
this.dtOptions = {
pagingType: 'full_numbers',
responsive: true,
serverSide: true,
processing: true,
** ajax: (dataTablesParameters: any, callback) => {
that.http
.post<DataTablesResponse>(
'https://angular-datatables-demo-server.herokuapp.com/',
dataTablesParameters, {}
).**subscribe(resp => {
that.persons = resp.data;
I need to use/using
ngOnInit(): void {
const that = this;
this.dtOptions = {
pagingType: 'full_numbers',
responsive: true,
serverSide: true,
processing: true,
this.subscription = this.controllerService.getAdminControllers().subscribe(
(controllers:{pagination?: Pagination, data?: Controller[]}) => {
this.controllers = controllers.data;
console.log(this.controllers);
this.isWorking = false;
this.rerender();
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Hi all,
I finally found the solution to my question.
It is simple as it looks
So when you using Server-side data-tables with angular,
In the.ts component file when using ajax instead make a direct call to some URL.
Just use a service that returns the observable (in my case).
Code snippet:
How to do it for Angular 7 server side pagination with get method