Answer the question
In order to leave comments, you need to log in
How is page-by-page unloading of records from the database implemented correctly in the Laravel bundle (a kind of simple API is written) & Angular?
Greetings! I apologize in advance for the "footcloth", but I'm used to expressing it in detail in order to better describe the picture. Key questions are highlighted. Details below.
Just started learning Angular. Can you please tell me how to implement page-by-page unloading of records from the database in Angular? Google gives articles where the pagination of the full amount of data is described, and I need to receive data in portions through the semblance of my simple API, and switch pages using the ngb-pagination component.
I have a service that gets/adds and removes db records. The constructor receives data (the getItems method) and passes the following data to the API: the current page (1), the number of records per page (5), the field by which to sort (title) and the sort direction (ASC). In principle, it outputs correctly, except for the peculiarity of sorting records with a title in the "Record N" format, where N ∈ [1; ∞) (with ASC - 10 comes immediately after 1, not after 9, i.e. 1 - 10 - 2 - 3 - ... - 9. With DESC - 9 - 8 - 7 - ... - 2 - 1 - 10.
->orderBy('LENGTH(title)', 'ASC')
->orderBy('title', 'ASC')
->get()
и через->orderByRaw("CAST(title as UNSIGNED) ASC")
->get()
всё равно не удалось достичь нужного результата.this.items = [ ...this.items, ...data['items'] ];
let app = this;
data['items'].forEach(function(item) {
if ( app.items.indexOf(item) === -1 ) {
app.items.push(item);
}
});
, but in this case, the records were again displayed only for a moment at the time of the page switch. I am sure that the crutch is terribly, but I have no experience in angular at all. Google does not know such cases (with data being received in batches), only ways where all the data has already been received. I only googled that angular does not notice array changes when records are added and therefore they are not displayed through ngFor.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question