Question
There is a table that collects income and expenses for a period.
In implementation, this is a temporary table, first the list is collected in h_header_input
.
I want adjacent days to have different colors. But there are a couple of caveats:
Days may not be in order, so the idea of using even numbers is not suitable, as it could be the 1st, 3rd, 5th day.
There may be many payments in one day, and they all should be the same color, so that the days of the month alternate, not the rows.
I did something like this in google script
. But there it is done in a loop, where a variable is alternately reset to true/false
when the next day in the loop occurs.
I can't figure out how to do this in Totume, but with such a feature, it's much more convenient to work, and the information is easier to read.
Answer
This can be done through string formatting code and process variables. A process variable is needed to calculate the entire list of colored strings once. Which string will be colored and which will not is determined using listReplace and an additional variable inside the code, set to the opposite position for each subsequent list element.
String formatting code:
f1=: setRowFormat(condition: $list = #date; background: "whitesmoke")
list: if(condition: $@color != $#lc; then: $@color; else: $color)
color: procVar(name: "color"; value: $filter[[date]])
filter: listFilter(list: $replace; key: "color" = true)
replace: listReplace(list: $rawlist; action: "color" = $checkbox)
rawlist: rowListCreate(field: "date" = $uniq)
uniq: listUniq(list: $datelist)
datelist: selectList(table: $#ntn; field: 'date'; where: 'id' = $#rows; order: 'id' asc)
checkbox: if(condition: $varcheck = false; then: false; else: true)
varcheck: if(condition: $check = true; then: $setfalse; else: $settrue)
check: var(name: "check"; default: true)
setfalse: var(name: "check"; value: false)
settrue: var(name: "check"; value: true)
The quick variable $#rows
is available in table formatting code and string formatting code and contains information about the id of the rows displayed on the page.