ui:listCollection
View as MarkdownTurns a list of items into the collection that Select and Combobox take as collection. The client rebuilds it as a Zag.js ListCollection.
<ui:listCollection
items="{
0: {value: 'de', label: 'Germany'},
1: {value: 'fr', label: 'France'},
2: {value: 'ch', label: 'Switzerland', disabled: true}
}"
as="countries"
/>
<ui:select.root collection="{countries}">...</ui:select.root>
Group the items
Permalink to heading "Group the items"Name the key that holds the group with groupByKey:
<ui:listCollection
items="{
0: {value: 'de', label: 'Germany', region: 'Europe'},
1: {value: 'fr', label: 'France', region: 'Europe'},
2: {value: 'us', label: 'United States', region: 'North America'},
3: {value: 'ca', label: 'Canada', region: 'North America'}
}"
as="countries"
groupByKey="region"
/>
groupSort takes asc, desc or a list of group keys in the order you want.
Use other item keys
Permalink to heading "Use other item keys"An item is an array or an object with a value, a label and optionally disabled. When your items use other keys, name them with itemToValueKey, itemToStringKey and isItemDisabledKey. A key can be a dot path such as country.isoCode.
Only the value, label, disabled flag and group of an item reach the page. Every other key, like the columns of a database record, stays on the server, so a template can still read it from item.original.
Arguments
Permalink to heading "Arguments"| Name | Type | Description | Required | Default |
|---|---|---|---|---|
as |
string | Variable name to assign the result to | No | '' |
items |
array | The items of the collection. {value: string, label: string, disabled: boolean}. |
No | [] |
itemToValueKey |
string | The key to use for the item value. | No | - |
itemToStringKey |
string | The key to use for the item label. | No | - |
isItemDisabledKey |
string | The key to use for the item disabled state. | No | - |
groupByKey |
string | The key to use for grouping items. | No | - |
groupSort |
array|string | Sorting for groups. | No | - |