Class: PhlexKit::DataTablePerPageSelect
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::DataTablePerPageSelect
- Defined in:
- app/components/phlex_kit/data_table/data_table_per_page_select.rb
Overview
Per-page NativeSelect in a GET form that self-submits on change (targeting
the table's turbo-frame when frame_id: is given). See data_table.rb.
Instance Method Summary collapse
-
#initialize(path:, name: "per_page", value: nil, frame_id: nil, options: [ 5, 10, 25, 50 ], **attrs) ⇒ DataTablePerPageSelect
constructor
A new instance of DataTablePerPageSelect.
- #view_template ⇒ Object
Methods inherited from BaseComponent
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 'app/components/phlex_kit/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 = @attrs = attrs end |
Instance Method Details
#view_template ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/phlex_kit/data_table/data_table_per_page_select.rb', line 14 def view_template form_attrs = { class: "pk-data-table-per-page", action: @path, method: "get" } form_attrs[:data] = { turbo_frame: @frame_id } if @frame_id form(**mix(form_attrs, @attrs)) do render 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 |