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

placeholder
STRING

Set the text placeholder to show when there is no data.

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.

spacing
INTEGER
Default: 0, Range: 0-64

The spacing between each cell.

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.

height
INTEGER
Default: 64, Range: 12-1024

The height of each rendered cell.

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.

init
OBJECT

As cells are reused for performance reasons, data needs to be set to an initialised state before the entry is set on the cell.

Use this object to initialse a cell with a base set of data.

selected
OBJECT

Additional data to be applied to the selected index, i.e. for styling.

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.
allowempty
BOOL
Default: false

Allow the table to have no cell selected. The changed event will pass null as the selected item if there is no selected cell.

hover
BOOL
Default: false

Change the selection when the mouse hovers over a cell. This will fire a changed event, so use with caution if the changed event runs a script.

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.

filterdata

Make the DataView re-filter the data based on the configured filter.

scrolltop

Scroll to the top of the data view.

scrollbottom

Scroll to the top of the data view.

selectfirst

Select the first item in the data view.

selectlast

Select the last item in the data view.

selectprevious

Select the previous item in the data view, will wrap to previous row.

selectnext

Select the first next in the data view, will wrap to next rwo.

selectup

Select up in the data view.

selectdown

Select down in the data view.

selectleft

Select left in the data view.

selectright

Select right in the data view.

selectnone

Deselect the table in the data view.

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"
          }
        ]
      }
    }
  ]
}