Class: PhlexKit::DataTablePagination

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/data_table/data_table_pagination.rb

Overview

Windowed page navigation built on the kit's Pagination parts. Feed it a paginated collection via one of the adapters — pagy:, kaminari:, plain page:/per_page:/total_count:, or any with: object responding to current_page/total_pages. Renders nothing for a single page. See data_table.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(with: nil, pagy: nil, kaminari: nil, page: nil, per_page: nil, total_count: nil, page_param: "page", path: "", query: {}, window: 1, prev_label: "<", next_label: ">", **attrs) ⇒ DataTablePagination

Returns a new instance of DataTablePagination.



8
9
10
11
12
13
14
15
16
17
# File 'app/components/phlex_kit/data_table/data_table_pagination.rb', line 8

def initialize(with: nil, pagy: nil, kaminari: nil, page: nil, per_page: nil, total_count: nil, page_param: "page", path: "", query: {}, window: 1, prev_label: "<", next_label: ">", **attrs)
  @adapter = resolve_adapter(with:, pagy:, kaminari:, page:, per_page:, total_count:)
  @page_param = page_param
  @path = path
  @query = query.to_h.transform_keys(&:to_s)
  @window = window
  @prev_label = prev_label
  @next_label = next_label
  @attrs = attrs
end

Instance Method Details

#view_templateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/phlex_kit/data_table/data_table_pagination.rb', line 19

def view_template
  return if total <= 1

  render Pagination.new(**mix({ class: "pk-data-table-pagination" }, @attrs)) do
    render PaginationContent.new do
      prev_item
      number_items
      next_item
    end
  end
end