Class: UU::DataTable::DataTable

Inherits:
OS::GVC::Component show all
Includes:
UU::DataTable
Defined in:
uu_datatable-0.11.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 included from UU::DataTable

#attributes

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)



400
401
402
403
404
405
406
407
408
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 400

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

Instance Attribute Details

- (Object) action_row_index (readonly)

Returns index (first row = index 0) in original data of a row from which VUC action has been fired or nil if VUC action was not fired from datatable row.

Examples:

# get action row, number 3 means that fourth row fired event
row_index = dtt.action_row_index # 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:

  • Index of a row from which VUC action has been fired or nil if VUC action was not fired from datatable row.



503
504
505
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 503

def action_row_index
  @action_row_index
end

- (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]


239
240
241
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 239

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]


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

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]


215
216
217
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 215

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]


187
188
189
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 187

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. Attribute data is not automatically filled from data_uri. Attribute data is empty until it is set for the first time. After that the attribute data keeps the data, and it can be accessed by the get method in future requests.

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()

# init data from data_uri ( text property )
data = UU::OS::Property.get_value(dtt.data_uri)
dtt.data = UU::DataTable::DataTableModel.new(data)

# init data from data_uri ( blob property )
data = UU::OS::Property.get_value(dtt.data_uri).data.read()
dtt.data = UU::DataTable::DataTableModel.new(data)

Parameters:

Returns:



59
60
61
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 59

def data
  @data
end

- (Object) data_uri (readonly)

Returns uri referencing JSON-formatted data object stored as an command-accessible entity (f.e. an uri of a TEXT Property). This attribute is read only and can be set only as an attribute of the content component in UXML via UXML or BBcode editation.

dtt.data_uri

#output "ues:TERRITORY:ARTIFACT:object_storing_the_json"



118
119
120
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 118

def data_uri
  @data_uri
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]


370
371
372
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 370

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]


348
349
350
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 348

def head_row
  @head_row
end

- (Object) min_width (readonly)

Minimal width of the DataTable.



394
395
396
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 394

def min_width
  @min_width
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"},
     :rowSelection => {:mode => "MULTI", :columnPosition => "LEFT", :submitAllRows => true}
   }

# 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.



108
109
110
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 108

def options
  @options
end

- (Object) options_uri (readonly)

Returns uri referencing JSON-formatted options object stored as an command-accessible entity (f.e. an uri of a TEXT Property). This attribute is read only and can be set only as an attribute of the content component in UXML via UXML or BBcode editation.

dtt.options_uri

#output "ues:TERRITORY:ARTIFACT:object_storing_the_json"



128
129
130
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 128

def options_uri
  @options_uri
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]


258
259
260
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 258

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]


304
305
306
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 304

def page_size
  @page_size
end

- (Object) row_selection (readonly)

Note:

By this setting is affected selected_rows_indexes value

Row selection options. Row selection is object and determinate selection mode of datatable. Datatable has three selection modes. Mode "NONE" does not allow select rows. Mode "SINGLE" allows select only one row and mode "MULTI" allows select any number of rows. In "MULTI" mode datatable shows checkboxes for select rows. Checkboxes may be in first or last column. This can be defined by columnPosition attribute. If is not set, checkboxes are showed in the first column.

Examples:

Example of possible values.


# datatable without selection ( default behavior )
row_selection = {:mode => "NONE"}

# datatable allowing one row selection
row_selection = {:mode => "SINGLE"}

# datatable allowing select any number of rows with checkboxes in first column
row_selection = {:mode => "MULTI"}

# datatable allowing select any number of rows with checkboxes in last column
row_selection = {:mode => "MULTI", :columnPosition => "RIGHT"}


391
392
393
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 391

def row_selection
  @row_selection
end

- (Array) selected_rows_indexes

Note:

The returned value and its behavior depend on the row_selection mode setting.

Note:

Deprecated for getting the index of the row which executed the VUC action. Use action_row_index instead.

Array of selected rows indexes.

If row_selection mode is set to "NONE", this attribute returns an array with an index of the row which started the VUC action. In this mode, the attribute is read only.

If row_selection mode is set to "SINGLE" or "MULTI", this attribute contains an array of indexes of the rows selected by the user. If is set submitAllRows in rowSelection option to true, then this array contains/sets selected rows from/to whole table regerdless of the current page. Otherwise array contains/sets only selected rows on current page. Modification of the returned object has no influence on original data. A modified array may be set back to the selected_rows_indexes.

In single selection mode, this array may contain only one value, and in multi selection mode the array may contain any number of indexes. These indexes are indexes of the rows in the unmodified datatable model. Any action like adding or removing a row in the model does not affect these indexes and indexes may point to incorrect rows.

Indexes in the array are not sorted and their order is not guaranteed. For destructive actions such as removing or moving rows, it is recommended to sort the array in descending order before starting to process the indexes, otherwise it may occur that the first row is deleted first and every index after that will point to an incorrect row or may point out of bounds of the array. It is also recommended to clear the array of selected indexes after making changes that modify the datatable model. As mentioned earlier, if you want to add a row at the beginning of the datatable and keep the row selection, you must shift the indexes, too.

Examples:

# get selected rows, number 3 means that fourth row was selected or fourth row fired VUC action
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 values
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"

Remove all selected rows and then clear the array of selected indexes

indexes = dtt.selected_rows_indexes;

# remove all rows from row with the highest index to the lowest index 
indexes.sort.reverse.each{|index| dtt.data.remove_row(index)}

# clear user selection
dtt.selected_rows_indexes = []

Add a row as the first row of the table and select it

row = # row definition

# add row to the first position
dtt.data.insert_row(0, row)
indexes = []

# shift the index of selected rows
dtt.selected_rows_indexes.each{|index| indexes << index +1 }

# select first row
indexes << 0
dtt.selected_rows_indexes = indexes

Returns:

  • (Array)

    Array with indexes of selected rows.



472
473
474
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 472

def selected_rows_indexes
  @selected_rows_indexes
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]


282
283
284
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 282

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]


329
330
331
# File 'uu_datatable-0.11.6/lib/uu/datatable/datatable.rb', line 329

def style_class
  @style_class
end