fix: updateSort instead of default v-model logic

This commit is contained in:
Shariq Ansari 2023-08-10 17:20:14 +05:30
parent fad5851392
commit 55812cd122

View File

@ -30,8 +30,9 @@
</div> </div>
<Autocomplete <Autocomplete
class="!w-32" class="!w-32"
v-model="sort.fieldname" :value="sort.fieldname"
:options="sortOptions.data" :options="sortOptions.data"
@change="(e) => updateSort(e, i)"
placeholder="Sort by" placeholder="Sort by"
/> />
<FormControl <FormControl
@ -150,9 +151,6 @@ watch(
(value) => { (value) => {
const updatedSort = value const updatedSort = value
.map((sort) => { .map((sort) => {
if (typeof sort.fieldname == 'object') {
sort.fieldname = sort.fieldname.value
}
const option = sortOptions.data.find((o) => o.value === sort.fieldname) const option = sortOptions.data.find((o) => o.value === sort.fieldname)
return `${option.value} ${sort.direction}` return `${option.value} ${sort.direction}`
}) })
@ -181,6 +179,13 @@ function setSort(data) {
sortSortable.start() sortSortable.start()
} }
function updateSort(data, index) {
sortValues.value[index] = {
fieldname: data.value,
direction: sortValues.value[index].direction,
}
}
function removeSort(index) { function removeSort(index) {
sortValues.value.splice(index, 1) sortValues.value.splice(index, 1)
} }