Class: HtmlTables::YieldedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/html_tables/yielded_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_table) ⇒ YieldedObject

Returns a new instance of YieldedObject.



7
8
9
# File 'lib/html_tables/yielded_object.rb', line 7

def initialize(data_table)
  @t = data_table
end

Instance Attribute Details

#tObject (readonly)

Returns the value of attribute t.



5
6
7
# File 'lib/html_tables/yielded_object.rb', line 5

def t
  @t
end

Instance Method Details

#checkbox(id = nil, options = { }, &block) ⇒ Object

Adds a checkbox column to the DataTable. If a block is supplied, it is used to determine the initial state of the checkbox.

Parameters:

  • options (Hash) (defaults to: { })

    the checkbox options

Options Hash (options):

  • checked (TrueClass, FalseClass)

    the initial state of the checkbox.

  • block (Proc)

    a block which will be evaluated to define the initial state of the checkbox.

  • value_method (String)

    the method to be called to define the checkbox value. Default = :id



17
18
19
20
# File 'lib/html_tables/yielded_object.rb', line 17

def checkbox(id = nil, options = { }, &block)
  options[:block] = block if block_given?
  t.columns[id] = options.reverse_merge! checkbox: true, align: :center
end

#column(id, options = {}, &block) ⇒ Object

Adds a regular column to the DataTable.



30
31
32
33
34
# File 'lib/html_tables/yielded_object.rb', line 30

def column(id, options = {}, &block)
  options[:block] = block if block_given?
  t.columns[id] = options
  nil
end

#group_by(column_or_lambda, &block) ⇒ Object



36
37
38
39
# File 'lib/html_tables/yielded_object.rb', line 36

def group_by(column_or_lambda, &block)
  t.group_by column_or_lambda, &block
  self
end

#item_url(enabled = true, &block) ⇒ Object



47
48
49
50
# File 'lib/html_tables/yielded_object.rb', line 47

def item_url(enabled = true, &block)
  t.item_url_options = { :block => block, :enabled => enabled }
  nil
end

#nodata(msg) ⇒ Object

Sets the ‘no-data’ message. If not set, no message will be displayed when there’s no records to show.



42
43
44
45
# File 'lib/html_tables/yielded_object.rb', line 42

def nodata(msg)
  t.nodata_message = msg
  nil
end

#radio(id = nil, options = { }) ⇒ Object

Adds a radio button column to the DataTable.

Parameters:

  • options (Hash) (defaults to: { })

    the radio options

Options Hash (options):

  • value_method (String)

    the method to be called to define the radio value. Default = :id



25
26
27
# File 'lib/html_tables/yielded_object.rb', line 25

def radio(id = nil, options = { })
  t.columns[id] = options.reverse_merge! radio: true, align: :center
end

#row_class(cls, options = { }) ⇒ Object



52
53
54
# File 'lib/html_tables/yielded_object.rb', line 52

def row_class(cls, options = { })
  t.row_classes << [cls, options]
end