setQuery

Defines columns and a query to define the table to view. Either this or setDpeNames needs to be called in order to initialize this instance.

Synopsis

bool setQuery(const dyn_mapping &columnDefs,
                const string &queryFromWhere,
                function_ptr rowIdCB = nullptr)

Parameters

Parameter Description
columnDefs
Definition of the table's columns. For each column, this parameter contains a mapping with the following keys. (For each key, a constant is defined as well, see code example below.):
"_config"
Name of the config (or element) that should be shown in this table. This will be added to the SELECT clause of the query that feeds this table with data. If this is omitted, both "_colID" and "_convert" must be set, in which case, the convert method is evaluated once for each row to provide static data for this column.
"_colID"
ID for this column, will be used in update callbacks and for definitions of sorting or filtering. If omitted, the value stored under "_config" will also be used as column ID.
"_convert"
A method on the receiver set with the constructor that converts the values for this column from the actual value to the final value to be used in the table. When "_config" is not present, returns a static value for this column. The method must have the following signature:
type name(const anytype &userData, const string &rowId, const string &colId[, const anytype &value]) 
type
Return type of the method.
name
Name of the method.
userData
User data that has been passed with this constructor.
rowId
ID of the row for which the value will be converted or static data should be created.
colId
ID of the column for which the value will be converted or static data should be created.
value
The value to convert. This will be 0 for static data.
This function must return the converted value that will be included in the tables data instead of the original "value" or the static value to be used for this column.
"_hidden"
If "true", this column is processed as every other column, but its values are never included in updates. It still can be used for sorting and filtering, which is the main purpose to have such a column.
"_fastUpdate"
If "true", this column should be optimized for frequent value updates. These columns cannot be used for sorting and filtering, but are therefore handled more efficiently when being updated. However, changing the set of visible rows is less efficient if such columns are present. Note also that at least one column must exist where "_config" is set and this flag is not "true".
queryFromWhere Contains the rest of the SQL statement that defines the data of this table. Since the SELECT clause is generated from "columnDefs", this always starts with the "FROM" clause, followed possibly by a where clause.
rowIdCB
(optional) Pointer to a method on "receiver" that will be called whenever a row ID is to be created for a datapoint(element) name. If not given, the datapoint(element) name will be used as the row ID. The function must have the following signature:
string name (const anytype &userData, const string &dpName)
name
Name of the method.
userData
User data that has been passed with this constructor.
dpName
Name of the datapoint(element) that should be converted to a row ID.

Return value

Returns "true" when the query could be generated and started successfully.

dyn_mapping columns =
  makeDynMapping(
  // simple column containing the online value
    makeMapping(DynamicTableView::COLUMN_CONFIG_KEY,      ":_online.._value",
                DynamicTableView::COLUMN_ID_KEY,          "value",
                DynamicTableView::COLUMN_FAST_UPDATE_KEY, true ),
  // column containing the status, converted to unsigned long by Receiver::toUlong()
    makeMapping(DynamicTableView::COLUMN_CONFIG_KEY,      ":_online.._status",
                DynamicTableView::COLUMN_ID_KEY,          "status",
                DynamicTableView::COLUMN_CONVERT_KEY,     Receiver::toUlong),
  // column containing static data that is generated by Receiver::staticData()
  // and hidden (only used e. g. for sorting, but never displayed to the user)
    makeMapping(DynamicTableView::COLUMN_ID_KEY,          "sortVal",
                DynamicTableView::COLUMN_HIDDEN_KEY,      true,
                DynamicTableView::COLUMN_CONVERT_KEY,     Receiver::staticData));

string queryPart = "FROM '*' WHERE _DPT=\"ExampleDP_Float\"";
view.setQuery(columns, queryPart);            

Assignment

DynamicTableView

Availability

CTRL