Class: UU::DataTable::DataTable

Inherits:
OS::GVC::Component show all
Includes:
UU::DataTable
Defined in:
uu_datatable-0.4.6/lib/uu/datatable/datatable.rb

Overview

DataTable component.

Instance Attribute Summary (collapse)

Attributes inherited from OS::GVC::Component

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

Instance Method Summary (collapse)

Methods inherited from OS::GVC::Component

#add_message, #focus, #messages

Constructor Details

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

Creates new instance of DataTable component.

Parameters:

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

    Container where to insert new component

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

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



345
346
347
348
349
350
351
352
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 345

def initialize(container, data = nil)
  super(container, data)
  # set data as Hash
  json_data = attributes[:data]
  if !json_data.kind_of?DataTableModel
    attributes[:data] = DataTableModel.new(json_data)
  end
end

Instance Attribute Details

- (Object) column_filter (readonly)

Column filter options. Column filter is Array of Hashes with row filtering definition. Only rows, which contains defined string are displayed. You can use regular expressions as filter value but you must insert '/' as first and last character. You can define more than one filter. Filtering by simple string (not regular expression) is case insensitive.

Examples:

Example of possible values

# display all rows which second column value contains 'pe' case insensitive ('Peter', 'PEter', 'pEter' are appropriate values)
# and first column value contains string 'data' 
column_filter = [{:column => 1, :value => "pe"}, {:column => 0, :value => "data"}]

# display all rows which third column value starts with 'An' using regular expressions
column_filter = [{:column => 2, :value => "/^An.*/"}]

# display all rows which first column value contains at least one number using regular expressions
column_filter = [{:column => 0, :value => "/.*[0-9].*/"}]

Example of usage

# get column filter options
column_filter = dtt.column_filter # [{:column => 1, :value => "P"}]

# same as above
options = dtt.options
column_filter = options[:columnFilter]


208
209
210
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 208

def column_filter
  @column_filter
end

- (Object) column_list (readonly)

Column list options. Column list is array with column indexes in original data, which will be displayed. Columns will appear in given order. Column index is a single positive integer between 0 (index 0 = first column) and the number of columns (excluding) which is returned by UU::DataTable::DataTableModel#number_of_columns method.

Examples:

Example of possible values


# Assume that we have DataTable with six columns
dtt.data.number_of_columns # 6

# Value [3,5,0] means that only fourth, sixth and first column will be displayed in that order
column_list = [3,5,0]

# Value [1] means that only second column will be displayed
column_list = [1]

# Value [5,4,3,2,1,0] means that six columns will be displayed in reverse order
column_list = [5,4,3,2,1,0]

Example of usage

# get column list options
column_list = dtt.column_list # [3,5,0,1,4,2]

# same as above
options = dtt.options
column_list = options[:columnList]


125
126
127
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 125

def column_list
  @column_list
end

- (Object) column_sort (readonly)

Column sort options. Column sort is Array with definition of columns indexes in original data, so it is possible to sort by invisible column (filtered by #column_list). Item in Array can be Hash or simple column index as number. You can define more that one column, than if values in first column are equal, theirs order is decided by second defined column and so on. Default sorting is ascending alphabetical by CSN 97 6030. If you want another sorting manner (numeric, by date), you must define column type by UU::DataTable::DataTableModel#set_column_type.

Examples:

Example of possible values


# sort ascending by fourth column
column_sort = [3]

# same as above but we filter columns that only third and second column is displayed
# so we sort by fourth invisible column
column_list = [2,1]
column_sort = [{:column => 3}]

# sort by second column ascending, than first column descending, than third column ascending
column_sort = [1, {:column => 0, :desc => true}, 2]

Example of usage

# get column sort options
column_sort = dtt.column_sort # [{:column => 1}, {:column => 0, :desc => true}]

# same as above
options = dtt.options
column_sort = options[:columnSort]


184
185
186
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 184

def column_sort
  @column_sort
end

- (Object) column_types (readonly)

Column types options. Columns types is Array of Hashes with specific view parameters for column. Hash uses Ruby Symbols for keys. See documentation for more information about possible parameters and their meaning. List of possible parameters:

  • column [Numeric] Index of column to which the parameters belongs. Index is a single positive integer between 0 (index 0 = first column) and the number of columns (excluding) which is returned by UU::DataTable::DataTableModel#number_of_columns method.

  • width [Numeric] Fixed width of column in pixels. If text in cell is wider then column width, than it is wrapped automatically.

  • type [String] Type of column.

  • label [String] If label is defined, all cells in specific column contains this label, irrespective of cell value.

  • icon [Boolean] (default to: true) If is set to false, icons are not displayed in ues-links.

  • dateFormat [String] Format for date column type.

  • newWindow [Boolean] (default to: false) If link is opened to new window.

  • modalWindow [Boolean] (default to: false) If link is opened to modal window.

  • tooltipType [String] (default to: system) Type of tooltip.

  • tooltipText [String] Text for tooltip.

  • styleClass [String] Column style.

  • textColor [String] Text color.

  • numberFormat [String] Format for number column type.

  • indicateNegative [Boolean] (default to: false) If column is number type, and if it is negative, value is highlighted.

  • action [String] Name of action in VUC controller.

  • component [String] Type of component which will be displayed.

Examples:

Example of usage

# get column types options
column_types = dtt.column_types # [{:column => 1, :type => "ues-button", :label => "OK", :tooltipType => "custom", :tooltipText => "Confirm"}]

# same as above
options = dtt.options
column_types = options[:columnTypes]


156
157
158
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 156

def column_types
  @column_types
end

- (UU::DataTable::DataTableModel) data

DataTable data representation. DataTableModel is used for work with DataTable inner structure, you can add, insert or remove rows and columns etc.

Examples:

# get selected rows, number 3 means that fourth row was selected
data = dtt.data # DataTableModel object

# get number of rows
data.number_of_rows # 13

# remove seventh row
data.remove_row(6)

# add column with label 'Surname'
data.add_column("Surname")

# add new row at the end
row = [ "Andrew", 13 , "1415-07-06T19:20+01:00", "ues:TERR[123]:ATR[12345]" ]
data.add_row(row)

# set column type to 'datetime' at last column
data.set_column_type(-1, UU::DataTable::DataTableModel::ColumnType::DATE_TIME)

# set empty DataTableModel object
dtt.data = UU::DataTable::DataTableModel.new()

Parameters:

Returns:



49
50
51
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 49

def data
  @data
end
Note:

If paging (page = true) or filtering (column_filter = [=> 1, :value => ā€œPā€]) is enabled, than footer rows are not displayed at all.

Footer row options. Footer row is object and determine how many rows from the end will be drawn in given style. Default style is same as header row.

Examples:

Example of possible values


# the last two rows will have same style as header row 
footer_row = {:size =>  2}

# text in last row will be bold  
footer_row = {:size =>  1, :styleClass => "bold"}

Example of usage

# get footer row options
footer_row = dtt.footer_row # {:size => 1, :styleClass => "financialCell1"}

# same as above
options = dtt.options
footer_row = options[:footerRow]


339
340
341
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 339

def footer_row
  @footer_row
end

- (Object) head_row (readonly)

Head row options. Head row is boolean and determine if header row will be displayed. Default is true.

Examples:

Example of possible values


# show header row
head_row = true

# hide header row
head_row = false

Example of usage

# get head row options
head_row = dtt.head_row # false

# same as above
options = dtt.options
head_row = options[:headRow]


317
318
319
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 317

def head_row
  @head_row
end

- (Hash) options (readonly)

Returns DataTable options as Hash object with Ruby Symbols as keys. Modification of the returned hash object has no influence on the original options of DataTable.

Examples:

# get options
options = dtt.options # Hash

# output:

   {
     :page => true,
     :startPage => 0,
     :pageSize => 20,
     :columnList => [3,5,0,1,4,2],
     :columnTypes =>[{:column => 0,
                      :styleClass => "bold italic",
                      :textColor => "#FF0000"},
                    {:column => 1,
                      :type => "ues-button",
                      :label => "OK",
                      :tooltipType => "custom",
                      :tooltipText => "Confirm",
                      :width => 150},
                    {:column => 3,
                      :type => "ues-link",
                      :icon => "false",
                      :newWindow => "true"},
                    {:column => 5,
                      :type => "date",
                      :styleClass => "headCell",
                      :dateFormat => "dd.MM.yyyy HH=>mm"}
                   ],
     :columnSort => [{:column => 1}, {:column => 0, :desc => true}],
     :columnFilter => [{:column => 1, :value => "P"}],
     :styleClass =>"portal yellow",
     :headRow => false,
     :footerRow => {:size => 1, :styleClass => "financialCell1"}
   }

# get pageSize option
page_size = options[:pageSize] # 20

# get columnFilter options
column_filter = options[:columnFilter] # [{:column => 1, :value => "P"}]

Returns:

  • (Hash)

    Hash object with DataTable options.



97
98
99
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 97

def options
  @options
end

- (Object) page (readonly)

Page options. Page is boolean value and determine if rows in DataTable will be paged. Default is false.

Examples:

Example of possible values


# turn paging on
 page = true

# turn paging off
 page = false

Example of usage

# get page options
page = dtt.page # true

# same as above
options = dtt.options
page = options[:page]


227
228
229
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 227

def page
  @page
end

- (Object) page_size (readonly)

Page size options. Page size is a positive integer and determine how many rows will be on one page. Default is 25.

Examples:

Example of possible values


# Assume that we have DataTable with 100 rows
dtt.data.number_of_rows # 100

# we get 20 pages each with 5 rows
page_size = 5

# we get 10 pages each with 10 rows
page_size = 10

Example of usage

# get page size
page_size = dtt.page_size # 20

# same as above
options = dtt.options
page_size = options[:pageSize]


273
274
275
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 273

def page_size
  @page_size
end

- (Object) start_page (readonly)

Start page options. Start page is a positive integer and determine page number from zero (0 = first page) which will be displayed. If start page is greater than number of pages, last page is displayed. Default is 0.

Examples:

Example of possible values


# Assume that we have DataTable with 10 pages
dtt.data.number_of_rows # 100
dtt.page_size # 10

# second page is start page
start_page = 1 

# last page (tenth) is start page
start_page = 999

Example of usage

# get Start page options
start_page = dtt.start_page # 1

# same as above
options = dtt.options
start_page = options[:startPage]


251
252
253
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 251

def start_page
  @start_page
end

- (Object) style_class (readonly)

Style class options. Style class is a string and determine style for whole table. See documentation for possible values.

Examples:

Example of possible values


# set style to red portal table
style_class = "portal red"

# set style to high priority portal table
style_class = "portal priorityHighest"

# set style to green frame table
style_class = "frame green"

# set style to violet gradient table
style_class = "gradient violet"

Example of usage

# get style class options
style_class = dtt.style_class # "portal yellow"

# same as above
options = dtt.options
style_class = options[:styleClass]


298
299
300
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 298

def style_class
  @style_class
end

Instance Method Details

- (Array) selected_rows_indexes

Returns array of selected row's indexes (first row = index 0) in original data.

Examples:

# get selected rows, number 3 means that fourth row was selected
indexes = dtt.selected_rows_indexes # Array with [3]

# get first element of array
row_index = indexes[0] # Number 3

# get DataTableModel object
data = dtt.data

# get selected row data
row_values = data.get_row_values(row_index) # Array ["First cell value", "2013-04-13T13:58:22+02:00", 13]

# get value of second column
date = row_values[1] # String "2013-04-13T13:58:22+02:00"

Returns:

  • (Array)

    Array with indexes of selected rows.



373
374
375
# File 'uu_datatable-0.4.6/lib/uu/datatable/datatable.rb', line 373

def selected_rows_indexes
  attributes[:selectedRows].freeze
end