Forcing one or more rows on an otherwise empty grid
When you have an empty grid in your model, upon which your end users can add (or remove) rows, it can sometimes be useful to automatically generate one or more rows. In this tutorial, you will learn how to force just that.
Visual example of the issue
Basically, in the model you have to force iteration(s) of the grid using empty value(s). That way the grid will first show with empty row(s), instead of nothing. You should also check whether the grid has already had input added or not before forcing iterations.
For the sake of example, I have declared ‘gridvar’ in my node
dataset gridvar: grid;
which is a reference to the ‘grid’ graph.
graph grid; begin node start; var data1, data2, data3; begin data1 := ''; data2 := ''; data3 := ''; end; end;
In the node containing
gridvar, we need to first
evaluate the content of this grid as it is at the moment
the end user arrives there - since we have no way of knowing
whether they have arrived at this node for the first time
or are simply returning, having already filled data into
To do this, we will add a function in the action of that node:
gridvar := editedvalue(^gridvar)
Now we can perform a simple check on the
gridvar to see
if there has been any input from the end user, just by
count() function as a conditional test.
Based on the outcome of this test, we can logically decide whether or not to add empty rows.
Here’s how we achieve that:
As you can see, if the
count(gridvar) returns anything
more than ‘0’, we know the end user has already filled in
some data, so we do nothing. If however the return is ‘0’,
we can safely assume the end user has not yet filled in
any data, and we can therefore add the desired number of
empty rows by forcing that number of iterations on the grid.
In the example above, we only iterate once, with:
gridvar.start.data1 := '';
If you wanted three empty rows, you could do this:
gridvar.start.data1 := ''; gridvar.start.data1 := ''; gridvar.start.data1 := '';
gridvar is the reference to the grid graph.
[0|1|2] is the iteration number, always zero-indexed (beginning at 0).
.start is the grid graph’s node which contains the data, or in this
case the blank references to the usable variables for the grid.
.data1 is one of the usable variables, as defined in the node:
:= ''; assigns an empty string to the
data1 for this iteration.
The fact that we used
data1 in this case is at random. You could use any
available variable in the grid graph’s start node. The rest of the fields
called in the grid will be also be empty.
In the end, your actions in that node should look like this: