Class: UU::OS::GVC::Table

Inherits:
Component show all
Defined in:
uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb

Overview

Table component.

Instance Attribute Summary (collapse)

Attributes inherited from Component

#attributes, #code, #component_type, #form, #height, #id, #name, #width

Instance Method Summary (collapse)

Methods inherited from Component

#add_message, #focus, #messages

Constructor Details

- (Table) initialize(container, data = nil)

Creates new instance of Table.

Parameters:

  • container (UU::OS::GVC::Container)

    Container where to insert new Table

  • data (String, Hash) (defaults to: nil)

    Initialization data in form of JSON string or Hash (optional)



15
16
17
18
19
20
21
22
23
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb', line 15

def initialize(container, data = nil)
  super(container, data)

  if rows.kind_of?Array
    rows.map!{ |row_data|
      UU::OS::GVC::TableRow.new(row_data)
    }
  end
end

Instance Attribute Details

- (Boolean) visible

Flag if table is visible in form. Default is true. If is set to false table is completely hidden.

Examples:

# get table component
table = view.get_components_by_code("table")[0]

# hide table
table.visible = false

# make table visible again
table.visible = true

Returns:

  • (Boolean)


38
39
40
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb', line 38

def visible
  @visible
end

Instance Method Details

- (UU::OS::GVC::TableRow?) get_row(index)

Returns row object on specific index.

Examples:

# get table component
table = view.get_components_by_code("table")[0]

# get third row
row = table.get_row(2) # UU::OS::GVC::TableRow object
code = row.code # string "row_3"

# get last row from five rows
row = table.get_row(-1) # UU::OS::GVC::TableRow object
row.visible = false  # set row visibility

Parameters:

  • index (Integer)

    The Index of row. An index can be represented by a single positive integer between 0 (index 0 = first row) and the number of rows (excluding) which is returned by #number_of_rows method. You can use negative indices as well, which start counting from the end (i.e. minus number of rows), with -1 being the last element.

Returns:

  • (UU::OS::GVC::TableRow, nil)

    The table row object for specific index or nil if index is greater than or equal to number_of_rows.



58
59
60
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb', line 58

def get_row(index)
  rows[index]
end

- (Array) get_rows_by_code(code)

Returns array of table row objects with specific code. If nil is entered as the code, than all rows without a defined code are returned.

Examples:

# get table component
table = view.get_components_by_code("table")[0]

# get row with code "row_4"
row_array = table.get_rows_by_code("row_4") # Array of UU::OS::GVC::TableRow object

# get first item of array (our row object with code "row_4")
row = row_array[0]
code = row.code # string "row_4"
row.visible = false  # set row visibility

Parameters:

  • code (String)

    Table row code.

Returns:

  • (Array)

    Array of UU::OS::GVC::TableRow objects. The array may be empty if there is no row with specific code.



79
80
81
82
83
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb', line 79

def get_rows_by_code(code)
  rows.select{|row|
    row.code == code
  }
end

- (Numeric) number_of_rows Also known as: size

Returns number of rows in Table. May be zero.

Examples:

# get table component
table = view.get_components_by_code("table")[0]

# get number of rows in Table
rows_num = table.number_of_rows # Number 5

Returns:

  • (Numeric)

    Number of rows.



95
96
97
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/table.rb', line 95

def number_of_rows
  rows.size
end