Question
To ensure that all selected rows are printed, you need to modify the code to iterate over each selected row and collect the necessary data. Here's a possible approach:
linkToPrint
function.Here's an example of how you might adjust the code:
=: linkToPrint(template: "Reestr_sertif"; data: $rowsData)
rowsData: rowsCollect(field: "reestr" = $example)
example: select(table: 'certificate_iss_tracking'; field: 'serial_numbers'; where: 'id' IN $ids)
ids: var(name: "selectedIds"; value: $#ids)
In this example, rowsCollect
is a hypothetical function that collects data from all selected rows. The select
function is modified to use IN $ids
to select all rows with IDs in the $ids
list. Make sure to replace rowsCollect
with the actual function or method you use to collect data from multiple rows in your system.
Answer
Totum strictly separates single values and multiple values — which are lists or list.
Accordingly, functions have two variants — single (for example, select) and multiple (selectList).
In the code you provided in the example
line, the single variant (select
) is used, so one value with the smallest id
is taken (if order
is not specified, it is not necessarily so — this is determined by postgres
internally).
I will modify the code to multiple:
=: linkToPrint(template: "Reestr_sertif"; data: $row)
row: rowCreate(field: "reestr" = $example)
example: selectList(table: 'certificate_iss_tracking'; field: 'serial_numbers'; where: 'id' = $#ids)
I also removed var
and specified where: 'id' = $#ids
— because an additional line of code is not needed here.
By doing this, you will encounter an error! because they are list
, and the print template expects text
.
Let's add the conversion list
—> text
using the function listJoin:
=: linkToPrint(template: "Reestr_sertif"; data: $row)
row: rowCreate(field: "reestr" = $example)
example: listJoin(list: $list; str: "<br>")
list: selectList(table: 'certificate_iss_tracking'; field: 'serial_numbers'; where: 'id' = $#ids)
We use <br>
as a separator, not the quick variable $#nl
(which is short for new line
) because html
does not understand these line separators.
Now it should work fine, but there will be an error when no checkboxes are selected. Let's add a check for the presence of checkboxes at the beginning. The variable $#ids
is a list, so we need to compare it with an empty list
— $#lc
:
=: if(condition: $#ids != $#lc; then: $print; else: $err)
err: linkToDataText(title: "Print Warning"; text: "Select at least one item")
print: linkToPrint(template: "Reestr_sertif"; data: $row)
row: rowCreate(field: "reestr" = $example)
example: listJoin(list: $list; str: "<br>")
list: selectList(table: 'certificate_iss_tracking'; field: 'serial_numbers'; where: 'id' = $#ids)
This is usually how it is used in our projects.