2019-03-25 12:21:45 +00:00
|
|
|
<template>
|
2021-03-18 10:41:31 +00:00
|
|
|
<AppDoc name="ListboxDemo" :sources="sources">
|
|
|
|
<h5>Import</h5>
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code.script><code>
|
2019-03-25 12:21:45 +00:00
|
|
|
import Listbox from 'primevue/listbox';
|
2020-09-24 11:14:55 +00:00
|
|
|
|
|
|
|
</code></pre>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Getting Started</h5>
|
|
|
|
<p>Listbox requires a value to bind and a collection of arbitrary objects along with the <i>optionLabel</i> property to specify the label property of the option.</p>
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code><code>
|
2019-05-22 16:30:18 +00:00
|
|
|
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" />
|
2019-05-22 15:20:03 +00:00
|
|
|
|
2020-09-24 11:14:55 +00:00
|
|
|
</code></pre>
|
|
|
|
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code.script><code>
|
2019-03-25 12:21:45 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedCity: null,
|
|
|
|
cities: [
|
|
|
|
{name: 'New York', code: 'NY'},
|
|
|
|
{name: 'Rome', code: 'RM'},
|
|
|
|
{name: 'London', code: 'LDN'},
|
|
|
|
{name: 'Istanbul', code: 'IST'},
|
|
|
|
{name: 'Paris', code: 'PRS'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 11:14:55 +00:00
|
|
|
|
|
|
|
</code></pre>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Selection</h5>
|
|
|
|
<p>Listbox allows selection of either single or multiple items. In single case, model should be a single object reference whereas in multiple case should be an array. Multiple items can either be selected
|
|
|
|
using metaKey or toggled individually depending on the value of <i>metaKeySelection</i> property value which is true by default. On touch enabled
|
|
|
|
devices metaKeySelection is turned off automatically.</p>
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code><code>
|
2019-05-22 16:30:18 +00:00
|
|
|
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" :multiple="true"/>
|
2020-09-24 11:14:55 +00:00
|
|
|
|
2021-02-15 08:50:11 +00:00
|
|
|
</code></pre>
|
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Grouping</h5>
|
|
|
|
<p>Options groups are specified with the <i>optionGroupLabel</i> and <i>optionGroupChildren</i> properties.</p>
|
2021-02-15 08:50:11 +00:00
|
|
|
<pre v-code.script><code>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedGroupedCity: null,
|
|
|
|
groupedCities: [{
|
|
|
|
label: 'Germany', code: 'DE',
|
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'USA', code: 'US',
|
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Japan', code: 'JP',
|
|
|
|
items: [
|
|
|
|
{label: 'Kyoto', value: 'Kyoto'},
|
|
|
|
{label: 'Osaka', value: 'Osaka'},
|
|
|
|
{label: 'Tokyo', value: 'Tokyo'},
|
|
|
|
{label: 'Yokohama', value: 'Yokohama'}
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</code></pre>
|
|
|
|
|
|
|
|
<pre v-code><code><template v-pre>
|
2021-02-15 14:05:02 +00:00
|
|
|
<Listbox v-model="selectedGroupedCity" :options="groupedCities"
|
|
|
|
optionLabel="label" optionGroupLabel="label" optionGroupChildren="items">
|
|
|
|
</Listbox>
|
2021-02-15 08:50:11 +00:00
|
|
|
</template>
|
2020-09-24 11:14:55 +00:00
|
|
|
</code></pre>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Filter</h5>
|
|
|
|
<p>Filtering allows searching items in the list using an input field at the header. In order to use filtering, enable <i>filter</i> property. By default,
|
|
|
|
optionLabel is used when searching and <i>filterFields</i> can be used to customize the fields being utilized. Furthermore, <i>filterMatchMode</i> is available
|
|
|
|
to define the search algorithm. Valid values are "contains" (default), "startsWith" and "endsWith".</p>
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code><code>
|
2019-05-22 16:30:18 +00:00
|
|
|
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" :filter="true"/>
|
2020-09-24 11:14:55 +00:00
|
|
|
|
2021-02-15 14:05:02 +00:00
|
|
|
</code></pre>
|
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Templating</h5>
|
|
|
|
<p>Label of an option is used as the display text of an item by default, for custom content support define an <i>option</i> template that gets the option instance as a parameter.
|
|
|
|
In addition <i>optiongroup</i>, <i>header</i>, <i>footer</i>, <i>emptyfilter</i> and <i>empty</i> slots are provided for further customization.</p>
|
2021-02-15 14:05:02 +00:00
|
|
|
<pre v-code><code><template v-pre>
|
|
|
|
<Listbox v-model="selectedCars" :options="cars" :multiple="true" :filter="true" optionLabel="brand" listStyle="max-height:250px" style="width:15em">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div>
|
|
|
|
<img :alt="slotProps.option.brand" :src="'demo/images/car/' + slotProps.option.brand + '.png'" />
|
|
|
|
<span>{{slotProps.option.brand}}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Listbox>
|
|
|
|
</template>
|
2020-09-24 11:14:55 +00:00
|
|
|
</code></pre>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Properties</h5>
|
|
|
|
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Type</th>
|
|
|
|
<th>Default</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>modelValue</td>
|
|
|
|
<td>any</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Value of the component.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>options</td>
|
|
|
|
<td>array</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>An array of selectitems to display as the available options.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionLabel</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the label of an option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionValue</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the value of an option, defaults to the option itself when not defined.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionDisabled</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionGroupLabel</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the label of an option group.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionGroupChildren</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function that refers to the children options of option group.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>listStyle</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Inline style of inner list element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>disabled</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>When specified, disables the component.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>dataKey</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>A property to uniquely identify an option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>multiple</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>When specified, allows selecting multiple values.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>metaKeySelection</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>true</td>
|
|
|
|
<td>Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item
|
|
|
|
can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filter</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>When specified, displays a filter input at header.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filterPlaceholder</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Placeholder text to show when filter input is empty.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filterLocale</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>undefined</td>
|
|
|
|
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filterMatchMode</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>contains</td>
|
|
|
|
<td>Defines the filtering algorithm to use when searching the options. Valid values are "contains" (default), "startsWith" and "endsWith"</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filterFields</td>
|
|
|
|
<td>array</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Fields used when filtering the options, defaults to optionLabel.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>emptyFilterMessage</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>No results found</td>
|
|
|
|
<td>Text to display when filtering does not return any results. Defaults to value from PrimeVue locale configuration.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>emptyMessage</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>No results found</td>
|
|
|
|
<td>Text to display when there are no options available. Defaults to value from PrimeVue locale configuration.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Events</h5>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Parameters</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>change</td>
|
|
|
|
<td>event.originalEvent: Original event <br />
|
|
|
|
event.value: Selected option value </td>
|
|
|
|
<td>Callback to invoke on value change.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>filter</td>
|
|
|
|
<td>event.originalEvent: Original event <br />
|
|
|
|
event.value: Filter value </td>
|
|
|
|
<td>Callback to invoke on filter input.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Slots</h5>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Parameters</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>option</td>
|
|
|
|
<td>option: Option instance <br />
|
|
|
|
index: Index of the option</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optiongroup</td>
|
|
|
|
<td>option: OptionGroup instance <br />
|
|
|
|
index: Index of the option group</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>header</td>
|
|
|
|
<td>value: Value of the component <br />
|
|
|
|
options: Displayed options</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>footer</td>
|
|
|
|
<td>value: Value of the component <br />
|
|
|
|
options: Displayed options</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>emptyfilter</td>
|
|
|
|
<td>-</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>empty</td>
|
|
|
|
<td>-</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2021-02-15 08:50:11 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Styling</h5>
|
|
|
|
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Element</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>p-listbox</td>
|
|
|
|
<td>Main container element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-listbox-header</td>
|
|
|
|
<td>Header element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-listbox-list-wrapper</td>
|
|
|
|
<td>Container of list element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-listbox-list</td>
|
|
|
|
<td>List element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-listbox-item</td>
|
|
|
|
<td>An item in the list element.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Dependencies</h5>
|
|
|
|
<p>None.</p>
|
|
|
|
</AppDoc>
|
|
|
|
</template>
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
sources: {
|
|
|
|
'options-api': {
|
|
|
|
tabName: 'Source',
|
|
|
|
content: `
|
|
|
|
<template>
|
2021-03-24 17:37:09 +00:00
|
|
|
<div>
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Single</h5>
|
|
|
|
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" style="width:15rem" />
|
2019-03-25 12:21:45 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Grouped</h5>
|
|
|
|
<Listbox v-model="selectedGroupedCity" :options="groupedCities" optionLabel="label" style="width:15rem" optionGroupLabel="label" optionGroupChildren="items" listStyle="max-height:250px">
|
|
|
|
<template #optiongroup="slotProps">
|
|
|
|
<div class="p-d-flex p-ai-center country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" width="18" class="p-mr-2" />
|
|
|
|
<div>{{slotProps.option.label}}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Listbox>
|
2021-02-15 08:50:11 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Advanced with Templating, Filtering and Multiple Selection</h5>
|
|
|
|
<Listbox v-model="selectedCountries" :options="countries" :multiple="true" :filter="true" optionLabel="name" listStyle="max-height:250px" style="width:15rem" filterPlaceholder="Search">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" width="18" class="p-mr-2" />
|
|
|
|
<div>{{slotProps.option.name}}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Listbox>
|
|
|
|
</div>
|
2019-03-25 12:21:45 +00:00
|
|
|
</template>
|
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<script>
|
2019-03-25 12:21:45 +00:00
|
|
|
export default {
|
2020-07-01 12:21:42 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedCity: null,
|
|
|
|
selectedCountries: null,
|
2021-02-15 08:50:11 +00:00
|
|
|
selectedGroupedCity: null,
|
2020-07-01 12:21:42 +00:00
|
|
|
cities: [
|
|
|
|
{name: 'New York', code: 'NY'},
|
|
|
|
{name: 'Rome', code: 'RM'},
|
|
|
|
{name: 'London', code: 'LDN'},
|
|
|
|
{name: 'Istanbul', code: 'IST'},
|
|
|
|
{name: 'Paris', code: 'PRS'}
|
|
|
|
],
|
|
|
|
countries: [
|
|
|
|
{name: 'Australia', code: 'AU'},
|
2020-07-01 12:33:00 +00:00
|
|
|
{name: 'Brazil', code: 'BR'},
|
2020-07-01 12:21:42 +00:00
|
|
|
{name: 'China', code: 'CN'},
|
2020-07-01 12:33:00 +00:00
|
|
|
{name: 'Egypt', code: 'EG'},
|
|
|
|
{name: 'France', code: 'FR'},
|
2020-07-01 12:21:42 +00:00
|
|
|
{name: 'Germany', code: 'DE'},
|
|
|
|
{name: 'India', code: 'IN'},
|
|
|
|
{name: 'Japan', code: 'JP'},
|
|
|
|
{name: 'Spain', code: 'ES'},
|
|
|
|
{name: 'United States', code: 'US'}
|
2021-02-15 08:50:11 +00:00
|
|
|
],
|
|
|
|
groupedCities: [{
|
|
|
|
label: 'Germany', code: 'DE',
|
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'USA', code: 'US',
|
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Japan', code: 'JP',
|
|
|
|
items: [
|
|
|
|
{label: 'Kyoto', value: 'Kyoto'},
|
|
|
|
{label: 'Osaka', value: 'Osaka'},
|
|
|
|
{label: 'Tokyo', value: 'Tokyo'},
|
|
|
|
{label: 'Yokohama', value: 'Yokohama'}
|
|
|
|
]
|
|
|
|
}]
|
2020-07-01 12:21:42 +00:00
|
|
|
}
|
2020-04-29 12:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-18 10:41:31 +00:00
|
|
|
<\\/script>
|
|
|
|
`
|
|
|
|
},
|
|
|
|
'composition-api': {
|
|
|
|
tabName: 'Composition API',
|
|
|
|
content: `
|
|
|
|
<template>
|
2021-03-24 17:37:09 +00:00
|
|
|
<div>
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Single</h5>
|
|
|
|
<Listbox v-model="selectedCity" :options="cities" optionLabel="name" style="width:15rem" />
|
2020-09-24 11:14:55 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Grouped</h5>
|
|
|
|
<Listbox v-model="selectedGroupedCity" :options="groupedCities" optionLabel="label" style="width:15rem" optionGroupLabel="label" optionGroupChildren="items" listStyle="max-height:250px">
|
|
|
|
<template #optiongroup="slotProps">
|
|
|
|
<div class="p-d-flex p-ai-center country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" width="18" class="p-mr-2" />
|
|
|
|
<div>{{slotProps.option.label}}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Listbox>
|
2021-02-15 08:50:11 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Advanced with Templating, Filtering and Multiple Selection</h5>
|
|
|
|
<Listbox v-model="selectedCountries" :options="countries" :multiple="true" :filter="true" optionLabel="name" listStyle="max-height:250px" style="width:15rem" filterPlaceholder="Search">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" width="18" class="p-mr-2" />
|
|
|
|
<div>{{slotProps.option.name}}</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Listbox>
|
2021-01-07 14:16:53 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-03-18 10:41:31 +00:00
|
|
|
import { ref } from 'vue';
|
|
|
|
|
2021-01-07 14:16:53 +00:00
|
|
|
export default {
|
2021-03-18 10:41:31 +00:00
|
|
|
setup() {
|
|
|
|
const selectedCity = ref();
|
|
|
|
const selectedCountries = ref();
|
|
|
|
const selectedGroupedCity = ref();
|
|
|
|
const cities = ref([
|
|
|
|
{name: 'New York', code: 'NY'},
|
|
|
|
{name: 'Rome', code: 'RM'},
|
|
|
|
{name: 'London', code: 'LDN'},
|
|
|
|
{name: 'Istanbul', code: 'IST'},
|
|
|
|
{name: 'Paris', code: 'PRS'}
|
|
|
|
]);
|
|
|
|
const countries = ref([
|
|
|
|
{name: 'Australia', code: 'AU'},
|
|
|
|
{name: 'Brazil', code: 'BR'},
|
|
|
|
{name: 'China', code: 'CN'},
|
|
|
|
{name: 'Egypt', code: 'EG'},
|
|
|
|
{name: 'France', code: 'FR'},
|
|
|
|
{name: 'Germany', code: 'DE'},
|
|
|
|
{name: 'India', code: 'IN'},
|
|
|
|
{name: 'Japan', code: 'JP'},
|
|
|
|
{name: 'Spain', code: 'ES'},
|
|
|
|
{name: 'United States', code: 'US'}
|
|
|
|
]);
|
|
|
|
const groupedCities = ref([
|
|
|
|
{
|
2021-02-15 08:50:11 +00:00
|
|
|
label: 'Germany', code: 'DE',
|
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'USA', code: 'US',
|
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Japan', code: 'JP',
|
|
|
|
items: [
|
|
|
|
{label: 'Kyoto', value: 'Kyoto'},
|
2021-03-18 10:41:31 +00:00
|
|
|
{label: 'Osaka', value: 'Osaka'},
|
|
|
|
{label: 'Tokyo', value: 'Tokyo'},
|
|
|
|
{label: 'Yokohama', value: 'Yokohama'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
return { selectedCity, selectedCountries, selectedGroupedCity, cities, countries, groupedCities }
|
2021-01-07 14:16:53 +00:00
|
|
|
}
|
2021-03-18 10:41:31 +00:00
|
|
|
}
|
|
|
|
<\\/script>
|
|
|
|
`
|
2021-01-07 14:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|