enhance(cosy): pagination list

This commit is contained in:
0xJacky 2024-01-15 00:08:27 +08:00
parent 79d0d37526
commit 526fedd04a
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0

View file

@ -104,7 +104,7 @@ func (c *Ctx[T]) PagingListData() (*model.DataList, bool) {
return nil, false
}
scopesResult := result.Session(&gorm.Session{}).Scopes(c.OrderAndPaginate())
scopesResult := result.Scopes(c.OrderAndPaginate())
data := &model.DataList{}
if c.scan == nil {
models := make([]*T, 0)
@ -124,7 +124,9 @@ func (c *Ctx[T]) PagingListData() (*model.DataList, bool) {
}
var totalRecords int64
result.Session(&gorm.Session{}).Count(&totalRecords)
delete(result.Statement.Clauses, "ORDER BY")
delete(result.Statement.Clauses, "LIMIT")
result.Count(&totalRecords)
page := cast.ToInt(c.ctx.Query("page"))
if page == 0 {