2019-03-25 12:21:45 +00:00
|
|
|
<template>
|
2021-04-06 09:16:59 +00:00
|
|
|
<AppDoc name="ListboxDemo" :sources="sources" github="listbox/ListboxDemo.vue">
|
2021-10-22 10:23:03 +00:00
|
|
|
<h5>Import via Module</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
|
|
|
|
2021-10-13 14:35:09 +00:00
|
|
|
</code></pre>
|
|
|
|
|
|
|
|
<h5>Import via CDN</h5>
|
|
|
|
<pre v-code><code>
|
2021-10-26 08:41:57 +00:00
|
|
|
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
|
2021-10-13 14:35:09 +00:00
|
|
|
<script src="https://unpkg.com/primevue@^3/listbox/listbox.min.js"></script>
|
|
|
|
|
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: [{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'Germany', code: 'DE',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'USA', code: 'US',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'Japan', code: 'JP',
|
2021-02-15 08:50:11 +00:00
|
|
|
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-08-16 10:48:49 +00:00
|
|
|
<Listbox v-model="selectedGroupedCity" :options="groupedCities"
|
2021-02-15 14:05:02 +00:00
|
|
|
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>
|
2021-05-05 14:33:56 +00:00
|
|
|
<td>null</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
<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>
|
2021-08-16 10:48:49 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>virtualScrollerOptions</td>
|
|
|
|
<td>object</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Whether to use the virtualScroller feature. The properties of <router-link to="/virtualscroller">VirtualScroller</router-link> component can be used like an object in it.</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
</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>
|
2021-08-17 14:09:43 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>content</td>
|
|
|
|
<td>items: An array of objects to display for virtualscroller<br />
|
|
|
|
styleClass: Style class of the component<br />
|
|
|
|
contentRef: Referance of the content<br />
|
|
|
|
getItemOptions: Options of the items</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>loader</td>
|
|
|
|
<td>options: Options of the loader items for virtualscroller</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
</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': {
|
2021-04-05 09:29:28 +00:00
|
|
|
tabName: 'Options API Source',
|
2021-03-18 10:41:31 +00:00
|
|
|
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>
|
2021-08-16 10:48:49 +00:00
|
|
|
|
2021-08-17 09:46:20 +00:00
|
|
|
<h5>Virtual Scroll (1000 Items)</h5>
|
2021-08-16 10:48:49 +00:00
|
|
|
<Listbox v-model="selectedItem" :options="items" optionLabel="label" optionValue="value" :virtualScrollerOptions="{ itemSize: 31 }" style="width:15rem" listStyle="height:250px" />
|
2021-03-18 10:41:31 +00:00
|
|
|
</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,
|
2021-08-16 10:48:49 +00:00
|
|
|
selectedItem: 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: [{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'Germany', code: 'DE',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'USA', code: 'US',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'Japan', code: 'JP',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Kyoto', value: 'Kyoto'},
|
|
|
|
{label: 'Osaka', value: 'Osaka'},
|
|
|
|
{label: 'Tokyo', value: 'Tokyo'},
|
|
|
|
{label: 'Yokohama', value: 'Yokohama'}
|
|
|
|
]
|
2021-08-16 10:48:49 +00:00
|
|
|
}],
|
2021-08-17 09:46:20 +00:00
|
|
|
items: Array.from({ length: 1000 }, (_, i) => ({ label: \`Item #\${i}\`, value: i }))
|
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': {
|
2021-04-05 09:29:28 +00:00
|
|
|
tabName: 'Composition API Source',
|
2021-03-18 10:41:31 +00:00
|
|
|
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-08-16 10:48:49 +00:00
|
|
|
|
2021-08-17 09:46:20 +00:00
|
|
|
<h5>Virtual Scroll (1000 Items)</h5>
|
2021-08-16 10:48:49 +00:00
|
|
|
<Listbox v-model="selectedItem" :options="items" optionLabel="label" optionValue="value" :virtualScrollerOptions="{ itemSize: 31 }" style="width:15rem" listStyle="height:250px" />
|
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();
|
2021-08-16 10:48:49 +00:00
|
|
|
const selectedItem = ref();
|
2021-03-18 10:41:31 +00:00
|
|
|
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-08-16 10:48:49 +00:00
|
|
|
label: 'Germany', code: 'DE',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Berlin', value: 'Berlin'},
|
|
|
|
{label: 'Frankfurt', value: 'Frankfurt'},
|
|
|
|
{label: 'Hamburg', value: 'Hamburg'},
|
|
|
|
{label: 'Munich', value: 'Munich'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'USA', code: 'US',
|
2021-02-15 08:50:11 +00:00
|
|
|
items: [
|
|
|
|
{label: 'Chicago', value: 'Chicago'},
|
|
|
|
{label: 'Los Angeles', value: 'Los Angeles'},
|
|
|
|
{label: 'New York', value: 'New York'},
|
|
|
|
{label: 'San Francisco', value: 'San Francisco'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2021-08-16 10:48:49 +00:00
|
|
|
label: 'Japan', code: 'JP',
|
2021-02-15 08:50:11 +00:00
|
|
|
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'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2021-08-17 09:46:20 +00:00
|
|
|
const items = ref(Array.from({ length: 1000 }, (_, i) => ({ label: \`Item #\${i}\`, value: i })));
|
2021-08-16 10:48:49 +00:00
|
|
|
|
|
|
|
return { selectedCity, selectedCountries, selectedGroupedCity, cities, countries, groupedCities, items, selectedItem }
|
2021-01-07 14:16:53 +00:00
|
|
|
}
|
2021-03-18 10:41:31 +00:00
|
|
|
}
|
|
|
|
<\\/script>
|
2021-10-11 13:51:36 +00:00
|
|
|
`
|
|
|
|
},
|
|
|
|
'browser-source': {
|
|
|
|
tabName: 'Browser Source',
|
|
|
|
imports: `<script src="https://unpkg.com/primevue@^3/listbox/listbox.min.js"><\\/script>`,
|
2021-10-11 17:57:45 +00:00
|
|
|
content: `<div id="app">
|
2021-10-11 13:51:36 +00:00
|
|
|
<h5>Single</h5>
|
|
|
|
<p-listbox v-model="selectedCity" :options="cities" option-label="name" style="width:15rem"></p-listbox>
|
|
|
|
|
|
|
|
<h5>Grouped</h5>
|
|
|
|
<p-listbox v-model="selectedGroupedCity" :options="groupedCities" option-label="label" style="width:15rem" option-group-label="label" option-group-children="items" list-style="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>
|
|
|
|
</p-listbox>
|
|
|
|
|
|
|
|
<h5>Advanced with Templating, Filtering and Multiple Selection</h5>
|
|
|
|
<p-listbox v-model="selectedCountries" :options="countries" :multiple="true" :filter="true" option-label="name" list-style="max-height:250px" style="width:15rem" filter-placeholder="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>
|
|
|
|
</p-listbox>
|
|
|
|
|
|
|
|
<h5>Virtual Scroll (1000 Items)</h5>
|
|
|
|
<p-listbox v-model="selectedItem" :options="items" option-label="label" option-value="value" :virtual-scroller-options="{ itemSize: 31 }" style="width:15rem" list-style="height:250px"></p-listbox>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="module">
|
|
|
|
const { createApp, ref } = Vue;
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
setup() {
|
|
|
|
const selectedCity = ref();
|
|
|
|
const selectedCountries = ref();
|
|
|
|
const selectedGroupedCity = ref();
|
|
|
|
const selectedItem = 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([
|
|
|
|
{
|
|
|
|
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'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const items = ref(Array.from({ length: 1000 }, (_, i) => ({ label: \`Item #\${i}\`, value: i })));
|
|
|
|
|
|
|
|
return { selectedCity, selectedCountries, selectedGroupedCity, cities, countries, groupedCities, items, selectedItem }
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
"p-listbox": primevue.listbox
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
createApp(App)
|
|
|
|
.use(primevue.config.default)
|
|
|
|
.mount("#app");
|
|
|
|
<\\/script>
|
2021-03-18 10:41:31 +00:00
|
|
|
`
|
2021-01-07 14:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 10:48:49 +00:00
|
|
|
</script>
|