dataview Component
Use the dataview component to render structured data and data-driven user interfaces.
{
"type": "dataview",
"cell": {
"root": {
"id": "foodname",
"type": "label"
}
},
"data": {
"type": "basic",
"src": [
{ "foodname.text": "Banana" },
{ "foodname.text": "Apple" }
]
}
}
Properties
- cols
- INTEGER
- Default:
1, Range:1-16
The number of columns in this data view. When set greater than 1, data is laid out row by row like a grid view.
- padding
- INTEGER
- Default:
0, Range:0-64
Inset the content around the perimeter of the dataview by the padding amount.
- autoadjustcontentinsets
- BOOL
- Default:
true
Automatically adjusts the scroll view's internal content insets property to account for any overlapping title bar.
Useful if you are using external Alfred UIs with transparent title bar and full size content views.
- cell
- OBJECT
Each entry of your data is fed into a UI cell to present that data.
Cells are automatically cached and reused for extreme performance.
- root
- OBJECT
The view configuration used for each cell.
This is essentially the data rendering UI which each entry of data will be fed into.
- behaviour
- OBJECT
Tweak the behaviour of the data view.
- selection
- OBJECT
Tweak the selection behaviour of the data view.
- wrap
- ENUM
- Default:
"none"
Selection wrapping.
| Value | Description |
|---|---|
"none" |
No selection wrapping. |
"vertical" |
The selection will wrap back to the start. |
- data
- OBJECT
- Required
The configuration for the data provider of this dataview.
- type
- ENUM
- Default: "basic"
The type of the data provider.
| Value | Description |
|---|---|
"basic" |
Basic data provider in JSON format. |
- select
- STRING
A data uid to select. If you're using the reselection options within modifydata, setting select will override this.
If you pass an empty string or an invalid uid, this will be treated as a reset selection (0 or deselect based on behaviour.allowemptyselection).
Also see Shared Properties.
Functions
Perform actions directly on this dataview using the functions Action.
Example Workflows
A simple list of items
{
"type": "dataview",
"cell": {
"root": {
"type": "view",
"layout": "inline",
"direction": "vertical",
"components": [
{
"id": "foodname",
"type": "label"
},
{
"id": "foodtype",
"type": "label",
"colour": "secondaryLabelColor"
}
]
}
},
"data": {
"type": "basic",
"src": [
{
"foodname.text": "Banana",
"foodtype.text": "Fruit"
},
{
"foodname.text": "Apple",
"foodtype.text": "Fruit"
},
{
"foodname.text": "Carrot",
"foodtype.text": "Vegetable"
}
]
}
}
Simple list of items with a selection filter
{
"constraints": {
"position": "centre"
},
"type": "view",
"layout": "border",
"components": [
{
"constraints": {
"region": "top"
},
"id": "searchfield",
"type": "textfield",
"events": [
{
"triggers": "changed",
"action": {
"type": "function",
"src": "foodlist",
"args": "filterdata"
}
}
]
},
{
"constraints": {
"region": "centre"
},
"id": "foodlist",
"type": "dataview",
"cell": {
"init": {
"foodcell.background": null
},
"selected": {
"foodcell.background": "systemPurpleColor"
},
"root": {
"id": "foodcell",
"type": "view",
"layout": "inline",
"direction": "vertical",
"padding": 8,
"components": [
{
"id": "foodname",
"type": "label"
},
{
"id": "foodtype",
"type": "label",
"colour": "secondaryLabelColor"
}
]
}
},
"data": {
"type": "basic",
"filter": {
"type": "basic",
"args": [
"foodname.text",
"foodtype.text"
],
"match": "{value:searchfield.text}"
},
"src": [
{
"foodname.text": "Banana",
"foodtype.text": "Fruit"
},
{
"foodname.text": "Apple",
"foodtype.text": "Fruit"
},
{
"foodname.text": "Carrot",
"foodtype.text": "Vegetable"
}
]
}
}
]
}