Class: UiBibz::Ui::Ux::TablePanel

Inherits:
Core::Panel show all
Defined in:
lib/ui_bibz/ui/ux/table/table_panel.rb

Overview

Create a TablePanel

This element is an extend of UiBibz::Ui::Ux::Panel.

Attributes

  • content - Content of element

  • options - Options of element

  • html_options - Html Options of element

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

  • store - Store generate by 'table_search_pagination' method

  • url - String

  • tap - Boolean

  • table_options - Hash

    • actionable - Boolean

    • sortable - Boolean

    • searchable - Boolean

Signatures

UiBibz::Ui::Ux::TablePanel.new(store: @store)

UiBibz::Ui::Ux::TablePanel.new(store: @store, tap: true) do |t|
  t.columns do |c|
    c.column '#', { data_index: '#' }
  end
  t.actions do |a|
    a.action '', url: url, glyph: ''
  end
end

Examples

UiBibz::Ui::Ux::TablePanel.new(store: @users, table_options: { actionable: false }).render

UiBibz::Ui::Ux::TablePanel.new(store: @users).tap do |t|
  t.header 'My Table panel'
  t.columns do |c|
    c.column :id, { name: '# }, { class: 'column-id' }
    c.column :name_fr, { name: 'Name FR', link: edit_user_path(:id), order: 2 }
    c.column :name_en
    c.column :status_id, { name: 'Status', format: lambda{ |records, record| "Test #{ record.id}"} }
  end
  t.actions do |a|
    a.action 'toto', url: users_path(:id), glyph: 'eye'
    a.action '---'
    a.action 'momo', url: users_path(:id), glyph: 'home'
  end
end.render

Helper

table_panel(options = {}, html_options = {})

table_panel(options = { tap: true }, html_options = {}) do |t|
  t.header(content, options = {}, html_options = {})
  # or
  t.header(options = {}, html_options = {}) do
    content
  end

  t.body(content, options = {}, html_options = {})
  # or
  t.body(options = {}, html_options = {}) do
    content
  end

  t.columns do |cls|
    cls.column(name, options = {}, html_options = {})
    cls.column(options = {}, html_options = {}) do
      name
    end
  end
  t.actions do |acs|
    acs.action(name, options = {}, html_options = {})
    acs.action(options = {}, html_options = {}) do
      content
    end
  end

  t.footer(content, options = {}, html_options = {})
  # or
  t.footer(options = {}, html_options = {}) do
    content
  end
end

Instance Attribute Summary (collapse)

Attributes inherited from Core::Component

#content, #html_options, #options

Attributes inherited from Base

#output_buffer

Instance Method Summary (collapse)

Methods inherited from Core::Panel

#body, #footer, #header

Methods inherited from Core::Component

#add_classes, #badge_html, #class_and_html_options, #glyph, #glyph_and_content_html, #glyph_with_space, #state

Methods inherited from Base

#i18n_set?

Constructor Details

- (TablePanel) initialize(content = nil, options = nil, html_options = nil, &block)

See UiBibz::Ui::Core::Component.initialize



99
100
101
102
103
# File 'lib/ui_bibz/ui/ux/table/table_panel.rb', line 99

def initialize content = nil, options = nil, html_options = nil, &block
  super
  table_options = (@options[:table_options] || {}).merge({ store: store })
  @table        = UiBibz::Ui::Ux::Table.new(table_options, @options[:table_html_options])
end

Instance Attribute Details

- (Object) columns(&block)

Add table columns item



125
126
127
# File 'lib/ui_bibz/ui/ux/table/table_panel.rb', line 125

def columns
  @columns
end

Instance Method Details

- (Object) actions(&block)

Add table actions item



130
131
132
# File 'lib/ui_bibz/ui/ux/table/table_panel.rb', line 130

def actions &block
  @table.actions &block
end

- (Object) actions_list

for test



135
136
137
# File 'lib/ui_bibz/ui/ux/table/table_panel.rb', line 135

def actions_list
  @table.actions_list
end

- (Object) render

Render html tag



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ui_bibz/ui/ux/table/table_panel.rb', line 106

def render
  initialize_header
  initialize_footer

   :div, class_and_html_options(panel_classes) do |f|
    form_tag(url_for(url_parameters), method: :get) do
      store.parameters.each do |k,v|
        concat tag(:input, type: 'hidden', name: k, value: v) if !default_parameters?(k) && !v.blank?
      end
      concat tag(:input, type: 'hidden', name: 'store_id', value: store.id) unless store.id.nil? # if there is more one table in html page
      concat(header_html) unless @header.nil?
      concat(body_html)   unless @body.nil?
      concat(table_html)  unless store.nil?
      concat(footer_html) unless @footer.nil?
    end
  end
end