Skip to main content

Table component

A Table component is used to load tabular data from a data source as well as filtering and modifying that data.
This data is organized in a table of records. A record corresponds to one row of the data source and consists of multiple columns, where each column can be a number, text or other value. A table is a grouping of records and provides functions to access a specific record.

You can use a table to:

  • fill a ComboBox or DataView control, to allow users to see and choose one record
  • access individual records and use its values in your product logic

Properties

A Table component has 2 properties: Query and Value.

  • The Query property is where you write a query to load data from a data source.
  • The Value property holds the resulting table. It's used automatically when you refer to the table component in other rules, you typically don't need to access it directly.

Using a table component

A typical use case is to select a particular record from a table; this could e.g. be the record that a user selected in a ComboBox or DataView control.

Let's assume we have a table component with the name parts and that it has 3 columns partNumber, name and price.
To select one part from this table, create a value component with the name part and enter this code:

parts.Get(Input or 0) or parts.GetFirst()

You also have to change the Input type of the value component to Number.
When you now type a part number into the Input field of your value component, you should see a part record in the result panel. Try typing different part numbers into the Input field to view different parts!

This value component can now be connected to UI controls to hold a part selected from the parts table.
Let's break down what the code above does:

  1. We try to look up a part with a particular number with parts.Get(…)
  2. As part number, we want to use Input, which can be connected to a UI control to automatically update
    • To prevent errors, we supply a default value for the Input with Input or 0.
    • Instead of 0 you could use the number of a part you want to be selected by default.
  3. In case the Input contains a part number that cannot be found in the table, we use the first record of the table as fallback
    • We get the first record of the table with parts.GetFirst()
    • Now our component will always select a part record, no matter what we type into the Input box!

Queries

To load data from a data source, we can use a so-called query in our Hive code, written into the Query property.
Let's assume our data source is called BikeParts, then the simplest query we could write is:

from BikeParts select all

This will load all records from the data source and include all its columns.

Queries support filtering, sorting, limiting and reshaping (projecting) the data they load – see the Hive Queries page for the full syntax and examples.