Class: Aurita::GUI::Table
- Defined in:
- lib/aurita-gui/table.rb
Overview
Usage:
table = Table.new(:headers => [ 'user', 'phone', 'mobile', 'email' ])
table.add_row('fuchsto', '+49 89 123456', '+49 89 987654', '[email protected]')
A row element may be of type Aurita::GUI::Element. In this case, method #string is invoked to render the cell.
More examples:
t = Table.new(:headers => ['user', 'phone', 'email'],
:class => 'css_class',
:id => 'test_table' )
t.add_row('a','b','c' )
t[0].class == Table_Cell
t[0][0].value = 'foo'
t[0][0].value = 45
t[1][0].onclick = 'test();'
t[0][1] = HTML.a(:href => 'http://google.com') { 'google' }
t[0][1].value.href = 'other'
t[0][1].value.content = 'clickme'
puts t[0][1].value.string
t[0].class = 'highlighted'
Instance Attribute Summary collapse
-
#column_css_classes ⇒ Object
Returns the value of attribute column_css_classes.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#row_class ⇒ Object
Returns the value of attribute row_class.
-
#row_css_classes ⇒ Object
Returns the value of attribute row_css_classes.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#template ⇒ Object
Returns the value of attribute template.
Attributes inherited from Element
#attrib, #force_closing_tag, #gui_element_id, #parent, #tag
Instance Method Summary collapse
-
#[](row_index) ⇒ Object
Returns Table_Row instance at given row index in table.
-
#[]=(row_index, row_data) ⇒ Object
Sets Table_Row instance at given row index in table.
- #add_row(*row_data) ⇒ Object
-
#cell(column, row) ⇒ Object
Returns cell at given column and row (like x, y coordinates).
-
#initialize(params = {}, &block) ⇒ Table
constructor
A new instance of Table.
- #set_column_decorator(column_index, decorator) ⇒ Object
- #set_data(row_array) ⇒ Object
- #string ⇒ Object (also: #to_s)
Methods inherited from Element
#+, #<<, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #inspect, #js_init_code, #length, #method_missing, #recurse, #remove_class, #set_content, #swap, #to_ary, #touch, #touched?, #type=, #untouch
Methods included from Marshal_Helper_Class_Methods
Methods included from Marshal_Helper
Constructor Details
#initialize(params = {}, &block) ⇒ Table
Returns a new instance of Table.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/aurita-gui/table.rb', line 40 def initialize(params={}, &block) params[:tag] = :table @headers ||= params[:headers] @num_columns ||= params[:num_columns] @num_columns ||= @headers.length if (!@columns && @headers) @columns ||= [] @rows ||= [] @headers ||= [] @row_class ||= params[:row_class] @row_class ||= Table_Row @row_css_classes = params[:row_css_classes] @row_css_classes ||= [] @row_css_classes = [ @row_css_classes ] unless @row_css_classes.is_a?(Array) @column_css_classes = params[:column_css_classes] @column_css_classes ||= [] @column_css_classes = [ @column_css_classes ] unless @column_css_classes.is_a?(Array) params[:cellpadding] = 0 unless params[:cellpadding] params[:cellspacing] = 0 unless params[:cellspacing] params.delete(:headers) params.delete(:num_columns) params.delete(:row_css_classes) params.delete(:column_css_classes) set_headers(@headers) super(params, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element
Instance Attribute Details
#column_css_classes ⇒ Object
Returns the value of attribute column_css_classes.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def column_css_classes @column_css_classes end |
#columns ⇒ Object
Returns the value of attribute columns.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def columns @columns end |
#headers ⇒ Object
Returns the value of attribute headers.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def headers @headers end |
#row_class ⇒ Object
Returns the value of attribute row_class.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def row_class @row_class end |
#row_css_classes ⇒ Object
Returns the value of attribute row_css_classes.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def row_css_classes @row_css_classes end |
#rows ⇒ Object
Returns the value of attribute rows.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def rows @rows end |
#template ⇒ Object
Returns the value of attribute template.
38 39 40 |
# File 'lib/aurita-gui/table.rb', line 38 def template @template end |
Instance Method Details
#[](row_index) ⇒ Object
Returns Table_Row instance at given row index in table.
131 132 133 |
# File 'lib/aurita-gui/table.rb', line 131 def [](row_index) rows[row_index] end |
#[]=(row_index, row_data) ⇒ Object
Sets Table_Row instance at given row index in table.
136 137 138 |
# File 'lib/aurita-gui/table.rb', line 136 def []=(row_index, row_data) rows[row_index] = row_data end |
#add_row(*row_data) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aurita-gui/table.rb', line 88 def add_row(*row_data) if row_data.first.is_a?(Array) then row_data = row_data.first end # TODO: This should happen in #string row = @row_class.new(row_data, :parent => self) @rows << row # Add row content to columns row_index = 0 @columns.each { |c| c.add[row[row_index]] row_index += 1 } end |
#cell(column, row) ⇒ Object
Returns cell at given column and row (like x, y coordinates)
126 127 128 |
# File 'lib/aurita-gui/table.rb', line 126 def cell(column, row) rows[row][column] end |
#set_column_decorator(column_index, decorator) ⇒ Object
115 116 |
# File 'lib/aurita-gui/table.rb', line 115 def set_column_decorator(column_index, decorator) end |
#set_data(row_array) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/aurita-gui/table.rb', line 118 def set_data(row_array) @rows = [] row_array.each { |row| @rows << @row_class.new(row, :parent => self) } end |
#string ⇒ Object Also known as: to_s
104 105 106 107 108 109 110 111 112 |
# File 'lib/aurita-gui/table.rb', line 104 def string t = [] if @headers.length > 0 then t = HTML.tr { @headers.collect { |cell| if cell.is_a? Element then cell else HTML.th { cell } end } } end t += rows() set_content(t) super() end |