Skip to content

Commit 1ed0a58

Browse files
author
Mattia Roccoberton
committed
feat: expose pagination total count
1 parent fb30f1f commit 1ed0a58

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

lib/tiny_admin/actions/index.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def setup_pagination(page, pagination_component_class, total_count:)
6262
@pages = (total_count / pagination.to_f).ceil
6363
return if pages <= 1 || !pagination_component_class
6464

65+
attributes = { current: current_page, pages: pages, query_string: query_string, total_count: total_count }
6566
page.pagination_component = pagination_component_class.new
66-
page.pagination_component.update_attributes(current: current_page, pages: pages, query_string: query_string)
67+
page.pagination_component.update_attributes(attributes)
6768
end
6869
end
6970
end

lib/tiny_admin/views/actions/index.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def template
2828

2929
table_body
3030
}
31+
32+
render pagination_component if pagination_component
3133
}
3234

3335
if filters&.any?
@@ -39,8 +41,6 @@ def template
3941
end
4042
}
4143

42-
render pagination_component if pagination_component
43-
4444
render TinyAdmin::Views::Components::Widgets.new(widgets)
4545
}
4646
end

lib/tiny_admin/views/components/pagination.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@ module TinyAdmin
44
module Views
55
module Components
66
class Pagination < BasicComponent
7-
attr_accessor :current, :pages, :query_string
7+
attr_accessor :current, :pages, :query_string, :total_count
88

99
def template
10-
div(class: 'pagination-div') {
11-
nav('aria-label' => 'Pagination') {
12-
ul(class: 'pagination justify-content-center') {
13-
if pages <= 10
14-
pages_range(1..pages)
15-
elsif current <= 4 || current >= pages - 3
16-
pages_range(1..(current <= 4 ? current + 2 : 4), with_dots: true)
17-
pages_range((current > pages - 4 ? current - 2 : pages - 2)..pages)
18-
else
19-
pages_range(1..1, with_dots: true)
20-
pages_range(current - 2..current + 2, with_dots: true)
21-
pages_range(pages..pages)
22-
end
10+
div(class: 'container') {
11+
div(class: 'row') {
12+
div(class: 'col total-count') {
13+
"#{total_count} items"
2314
}
15+
div(class: 'col col-6 text-center pagination-div') {
16+
nav(class: 'd-inline-block', 'aria-label': 'Pagination') {
17+
ul(class: 'pagination') {
18+
if pages <= 10
19+
pages_range(1..pages)
20+
elsif current <= 4 || current >= pages - 3
21+
pages_range(1..(current <= 4 ? current + 2 : 4), with_dots: true)
22+
pages_range((current > pages - 4 ? current - 2 : pages - 2)..pages)
23+
else
24+
pages_range(1..1, with_dots: true)
25+
pages_range(current - 2..current + 2, with_dots: true)
26+
pages_range(pages..pages)
27+
end
28+
}
29+
}
30+
}
31+
div(class: 'col')
2432
}
2533
}
2634
end

0 commit comments

Comments
 (0)