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

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

Overview

Create a Table

This element is an extend of UiBibz::Ui::Ux::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

  • tap - Boolean

  • actionable - Boolean

  • sortable - Boolean

  • searchable - Boolean

Signatures

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

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

Examples

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

UiBibz::Ui::Ux::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 :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(options = {}, html_options = {})

table(options = { tap: true }, 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.action(content, options = {}, html_options = {})
    acs.action(options = {}, html_options = {}) do
      content
    end
  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::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

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

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



87
88
89
90
91
# File 'lib/ui_bibz/ui/ux/table/table.rb', line 87

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

Instance Attribute Details

- (Object) columns(&block)

Add table columns items



94
95
96
# File 'lib/ui_bibz/ui/ux/table/table.rb', line 94

def columns
  @columns
end

Instance Method Details

- (Object) actions(&block)

Add table actions items



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

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

- (Object) actions_list

for test



104
105
106
# File 'lib/ui_bibz/ui/ux/table/table.rb', line 104

def actions_list
  @actions
end

- (Object) render

Render html tag



109
110
111
# File 'lib/ui_bibz/ui/ux/table/table.rb', line 109

def render
  table_html
end

- (Object) store

Store must be generated by table_search_pagination method



114
115
116
117
118
119
120
121
122
# File 'lib/ui_bibz/ui/ux/table/table.rb', line 114

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