Can I calculate different sets of displays depending on the row or values in other fields?
Yes!
For example, if depending on the parameter you need to take displays from different tables:
=: if(condition: #condition_field = 1; then: $s1; else: $s2)
s1: selectRowListForSelect(table: 'table_1'; field: 'name')
s2: selectRowListForSelect(table: 'table_2'; field: 'name')
Or a different set of values:
=: selectRowListForSelect(table: 'table'; field: 'name'; where: 'type' = #condition_field)
For this to work, you need to enable the individual calculation of the select for each row parameter.
By default, it is turned off, which means that by default the select is calculated only for the first row.
When the parameter is enabled, the select will be recalculated for each row.
This same parameter updates dependent selects in the header/footer/prefilter.
Therefore, if you have an if
in the select code or a where
that depends on a field in the table, enable the individual calculation of the select for each row.
How does the enabled Individual Select Calculation for each row effect the load?
Significantly increases server load! Very significantly!
Use only when necessary!
Is the individual select calculation used only in the rows part?
Not only that. For example, you have a select with statuses in the header, but there are restrictions on which status the user can switch to depending on the current one:
=: if(condition: $#nfv = 1; then: $v1; else: $if2)
if2: if(condition: $#nfv = 2; then: $v2; else: $if3)
if3: if(condition: $#nfv = 3; then: $v3)
// There is a more elegant way of branching, but more on that later :)
v1: selectRowListForSelect(table: 'table'; field: 'name'; where: 'id' = json`[1,2]`)
v2: selectRowListForSelect(table: 'table'; field: 'name'; where: 'id' = json`[2,3]`)
v3: selectRowListForSelect(table: 'table'; field: 'name'; where: 'id' = json`[3]`)
// from 1 only to 2
// from 2 only to 3
// from 3 to nowhere
Since if
takes the value of the current field, we need the select to be recalculated when the user selects, for example, 2 — for this, it is necessary to enable individual calculation of the select for each row.
Can the code add one value to the automatically generated select?
Yes. The select can be manually formed according to a specific template:
[
{"value": 0, "is_del": false, "title":"Display 1"},
{"value": 1, "is_del": false, "title":"Display 1"},
{"value": 2, "is_del": false, "title":"Display 1"}
]
This is the exact structure created by selectRowListForSelect.
It is a list of rows. Therefore, to add a special value to it, we need to create a row in this format and add it to the automatically generated selectRowListForSelect list of rows:
=: listAdd(list: $sel; item: $spec)
sel: selectRowListForSelect(table: 'table'; field: 'name')
spec: rowCreate(field: "value" = "spec"; field: "is_del" = false; field: "title" = "Special Display")
// is_del — a special mark that can be used to mark a hidden row. This will be covered in subsequent lessons. For now, set it to false.