Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit d47d56c

Browse files
committed
feat(BTable): do not require sortDesc when using sortBy
refactor(BTable): remove internalBusy and replace it with a passive vmodel fixes bootstrap-vue-next#1099
1 parent bb72530 commit d47d56c

File tree

1 file changed

+17
-21
lines changed
  • packages/bootstrap-vue-next/src/components/BTable

1 file changed

+17
-21
lines changed

packages/bootstrap-vue-next/src/components/BTable/BTable.vue

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</tr>
129129
</template>
130130
<tr
131-
v-if="internalBusyFlag"
131+
v-if="busyBoolean"
132132
class="b-table-busy-slot"
133133
:class="{'b-table-static-busy': computedItems.length === 0}"
134134
>
@@ -207,6 +207,7 @@ import type {
207207
import BTableSimple from './BTableSimple.vue'
208208
import {filterEvent} from './helpers/filter-event'
209209
import useItemHelper from './itemHelper'
210+
import {useVModel} from '@vueuse/core'
210211
211212
type NoProviderTypes = 'paging' | 'sorting' | 'filtering'
212213
@@ -318,23 +319,26 @@ const emit = defineEmits<{
318319
'filtered': [value: TableItem[]]
319320
}>()
320321
322+
const sortByModel = useVModel(props, 'sortBy', emit)
323+
const busyModel = useVModel(props, 'busy', emit, {passive: true})
324+
const sortDescModel = useVModel(props, 'sortDesc', emit, {passive: true})
325+
321326
const slots = useSlots()
322327
323328
const itemHelper = useItemHelper()
324329
325330
const footCloneBoolean = useBooleanish(() => props.footClone)
326-
const sortDescBoolean = useBooleanish(() => props.sortDesc)
331+
const sortDescBoolean = useBooleanish(sortDescModel)
327332
const sortInternalBoolean = useBooleanish(() => props.sortInternal)
328333
const selectableBoolean = useBooleanish(() => props.selectable)
329334
const stickySelectBoolean = useBooleanish(() => props.stickySelect)
330335
const labelStackedBoolean = useBooleanish(() => props.labelStacked)
331-
const busyBoolean = useBooleanish(() => props.busy)
336+
const busyBoolean = useBooleanish(busyModel)
332337
const showEmptyBoolean = useBooleanish(() => props.showEmpty)
333338
const noProviderPagingBoolean = useBooleanish(() => props.noProviderPaging)
334339
const noProviderSortingBoolean = useBooleanish(() => props.noProviderSorting)
335340
const noProviderFilteringBoolean = useBooleanish(() => props.noProviderFiltering)
336341
337-
const internalBusyFlag = ref(busyBoolean.value)
338342
itemHelper.filterEvent.value = async (items) => {
339343
if (usesProvider.value) {
340344
await callItemsProvider()
@@ -352,7 +356,7 @@ const tableClasses = computed(() => ({
352356
'b-table-selectable': selectableBoolean.value,
353357
[`b-table-select-${props.selectMode}`]: selectableBoolean.value,
354358
'b-table-selecting user-select-none': selectableBoolean.value && isSelecting.value,
355-
'b-table-busy': internalBusyFlag.value,
359+
'b-table-busy': busyBoolean.value,
356360
'b-table-sortable': isSortable.value,
357361
'b-table-sort-desc': isSortable.value && sortDescBoolean.value === true,
358362
'b-table-sort-asc': isSortable.value && sortDescBoolean.value === false,
@@ -452,9 +456,9 @@ const handleFieldSorting = (field: TableField) => {
452456
if (isSortable.value === true && fieldSortable === true) {
453457
const sortDesc = !sortDescBoolean.value
454458
if (fieldKey !== props.sortBy) {
455-
emit('update:sortBy', fieldKey)
459+
sortByModel.value = fieldKey
456460
}
457-
emit('update:sortDesc', sortDesc)
461+
sortDescModel.value = sortDesc
458462
emit('sorted', fieldKey, sortDesc)
459463
}
460464
}
@@ -508,8 +512,8 @@ const handleRowSelection = (
508512
}
509513
510514
const callItemsProvider = async () => {
511-
if (!usesProvider.value || !props.provider || internalBusyFlag.value) return
512-
internalBusyFlag.value = true
515+
if (!usesProvider.value || !props.provider || busyBoolean.value) return
516+
busyModel.value = true
513517
const context = new Proxy(
514518
{
515519
currentPage: props.currentPage,
@@ -536,8 +540,8 @@ const callItemsProvider = async () => {
536540
const internalItems = await itemHelper.updateInternalItems(items)
537541
return internalItems
538542
} finally {
539-
if (internalBusyFlag.value) {
540-
internalBusyFlag.value = false
543+
if (busyBoolean.value) {
544+
busyModel.value = false
541545
}
542546
}
543547
}
@@ -546,8 +550,8 @@ const callItemsProvider = async () => {
546550
const internalItems = await itemHelper.updateInternalItems(response)
547551
return internalItems
548552
} finally {
549-
if (internalBusyFlag.value) {
550-
internalBusyFlag.value = false
553+
if (busyBoolean.value) {
554+
busyModel.value = false
551555
}
552556
}
553557
}
@@ -659,14 +663,6 @@ watch(
659663
}
660664
)
661665
662-
watch(
663-
internalBusyFlag,
664-
() => internalBusyFlag.value !== busyBoolean.value && emit('update:busy', internalBusyFlag.value)
665-
)
666-
watch(
667-
busyBoolean,
668-
() => internalBusyFlag.value !== busyBoolean.value && (internalBusyFlag.value = busyBoolean.value)
669-
)
670666
watch(
671667
() => props.filter,
672668
(val, oldVal) => providerPropsWatch('filter', val, oldVal)

0 commit comments

Comments
 (0)