primevue-mirror/apps/showcase/doc/multiselect/VirtualScrollDoc.vue

108 lines
3.8 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>
VirtualScroller is used to render a long list of options efficiently like 100K records in this demo. The configuration is done with <i>virtualScrollerOptions</i> property, refer to the
<NuxtLink to="/virtualscroller">VirtualScroller</NuxtLink> for more information about the available options as it is used internally by MultiSelect.
</p>
</DocSectionText>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2023-02-28 08:29:30 +00:00
<MultiSelect
v-model="selectedItems"
:options="items"
:maxSelectedLabels="3"
:selectAll="selectAll"
@selectall-change="onSelectAllChange($event)"
@change="onChange($event)"
optionLabel="label"
optionValue="value"
:virtualScrollerOptions="{ itemSize: 44 }"
2024-05-09 06:00:26 +00:00
filter
2023-02-28 08:29:30 +00:00
placeholder="Select Item"
2024-05-20 12:14:38 +00:00
class="w-full md:w-80"
2023-02-28 08:29:30 +00:00
/>
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
selectedItems: null,
selectAll: false,
items: Array.from({ length: 100000 }, (_, i) => ({ label: `Item #${i}`, value: i })),
code: {
2023-09-22 12:54:14 +00:00
basic: `
<MultiSelect v-model="selectedItems" :options="items" :maxSelectedLabels="3" :selectAll="selectAll" optionLabel="label" optionValue="value"
2024-05-20 12:14:38 +00:00
@selectall-change="onSelectAllChange($event)" @change="onChange($event)" :virtualScrollerOptions="{ itemSize: 44 }" filter placeholder="Select Item" class="w-full md:w-80" />
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2023-02-28 08:29:30 +00:00
<MultiSelect v-model="selectedItems" :options="items" :maxSelectedLabels="3" :selectAll="selectAll" optionLabel="label" optionValue="value"
2024-05-20 12:14:38 +00:00
@selectall-change="onSelectAllChange($event)" @change="onChange($event)" :virtualScrollerOptions="{ itemSize: 44 }" filter placeholder="Select Item" class="w-full md:w-80" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
data() {
return {
selectedItems: null,
selectAll: false,
items: Array.from({ length: 100000 }, (_, i) => ({ label: \`Item #\${i}\`, value: i }))
};
},
methods: {
onSelectAllChange(event) {
this.selectedItems = event.checked ? this.items.map((item) => item.value) : [];
this.selectAll = event.checked;
},
onChange(event) {
this.selectAll = event.value.length === this.items.length;
}
}
};
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">
2023-02-28 08:29:30 +00:00
<MultiSelect v-model="selectedItems" :options="items" :maxSelectedLabels="3" :selectAll="selectAll" optionLabel="label" optionValue="value"
2024-05-20 12:14:38 +00:00
@selectall-change="onSelectAllChange($event)" @change="onChange($event)" :virtualScrollerOptions="{ itemSize: 44 }" filter placeholder="Select Item" class="w-full md:w-80" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { ref } from 'vue';
const selectedItems = ref();
const selectAll = ref(false);
const items = ref(Array.from({ length: 100000 }, (_, i) => ({ label: \`Item #\${i}\`, value: i })));
const onSelectAllChange = (event) => {
selectedItems.value = event.checked ? items.value.map((item) => item.value) : [];
selectAll.value = event.checked;
};
2023-11-02 12:51:02 +00:00
const onChange = (event) => {
2023-02-28 08:29:30 +00:00
selectAll.value = event.value.length === items.value.length;
}
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-02-28 08:29:30 +00:00
}
};
},
methods: {
onSelectAllChange(event) {
this.selectedItems = event.checked ? this.items.map((item) => item.value) : [];
this.selectAll = event.checked;
},
onChange(event) {
this.selectAll = event.value.length === this.items.length;
}
}
};
</script>