I want to handle page pagination in Go.
This is my code right now:
// Item size like call 2 item from database
var pagesize = 2
var PaginationSize int = 6
Pagination := make([]int, PaginationSize)
for i := 0; i < PaginationSize; i++ {
if RequestPageNumber <= page {
Pagination[i] = i + 1
}else{
Pagination[i] = RequestPageNumber + i
}
// Make it active
if i == 0 {
Info.Pagination += template.HTML(fmt.Sprintf(`<li class="page-item active"><a class="page-link" href=?id=%v>%v</a></li>`,RequestPageNumber + i ,RequestPageNumber + i))
}else{
Info.Pagination += template.HTML(fmt.Sprintf(`<li class="page-item"><a class="page-link" href=?id=%v>%v</a></li>`,RequestPageNumber + i ,RequestPageNumber + i))
}
}
The main problem is handle active page, for example active page always the first pagination:
1, 2, 3, 4, 5, 6
I want to be do it pagination page change only after number 6 (PaginationSize )
Look like 7, 8, 9, 10, 11, 12 ,13 ,14
but mine code work like this when user click on number 2:
(2), 3, 4, 5, 6, 7
also handle pagination when data in database over if possible. Thanks.
Live example to what i want to do: https://www.solodev.com/blog/web-design/adding-pagination-to-your-website.stml
Aucun commentaire:
Enregistrer un commentaire