Skip to content

Commit

Permalink
fix: add search scope to total rows
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 20, 2024
1 parent a7912ef commit f7a6581
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion components/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func FromContext[T any](c *fiber.Ctx) (Results[T], error) {
// PaginatedResults returns a function that paginates the results.
func PaginatedResults[T any](value interface{}, pagination *Results[T], db *gorm.DB) func(db *gorm.DB) *gorm.DB {
var totalRows int64
db.Model(value).Count(&totalRows).Where("deleted_at IS NULL")
db.Model(value).Scopes(searchScope(pagination)).Count(&totalRows).Where("deleted_at IS NULL")

pagination.TotalRows = int(totalRows)
totalPages := int(math.Ceil(float64(totalRows) / float64(pagination.Limit)))
Expand Down

0 comments on commit f7a6581

Please sign in to comment.