B
B
bzotsss2021-09-11 15:24:54
React
bzotsss, 2021-09-11 15:24:54

Algorithm for implementing pagination on the client side (without repeated requests to the API)?

Hello . Let's say I have an array

[
{Id:1,title:'hi'},
{Id:2,title:'hi'},
{Id:3,title:'hi'},
... И ещё сто объектов 
]

How to use this array to implement full-fledged pagination without repeated requests to the API? The array is loaded by fetch once.
Let's say we will display 10 objects per page. How to set the total number of buttons for pagination, I understand ( array.length / pageCountPerPage ) The
question is as follows:
1) How, for example, to click on the second button, display the next 20 objects on the page
2) How to take 20 objects from the array correctly? I had an option
//pageCount - кнопка с цифрой которую мы получили* на 20 - так я получаю до скольки записей нужно "обрезать" массив
arr.slice(0,pageCount)

My logical option is not quite working:
1) for example, the user clicks on a button with a value of 3
2) the array is cut arr.slice(0,60)
3) we get an array from 0th element to 60 , everything is OK, but what to do with 0?
It is possible without code, but only implementation logic. Preferably in React, you can use Redux
Thanks!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question