1
0
forked from test/crm

fix: show sort count & filter out applied sort while adding new sort

This commit is contained in:
Shariq Ansari 2023-08-10 13:47:56 +05:30
parent 7a9d22cbe1
commit 9a8f47b007

View File

@ -1,8 +1,15 @@
<template> <template>
<NestedPopover v-if="sortOptions.data"> <NestedPopover v-if="options">
<template #target> <template #target>
<Button label="Sort" ref="sortButtonRef"> <Button label="Sort" ref="sortButtonRef">
<template #prefix><SortIcon class="h-4" /></template> <template #prefix><SortIcon class="h-4" /></template>
<template v-if="sortValues.length" #suffix>
<div
class="flex justify-center items-center w-5 h-5 text-2xs font-medium pt-[1px] bg-gray-900 text-white rounded"
>
{{ sortValues.length }}
</div>
</template>
</Button> </Button>
</template> </template>
<template #body="{ close }"> <template #body="{ close }">
@ -45,7 +52,7 @@
</div> </div>
<div class="flex items-center justify-between gap-2"> <div class="flex items-center justify-between gap-2">
<Autocomplete <Autocomplete
:options="sortOptions.data" :options="options"
value="" value=""
placeholder="Sort by" placeholder="Sort by"
@change="(e) => setSort(e)" @change="(e) => setSort(e)"
@ -88,7 +95,7 @@ import {
FormControl, FormControl,
createResource, createResource,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
const props = defineProps({ const props = defineProps({
doctype: { doctype: {
@ -110,6 +117,14 @@ const sortOptions = createResource({
}, },
}) })
const options = computed(() => {
if (!sortOptions.data) return []
const selectedOptions = sortValues.value.map((sort) => sort.fieldname)
return sortOptions.data.filter((option) => {
return !selectedOptions.includes(option.value)
})
})
function initialOrderBy() { function initialOrderBy() {
const orderBy = getOrderBy() const orderBy = getOrderBy()
if (!orderBy) return [] if (!orderBy) return []