2023-02-28 08:29:30 +00:00
|
|
|
<template>
|
|
|
|
<DocSectionText v-bind="$attrs" />
|
2024-05-20 12:14:38 +00:00
|
|
|
<div class="card flex justify-center">
|
2024-04-18 14:22:30 +00:00
|
|
|
<Select
|
2023-02-28 08:29:30 +00:00
|
|
|
v-model="selectedItem"
|
|
|
|
:options="items"
|
|
|
|
optionLabel="label"
|
|
|
|
optionValue="value"
|
|
|
|
:virtualScrollerOptions="{ lazy: true, onLazyLoad: onLazyLoad, itemSize: 38, showLoader: true, loading: loading, delay: 250 }"
|
|
|
|
placeholder="Select Item"
|
2024-05-20 12:14:38 +00:00
|
|
|
class="w-full md:w-56"
|
2023-02-28 08:29:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<DocSectionCode :code="code" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedItem: null,
|
|
|
|
items: Array.from({ length: 100000 }),
|
|
|
|
loading: false,
|
|
|
|
code: {
|
2023-09-22 12:54:14 +00:00
|
|
|
basic: `
|
2024-05-20 12:14:38 +00:00
|
|
|
<Select v-model="selectedItem" :options="items" optionLabel="label" optionValue="value" class="w-full md:w-56"
|
2023-10-15 09:38:39 +00:00
|
|
|
:virtualScrollerOptions="{ lazy: true, onLazyLoad: onLazyLoad, itemSize: 38, showLoader: true, loading: loading, delay: 250 }" placeholder="Select Item" />
|
|
|
|
`,
|
2023-09-22 12:54:14 +00:00
|
|
|
options: `
|
|
|
|
<template>
|
2024-05-20 12:14:38 +00:00
|
|
|
<div class="card flex justify-center">
|
|
|
|
<Select v-model="selectedItem" :options="items" optionLabel="label" optionValue="value" class="w-full md:w-56"
|
2023-02-28 08:29:30 +00:00
|
|
|
:virtualScrollerOptions="{ lazy: true, onLazyLoad: onLazyLoad, itemSize: 38, showLoader: true, loading: loading, delay: 250 }" placeholder="Select Item" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedItem: null,
|
|
|
|
items: Array.from({ length: 100000 }),
|
|
|
|
loading: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
loadLazyTimeout: null,
|
|
|
|
methods: {
|
|
|
|
onLazyLoad(event) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
if (this.loadLazyTimeout) {
|
|
|
|
clearTimeout(this.loadLazyTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
//imitate delay of a backend call
|
|
|
|
this.loadLazyTimeout = setTimeout(() => {
|
|
|
|
const { first, last } = event;
|
|
|
|
const _items = [...this.items];
|
|
|
|
|
|
|
|
for (let i = first; i < last; i++) {
|
|
|
|
_items[i] = { label: \`Item #\${i}\`, value: i };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = _items;
|
|
|
|
this.loading = false;
|
|
|
|
}, Math.random() * 1000 + 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-10-15 09:38:39 +00:00
|
|
|
<\/script>
|
|
|
|
`,
|
2023-09-22 12:54:14 +00:00
|
|
|
composition: `
|
|
|
|
<template>
|
2024-05-20 12:14:38 +00:00
|
|
|
<div class="card flex justify-center">
|
|
|
|
<Select v-model="selectedItem" :options="items" optionLabel="label" optionValue="value" class="w-full md:w-56"
|
2023-02-28 08:29:30 +00:00
|
|
|
:virtualScrollerOptions="{ lazy: true, onLazyLoad: onLazyLoad, itemSize: 38, showLoader: true, loading: loading, delay: 250 }" placeholder="Select Item" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import { ref } from "vue";
|
|
|
|
|
|
|
|
const selectedItem = ref();
|
|
|
|
const items = ref(Array.from({ length: 100000 }));
|
|
|
|
const loading = ref(false);
|
|
|
|
const loadLazyTimeout = ref();
|
|
|
|
const onLazyLoad = (event) => {
|
|
|
|
loading.value = true;
|
|
|
|
|
|
|
|
if (loadLazyTimeout.value) {
|
|
|
|
clearTimeout(loadLazyTimeout.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//imitate delay of a backend call
|
|
|
|
loadLazyTimeout.value = setTimeout(() => {
|
|
|
|
const { first, last } = event;
|
|
|
|
const _items = [...items.value];
|
|
|
|
|
|
|
|
for (let i = first; i < last; i++) {
|
|
|
|
_items[i] = { label: \`Item #\${i}\`, value: i };
|
|
|
|
}
|
|
|
|
|
|
|
|
items.value = _items;
|
|
|
|
loading.value = false;
|
|
|
|
}, Math.random() * 1000 + 250);
|
|
|
|
}
|
2023-10-15 09:38:39 +00:00
|
|
|
<\/script>
|
|
|
|
`
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
loadLazyTimeout: null,
|
|
|
|
methods: {
|
|
|
|
onLazyLoad(event) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
if (this.loadLazyTimeout) {
|
|
|
|
clearTimeout(this.loadLazyTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
//imitate delay of a backend call
|
2024-06-14 14:56:05 +00:00
|
|
|
this.loadLazyTimeout = setTimeout(() => {
|
|
|
|
const { first, last } = event;
|
|
|
|
const items = [...this.items];
|
|
|
|
|
|
|
|
for (let i = first; i < last; i++) {
|
|
|
|
items[i] = { label: `Item #${i}`, value: i };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = items;
|
|
|
|
this.loading = false;
|
|
|
|
}, Math.random() * 1000 + 250);
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|