Data Gridv5
Data Grid (component 81) shows the records of a chosen target form as a table inside the form it is placed on, and lets users edit them in the cells. Each row is a record in the target form's table (UserTableID); added, changed and deleted rows are written straight to the target form. Unlike the classic Grid, the rows are not details of the main record but records of an independent form.
Data Grids on the same form can be linked: when a row is selected in the parent grid, the child grid shows only the records that belong to that row (e.g. Countries, Cities, Districts).
In the toolbox
Data Grid in the Data & Layout group.
Compatibility
| Free Form | Responsive Form | Flexible Form | Mobile |
|---|---|---|---|
| ✓ | ✓ | ✓ | — |
Properties
| Property | Description |
|---|---|
| Module / Edit Form | The target module and form the rows belong to. Columns come from this form's fields. |
| Record Loading Query (SQL Query) | Decides which records appear in the grid. Form fields can be used as $PFieldName; for example, to show only the open customer's records: WHERE CustomerCode = '$PCustomerCode'. |
| Columns | Which fields of the target form are shown, column type, default value and drop-down source. For drop-down columns the displayed text is kept separately. |
| Fit horizontal | Stretches the grid to the form width. |
| Parent Data Grid | New. The parent Data Grid this grid is linked to. The list shows the other Data Grids on the same form. Leave empty for an independent grid. |
| Master Field | New. The column of the selected parent row that is used as the link value. The list shows the parent grid's columns; if empty, UserTableID is used. |
| Link Field | New. The field in this grid's target form that holds the parent row's value (e.g. CountryID in the Cities form). |
Note: UserTableID, CreateDate, CreateUser, UpdateDate and UpdateUser are system columns and cannot be edited. The target form's field permissions (Read-only / Hidden) also apply in the grid.
Linked Data Grids
A linked grid is filtered by the row selected in its parent grid. Example: a form with three Data Grids.
| Data Grid | Edit Form | Parent Data Grid | Master Field | Link Field |
|---|---|---|---|---|
dgCountries | Countries | (empty) | (empty) | (empty) |
dgCities | Cities | dgCountries | UserTableID | CountryID |
dgDistricts | Districts | dgCities | UserTableID | CityID |
With these settings:
- The Cities grid shows only the records whose
CountryIDequals theUserTableIDof the row selected in the Countries grid. - When another row is selected in Countries, Cities is read again, and Districts is cleared or refreshed for the new selection. The chain can be as deep as needed.
- If no row is selected in the parent grid, or the selected row is not saved yet, the child grid stays empty and no row can be added.
- The Link Field of a new row in the child grid is filled automatically; the column does not have to be shown or entered.
- On a saved row the Link Field cannot be changed; a row cannot be moved to another parent record.
- On update and delete, the server checks again that the row belongs to the selected parent row.
With a Record Loading Query: If the child grid also has a query, the query runs as it is and its result is additionally filtered by the Link Field. So the Link Field must be one of the query's result columns (e.g. SELECT UserTableID, CityName, CountryID FROM ...). A trailing ORDER BY is kept.
Another column as Master Field: The link can use a code field instead of the record number, e.g. Master Field = CountryCode, Link Field = CountryCode. The value is always read on the server from the parent grid's target table.
Permissions
Adding, updating and deleting from a Data Grid is checked against the target form's permission definitions, as if the user opened the target form itself:
| Action | Required permission (target form) |
|---|---|
| Add a row | New record |
| Change a cell | Update record |
| Delete a row | Delete record |
Without the permission the action is not performed and a "you are not authorized" message is shown. The target project and form are read from the Data Grid's settings in Studio, not from the browser.
Using it in Client
- Add a row, click a cell to change its value or delete a row; the change is written to the target form's record.
- Checkbox columns toggle with a single click. On a saved row the change is saved at once; on a new row it is saved with the other fields when the row is completed.
- Required and minimum / maximum value rules now apply to saved rows as well as new ones; an invalid value is not saved.
- If the query depends on a form field, use the Update Value action to refresh the grid when the field changes.
- With linked grids, first select the row in the parent grid; the child grid refreshes by itself.
Common issues
| Symptom | Cause / fix |
|---|---|
| Child grid is always empty | No row is selected in the parent grid, or the selected row is new (unsaved). Save and select the row. If a query is used, check that the Link Field is in its result. |
| Cannot add a row to the child grid | No parent row is selected; a linked grid does not open a new row without one. |
| "You are not authorized" | The user lacks the permission (new / update / delete) on the target form. |
| Value on a saved row is not saved | The field is required or outside the min / max rule; correct the value. |