Skip to content

Data table

The data table shows rows from any source. “Manual” — rows are set in the editor: a reference list, a schedule, a memo. “SQL” — a SELECT query to a database from the project’s Databases node, run by the server (at most 1000 rows). “Function” — a server script function returns an array of rows: [["a", 1], …] or [{Name: …}, …]. “Refresh, s” reloads the data periodically.

The client cannot send its own SQL to the server: the server runs only the query from the project. A script sees the rows and the selected row and can query the data again. The operator’s selection is the “Row selected” event. Databases and server functions are described in Tasks, databases, files.

Besides the properties of every element — name, position, size, tooltip, rotation, transparency and the operate right:

Property Values Default Description
Source Manual, Sql, Script Manual Data source. Manual: rows below; SQL: a query to a project database; server function: an array of rows from a server script
Columns text Параметр;Значение Columns. Headers separated by “;”: Name;Value;Unit. For SQL and functions, your own headers replace column names (empty keeps them as received)
Rows text Rows. For the “Manual” source: one table row per text line, cells separated by “;”
Database database Database. For the SQL source: a database from the project’s “Databases” node
Query text SQL query. For the SQL source: SELECT … runs on the server, at most 1000 rows
Function server function Server function. For the “Function” source: a server script function returns an array of rows: [[“a”, 1], …] or [{Name: …}, …]
RefreshSec integer 0 Refresh, s. How often to request data from the server; 0 means only when the screen opens
ShowHeader true / false true Column headers
Striped true / false true Stripes. Even rows are slightly darker, which makes long tables easier to read
FontSize number 12 Font size

Item.Type = DataTable. Any property is read and changed by name: Item.FontSize = 10. The common element members (Visible, Enabled, Value, Raise, Apply…) are described in Elements from scripts.

Actions of this element:

Member Description
GetColumns() Column headers
GetRows() Rows — an array of arrays of text
RowCount Number of rows
Selected Zero-based number of the selected row; -1 — none
SelectedRow Cells of the selected row; null — none
Cell(row, column) Cell text; the column is a number or a header
Select(number) Select a row by zero-based number; -1 — clear the selection
Refresh() Query the data again

Mouse, hover, focus and keyboard — as for any element (see Events and functions). Its own events:

  • Row selected (SelectionChanged) — The operator selected another row, alarm or tab; the selection is in Item.Selected.

The selected order number into a tag for a recipe or a report: the “Row selected” event.

var row = Item.SelectedRow;
if (row) Tags("Order.Id").Write(Number(row[0]));

A cell by column header.

var t = Screen.Items("Orders");
if (t.Selected >= 0) HMI.ShowMessage("Product: " + t.Cell(t.Selected, "Product"));

Refresh after a write — an “Accept order” button calls a server function and reloads the table.

var t = Screen.Items("Orders");
if (!t.SelectedRow) return;
HMI.RunServerScript("AcceptOrder", t.SelectedRow[0]);
t.Refresh(); // runs after the server function