Sfairadora

  • Reference Guide

Inserting Columns

You can insert a new column into a table using the New Column command from the context menu. The same command is located also in the Table|New Column menu and in the tool bar. The new column is inserted next to the column on which you opened the context menu (or next to the column that was active when you invoked the menu or tool bar command). Upon invoking the command, a window appears that allows you to enter the properties of the new column. First of all, you can select the level of the column insertion – that is, whether the new column should appear only at the presentation level, the view level, or also at the data level. Inserting a column at any of these three levels has completely different implications; they will be therefore explained separately. For any of the three levels you can choose whether the new column should be inserted to the left or to the right of the selected column.

Inserting a Column at the Data Level

If the actual table data is stored in the Data document section, you can select insertion at the data level. This operation is equivalent to the addition of a new column to the respective table in the Data Type document section. If you need to insert multiple columns, it may be more convenient to do it in the Data Type document section. If the table has a view stored in the View section, the column will be automatically inserted also in this section.
The following properties can be specified upon the insertion of a data column:
Operation
Description
Target table
If the table view contains another joined table, or if the table has a subordinate table, you can select the target table into which the column will be inserted. In simple situations, there is only one option available and therefore you cannot change anything.
Name
Name of column data. It must be an identifier.
Data type
Column data type. It is specified by the data type editor.
Optional
If checked, the column can have missing values.
Custom presentation
If checked, custom presentation can be defined for the column – an editor for column presentation properties appears as described below in the section on columns at the presentation level. If custom presentation is not specified, which is the most common case, an adequate presentation is created automatically for the column.

Inserting a Column at the View Level

If the table presentation has a local view (e.g. an automatically created table presentation in the Data document section), only this local view is changed. If the table is located in the View section, the respective view is changed as well so that this operation is equivalent to the addition of a new column to the respective table in the View Type section.
If you select the view insertion level, the data type of the inserted column is automatically switched to computed because this is the most common case. Column type can be switched to another type using the data type editor. One typical example of a computed column is illustrated below:
Operation
Description
Name
Column name. It must be an identifier.
Data type
Column data type. (Assume computed data type).
Computed item properties
Result data type
Data type of the computed column result. It must be a scalar (non-compound) type.
Getter function
A function in the Enki language computing the column value.
Example 1: suppose you have a table with columns a and b of the real number (Real) type, and you wish to create a new column containing their average value. Set the Result data type to real number and the getter function to (a+b)/2.
Example 2: suppose you have a table with a column called orders containing a subordinate table (list) of orders, and you wish to create a computed column containing the number of orders in this list. Set the Result data type to integer number (Int) and the getter function to size(orders).
Setter function
If you wish to use the computed column also to enter data into the table, you will need to specify, by means of this function, how the existing table data should be modified by the change of the computed value. The value entered into the column is referred by the function as val.
If no setter function is defined, the column values are read-only.
Example: suppose you have a column that calculates the average of a and b columns. When the value of the computed column is changed, you wish to see the same value in both source columns. Hence the Setter function should be: a = b = val .
Other
Contains analytic type supplement info. Usually you do not need to change these properties.
Custom presentation
If checked, a custom presentation can be defined for the column – an editor for column presentation properties appears as described below in the section on columns at the presentation level. If custom presentation is not specified, which is the most common case, an adequate presentation is created automatically for the column.

Inserting a Column at the Presentation Level

This operation is used to create a column presenting current data in a different fashion. The operation is equivalent to the Edit presentation command in the context menu, Table menu, or the in the tool bar and to the insertion of a new column in the dispel definition editor of the respective table. Insertion of a column into the presentation does not affect the data and view.
When you insert a column at the presentation level, you need to specify column properties as explained in the chapter on column properties. In addition to table column properties, you have to specify the control that will be displayed in every cell of the table. This is done by the dispel definition editor.
In order to create a table cell control, you have to enter a reference to the appropriate data. A table provides objects of the following names to cell controls:
Name
Description
row_data
Refers to the entire table row. For example, data in a column called Score is referenced by the Enki language as row_data.score. In a control definition, the Object name field would be set to row_data and the Data reference field to Score.
You can change the row_data name in the table definition in the Object name of data for rows field.
cell_data
Refers to data in a particular cell, i.e. data of the specific column contained in a certain row. The column is identified by the Reference of column data item in column properties. If the Reference of column data item is empty, then row_data and cell_data refer to the same data. If we consider the above example and the Reference of column data is set to Score, then the row_data.score and cell_data references refer to the same data.
You can change the cell_data name in the table definition in the Object name of data for cells field.
Example: suppose you have an integer number (Int) type column called Score in a table and wish to create a column that will graphically illustrate the score by a horizontal bar, which will be the longer, the higher the score is. To do this, insert a new column at the presentation level (no data is added and no view is changed). Set the Reference of column data to Score because an alternative presentation of this column is being created. Select Image label as the required control. Switch the Display|Image control property to specification by function (by clicking the fn button). Enter the following Enki language code in the function editor:
var Bitmap bmp = bitmap(100, 10);
bmp<-draw_rectangle(0, 0, cell_data, 10, color(0, 0, 200));
return bmp;
The first line creates an image named bmp of 100×10 pixels. The second line draws a rectangle into the picture (a horizontal line) from the upper left corner (coordinates 0, 0), whose height is 10 pixels and length determined by the column value (cell_data reference). The rectangle will be blue (color color(0,0,200)). The function returns the created image. (return bmp command).
Note: You can achieve a similar result by inserting a computed column returning an image (Bitmap type) into the table view. The solution utilizing table presentation is more appropriate, because images are created only for the currently displayed rows.