I want to make pagination with format like this: 1, 2, 3, ..., latest three.
This is my code:
let skip = null;
if(pageCount > 10){
skip = <li><span>...</span></li>
}
for(let i = 1; i <= pageCount; i++) {
if((i < page + 3 && i > page - 3)){
result.push(
<li key={i}>some link</li>
);
continue;
} else if(skip){
result.push(skip);
skip = null;
}
}
I have pageCount, which is for the example 20 and page, which is the number of the current page, for the example - 3.
I have tried many things, but still can't figure out how to do that.
The format that, I am trying to do is
if page=10, pageCount=20 :
8, 9, 10, ..., 18, 19, 20.
If page=1:
1, 2, 3, ..., 18, 19, 20.
If page=20:
1, 2, 3, ..., 18, 19, 20.