Class: RubyUI::DataTablePerPageSelect

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_ui/data_table/data_table_per_page_select.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Constructor Details

#initialize(path:, name: "per_page", value: nil, frame_id: nil, options: [5, 10, 25, 50], **attrs) ⇒ DataTablePerPageSelect

Returns a new instance of DataTablePerPageSelect.



5
6
7
8
9
10
11
12
# File 'lib/ruby_ui/data_table/data_table_per_page_select.rb', line 5

def initialize(path:, name: "per_page", value: nil, frame_id: nil, options: [5, 10, 25, 50], **attrs)
  @path = path
  @name = name
  @value = value
  @frame_id = frame_id
  @options = options
  super(**attrs)
end

Instance Method Details

#view_templateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_ui/data_table/data_table_per_page_select.rb', line 14

def view_template
  form_attrs = {action: @path, method: "get"}
  form_attrs[:data] = {turbo_frame: @frame_id} if @frame_id

  form(**attrs.merge(form_attrs)) do
    render RubyUI::NativeSelect.new(name: @name, onchange: safe("this.form.requestSubmit()")) do
      @options.each do |opt|
        option_attrs = {value: opt.to_s}
        option_attrs[:selected] = true if opt.to_s == @value.to_s
        option(**option_attrs) { plain opt.to_s }
      end
    end
  end
end