Class: UiBibz::Ui::Ux::Tables::Table

Inherits:
Core::Component show all
Defined in:
lib/ui_bibz/ui/ux/tables/table.rb

Overview

Create a Table

This element is an extend of UiBibz::Ui::Core::Component.

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

  • actionable - Boolean

  • sortable - Boolean

  • searchable - Boolean

  • default_actions - Boolean

  • status (:inverse, :default, :success, :primary, :secondary, :info, :danger, :warning)

  • thead - Hash (status)

    (+:inverse+, +:default+)
    
  • bordered - Boolean

  • hoverable - Boolean

  • size (:sm)

  • responsive - Boolean

  • breakpoint (:sm, :md, :lg, :xl, :xxl)

Signatures

UiBibz::Ui::Ux::Tables::Table.new(store: @store)

UiBibz::Ui::Ux::Tables::Table.new(store: @store) do |t|
  t.columns do |c|
    c.column :id, name: '#'
  end
  t.actions do |a|
    a.link '', url: url, glyph: ''
  end
end

Examples

UiBibz::Ui::Ux::Tables::Table.new(store: @users).render

UiBibz::Ui::Ux::Tables::Table.new(store: @users).tap do |t|
  t.columns do |c|
    c.column :id, { name: '#' }
    c.column :name_fr', { link: edit_user_path(:id), order: 2 }
    c.column :name_en'
    c.column :state_id, { name: 'state', format: lambda{ |records, record| "Test #{ record.id}"} }
  end
  t.actions do |a|
    a.link 'state', url: users_path(:id), glyph: 'eye'
    a.divider
    a.link 'momo', url: users_path(:id), glyph: 'home'
  end
end.render

Helper

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

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

Constant Summary

Constants inherited from Core::Component

Core::Component::BREAKPOINTS, Core::Component::SIZES, Core::Component::STATUSES

Instance Attribute Summary

Attributes inherited from Core::Component

#content, #html_options, #options

Attributes inherited from Base

#output_buffer

Instance Method Summary collapse

Methods inherited from Core::Component

#render, #tapped?

Methods included from PopoverExtension

#popover_data_html, #tooltip_data_html

Methods included from GlyphExtension

#generate_glyph, #glyph_and_content_html

Methods included from KlassExtension

#exclude_classes, #exclude_classes_in_html_options, #join_classes

Methods inherited from Base

#generate_id, #i18n_set?, #inject_url

Constructor Details

#initialize(content = nil, options = nil, html_options = nil, &block) ⇒ Table

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



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

def initialize(content = nil, options = nil, html_options = nil, &block)
  super
  @columns = Columns.new
  @actions = Actions.new store
end

Instance Method Details

#actions(&block) ⇒ Object

Add table actions items



111
112
113
# File 'lib/ui_bibz/ui/ux/tables/table.rb', line 111

def actions(&block)
  @actions.tap(&block)
end

#actions_listObject

for test



116
117
118
# File 'lib/ui_bibz/ui/ux/tables/table.rb', line 116

def actions_list
  @actions
end

#columns(&block) ⇒ Object

Add table columns items



106
107
108
# File 'lib/ui_bibz/ui/ux/tables/table.rb', line 106

def columns(&block)
  @columns.tap(&block)
end

#pre_renderObject

Render html tag



121
122
123
# File 'lib/ui_bibz/ui/ux/tables/table.rb', line 121

def pre_render
  options[:responsive] ? (:div, table_html, class: responsive) : table_html
end

#storeObject

Store must be generated by table_search_pagination method



126
127
128
129
130
131
# File 'lib/ui_bibz/ui/ux/tables/table.rb', line 126

def store
  raise 'Store is nil!' if @options[:store].nil?
  raise 'Store can be created only with "table_search_pagination" method!' if @options[:store].try(:records).nil?

  @store ||= Store.new @options[:store]
end