0
I searched a lot on Google but I did not have a clear path of how to make a datatable ( angular use 2 ) that contains pagination by the server, or seka, that each page he made an individual request of the same.
All I saw, makes the php request with the back-end, but brings all records in JSON at once, IE, if there are 100,000 lines it takes all of them.
I would like to develop a table that on each page ( of 30 records ) makes a request to get the JSON of the next records. The back-end part is quiet, I only need one way to do this page at the angle, how to request each request. I believe that first I will have to take a total of lines and do the division of pages, then the home page do a req http type: companies/2(page)/30 (records) to return the records of that interval.
I’ve done this with Laravel (php) through his native paging with bootstrap, but now I’m doing the front end at angular 2 and I’ll have to change.
Updating:
My Service to get http:(it works on the.log() console, but I’m unable to pass the answer to a variable and then send it to view. I’m adventuring now in Angular, mainly typescript, I’m seeing several video-lessons and tals but complicated, my area is PHP.
Service.ts
import { Injectable } from '@angular/core'; import { Http, Response, Headers, Requestoptions } from '@angular/http'; import {Observable} from 'rxjs/Rx'; //import {Company} from '.. /models/companies';
// Import Rxjs required methods import 'rxjs/add/Operator/map'; //import 'rxjs/add/Operator/catch';
@Injectable() export class Empresascrudservice { //private commentsUrl = 'http://localhost:8000/api/enterprise';
constructor(private _http: Http) { }
_endpoint_url: string = 'http://localhost/16-11/Sysferaser5.3/public/data/4';
getEmpresas(page:number) { Return this. _http.get(this._endpoint_url + "?page=" + page) . map(Sponse => Sponse.json()); }}
companies-index.component.ts:
import { Component, Oninit } from '@angular/core';
import { Empresascrudservice } from '. /services/crud.service'; import { Http, Response, Headers, Requestoptions } from '@angular/http';
@Component(? selector: 'enterprises-index', templateUrl: 'app/registrations/companies/companies-index.component.html' }) export class Empresasindexcomponent Implements Oninit{
constructor(private dataService: EmpresasCrudService) { this._service = dataService; } public _service; public _data; public _total; public _page; getEmps(page: number){ this._service.getEmpresas(page) .subscribe( people => {this._data = people.data, this._total = people.total}, error => console.error('Error: ' + error), () => console.log('Completed!') ); this._page = page; } ngOnInit(){ this.getEmps(1); }
}
enterprise-index.component.html
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Panel title
</h3>
</div>
<div class="panel-body">
Total: {{ _total }} <br>
Página: {{ _page }}
<ul>
<li *ngFor="let item of _data">{{item.empresa_id}}</li>
</ul><br><br>
</div>
<div class="panel-footer">
Panel footer
</div>
I was able to do but a question arose in the pagination, but for those who want to see the code is in the other question: <https://answall.com/questions/166128/pagina%C3%A7%C3%A3o-angular-2-server-side> I did with the library that the friend indicated
– Fernando Herique Rubim Pioli