Show view
| Option | type | default | description |
|---|---|---|---|
| fields | (string|FieldConfig)[] | see below | what fields to show in the view and how they should be rendered |
| assocFrom | (string|UiAssocFromConfig)[] | all assoFrom relations | what assocFrom to include and how to render on the show view |
| comments | boolean | true | whether to include a section for showing / adding comments for the entity on the show view |
Fields
Per default the show view contains (beside the assocFrom tables)
- all attributes of the entity except id, createdAt, updatedAt
- all
assocToitems - all
assocToManyitems
in unreliable order - although usually in the order of the definition of the attributes in the domain configuration.
You can state which field and which order should be rendered by giving an array of either the field or assoc names (with default behavior) or FieldConfig objects which allows you to control nearly every aspect of rendering.
adminConfig:AdminConfig = {
entities: {
Car: {
show: {
fields: ['Driver', 'license', 'color', 'mileage']
}
}
}
}FieldConfig
| Option | type | default | description |
|---|---|---|---|
| name | string | the name of the attribute or entity of the assoc or assocToMany | |
| type | string | the type from the domain configuration | the type of the attribute or entity of the assoc |
| label | string | ()=>string | lookup in resources or humanized field name | the label for the field |
| list | boolean | dependent from the attribute / assoc type in the domainConfiguration | the column label for the field |
| render | Function | uses renderValue / renderList | returns the string-value that should be displayed in the index table |
| renderValue | Function | type aware content (as link if assoc) | returns the string-value of exactly one value (e.g. from array values) that should be displayed in the view |
| renderList | Function | comma-separated values | if more than one value, gets the (rendered) values and returns the (combined) string-value that should be displayed in the view |
| value | any | item[field] | gets the value (as is) from the item |
| query | string | attribute or indication for assoc | part of the query of the view to add for this field's value |
Label
If you do not provide a label, the default label will be looked up under this path in the resources of the AdminConfig.
['resources', locale, 'entities', entity, 'label', field]If no such entry exists, the humanized attribute name of the entity or the humanized name of the assoc entity will be used.
Render
Let's say you want to render the color attribute in the respective color itself. A (admittedly trivial) implementation could be:
adminConfig:AdminConfig = {
entities: {
Car: {
show: {
fields: [
'license',
{ name: 'color', render: (item:any) => `<span style="color: ${item.color}">${item.color}</span>` },
'mileage',
'Driver'
]
}
}
}
}assocFrom
Per default the show view will render every assocFrom as a child-table with the same fields as on the index view of the associated entity.
You can define which assocFrom tables, in which order and with which fields to render by providing this configuration.
| Option | type | default | description |
|---|---|---|---|
| entity | string | the entity of the assocFrom relationship | |
| fields | (string|FieldConfig)[] | see fields for index | what fields to show in the table and how they should be rendered |
| query | QueryFn | default query for the index action of the assocFrom relationship | custom query |
| search | boolean | true if > 10 items | whether to offer client side search of the table |
| order | OrderType | 1st column asc | which column should be sorted initially |
| filter | FilterType | filter for the table - same as in index view but performed on the client | |
| entity | string | the entity of the assocFrom relationship | |
| showAdd | boolean | true | whether offering the creation of a new child record for this assocFrom relationship |
Example
Given the following domain configuration:
entity:
Car:
assocFrom:
- Driver
- Accessory
attributes:
license: Key
color: string
Driver:
assocTo: Car
attributes:
name: string
licenseValidTill: Date
Accessory:
assocTo: Car
attributes:
name: Key
available: boolean!A show view configuration like this
adminConfig:AdminConfig = {
entities: {
Car: {
show: {
assocFrom: [
'Driver',
{
entity: 'Accessory',
fields: [
'name',
{ name: 'available', render: (item:any) => item['available'] ? '🙂' : '🙁' }
],
search: false
}
]
}
}
}
}would
- render all attributes of Car
- the
assocFromtables forDriverandAccessoryin this order - the
Drivertable same as forindexaction for this entity - the
Accessorytable with the fieldsnameandavailablein that order - the field
availableof theAccessorytable with emojis instead oftrue/false - regardless of the number of items in the
Accessorytable, there will be no search offered