The cross data model includes one or more fields that will be expanded into either a
horizontal array of items (CrossArray type) or into a keyed
object (CrossObject type).
Such models are most often used to build cross-sectional reports, in which the number of columns is variable and is determined by the received data. This is similar to the sql pivot statement, but, unlike it, you do not need to know in advance which columns will be included in the result set.
Note that it doesn't make sense (though not forbidden) to use cross-models
for objects (not arrays). Just use MapObject instead.
For cross arrays, the differences from simple nested arrays are the following:
Key) of the cross item.For cross objects, the logic is as follows:
The easiest way to understand how cross models work is with an example.
Let there be a fragment of SQL code:
And it returns the following data:
| RepData!TData!Array | Id!!Id | S1 | N1 | Cross1!TCross!CrossArray |
|---|---|---|---|---|
| null | 10 | Str1 | 100 | null |
| null | 20 | Str2 | 200 | null |
| !TCross!CrossArray | Key!!Key | Val | !TData.Cross1!ParentId |
|---|---|---|---|
| null | K1 | 111 | 10 |
| null | K2 | 222 | 20 |
When the first set is being processed, a simple array
of the RepData items of the TData type will be created.
Each item of this array will contain the Cross1 field,
which will later become a cross array of items of the TCross type.
Please note that the main items must contain an
identifier (a field with the !Id type),
so that the next data sets can refer to the array item.
The second set is processed as follows. First, the field of reference
to the cross field of the main item of the array is searched
(a field with the !ParentId type).
The link type indicates the type name and the field name separated by a dot.
!TData.Cross1!ParentId - the Cross1 field in
the TData type item.
The content of the cross-record is stored in the internal
buffer of the found master record.
Please note that the cross array must contain a test field of the
!Key type.
It is used for internal processing.
It is this field that will be contained in the array returned
by the $cross property.
This property will be added to the array itself (not an item!) of TData objects.
A reference to the list of keys will look like RepArray.$Cross.Cross1.
After processing all cross-set records, the system finds
the concatenation of all possible keys in all TData records and
converts the internal buffers to arrays. As a result,
all cross arrays will have the same length.
The resulting model will look as follows:
The cross models are most often used to build reports in conjunction with Sheettables. To make the example more realistic, let's add the output of the totals. The SheetCellGroup element is used to display cross arrays.
Template
XAML:
Result:
| Id | S1 | N1 | Cross1 | ||
|---|---|---|---|---|---|
| K1 | K2 | Total | |||
| Total | 111 | 222 | 333 | ||
| 10 | Str1 | 100 | 111 | 111 | |
| 20 | Str2 | 200 | 222 | 222 | |