A2v10 Platform documentation
UK


Working with arrays

An array can be either an independent item of the model (then it has a name and it will be displayed in the root of the model), or a child item of some other object.

An array is defined by the Array type (or LazyArray for "lazy" array) in the descriptor (the first field) of the dataset.

Note! The arrays with too many items should not be used. In addition to the fact that this leads to a drop in performance, it is also very inconvenient for the end user to work with. Use server-side sorting, filtering, and paging to work with large arrays (tables). Подробнее....

The recommended size of the array on the client is no more than 100 items. The maximum, which does not lead to a noticeable decrease in performance, is about 200 items.

Regular arrays

It's simply a recordset. Each row in the set will be a corresponding object of array. The type of the object is determined by the set descriptor.

Example

Let there be a fragment of SQL code:


It will form the Agents. array at the root of the model. Each item of the array will be of TAgent type with the following properties: Id, Name, Code.

Child arrays

A child array is always nested and is a property of another object. Usually has no name. The parent must have a null placeholder property with the item type of the child array. Please note that the child set must be processed after the basic one.

In order to associate an array with a parent object, the recordset must contain a field with a link to the parent object in the form [Name!ParentType.PropertyName!ParentId], where

  • [Name] - the optional field name. May be empty.
  • ParentType.PropertyName - the type name and the property name of the parent object where the array item will be recorded.
  • ParentId - the field modifier.

Binding works as follows:

  1. The value of the !ParentId field is taken.
  2. The object of the ParentType type with the corresponding identifier is searched for in the model (it goes without saying that this identifier should be marked with the !Id modifier).
  3. The field with the PropertyName name is searched for in the found object. The item is added to the array corresponding to this field.

Example

Let there be a fragment of SQL code:

		
It will form the Document object of the TDocument ype at the root with the following properties: Id, Date, Rows. The Rows property will be the items array of the TRow type with the following properties: Id, Qty, Price, Sum.

"Lazy" arrays

Lazy (on demand) arrays are not added to the model in the process, but are loaded the first time the property is accessed. Most often, this mechanism is used when the basic model is an array, and the child arrays are not always needed, but only on the attempt to display them. A typical example is a list of contractors, each of which contains the documents associated with it.

Lazy arrays can only be children and are defined by the LazyArray modifier.

It should be noted that the structure of the child object (not data!) must be known to the system at the initial building of the model. Therefore, when using "lazy" arrays, it is necessary to return an empty recordset, which will define the correct data structure of the array. The array will be filled with real data during the loading process.

To load the lazy array, the model load stored procedure will be called with a suffix corresponding to the property name of the main model. The ID of the main item will be passed to it as the @Id parameter. It should return a set that corresponds to the description of the array in the main model. The property with the !ParentId modifier is optional.

Example

Let there be a list of the contractors with a list of documents.

		
It will form the Document object of the TDocument ype at the root with the following properties: Id, Date, Rows. The Rows type will be the items array of the TRow with the following properties: Id, Qty, Price, Sum.

Lazy array loading procedures can also take parameters and use pagination.

Please note! It is possible to update (reload from the database) only the contents of the lazy array without the basic model. To do this, simply pass the array as an argument to the Refresh (Reload) command or to the controller's $reload method.