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

Commit 3bec258

Browse files
committed
feat(BTable): sortBy & sortDesc now can be used to pre-sort the table items without making any fields sortable
1 parent 7413433 commit 3bec258

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,11 @@ const noProviderFilteringBoolean = useBooleanish(() => props.noProviderFiltering
338338
339339
const isFilterableTable = computed(() => props.filter !== undefined && props.filter !== '')
340340
341-
const isSortable = computed(
342-
() =>
341+
const isSortable = computed(() => {
342+
const hasSortableFields =
343343
props.fields.filter((field) => (typeof field === 'string' ? false : field.sortable)).length > 0
344-
)
344+
return hasSortableFields || props.sortBy !== undefined
345+
})
345346
const usesProvider = computed(() => props.provider !== undefined)
346347
347348
const selectedItems = ref<Set<TableItem>>(new Set([]))
@@ -383,6 +384,8 @@ const addSelectableCell = computed(
383384
() => selectableBoolean.value && (!!props.selectHead || slots.selectHead !== undefined)
384385
)
385386
387+
const requireItemsMapping = computed(() => isSortable.value && sortInternalBoolean.value === true)
388+
386389
const {
387390
computedItems,
388391
computedDisplayItems,
@@ -396,6 +399,7 @@ const {
396399
isFilterableTable,
397400
noProviderPagingBoolean,
398401
isSortable,
402+
requireItemsMapping,
399403
sortDescBoolean,
400404
},
401405
usesProvider.value

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,10 @@ export const useTableItems = (
2828
const filteredHandler = ref<(items: TableItem[]) => void>()
2929
const internalItems = ref(tableProps.items ?? [])
3030
const displayStartEndIdx = ref([0, internalItems.value.length])
31-
const requireItemsMapping = computed(
32-
() => isSortable.value && flags.sortInternalBoolean.value === true
33-
)
34-
35-
const isSortable = computed(() => {
36-
const sortableLength = tableProps.fields?.filter((field) =>
37-
typeof field === 'string' ? false : field.sortable
38-
)?.length
39-
return sortableLength && sortableLength > 0
40-
})
41-
4231
const computedItems = computed<TableItem[]>(() => {
4332
const items = usesProvider
4433
? internalItems.value
45-
: requireItemsMapping.value
34+
: flags.requireItemsMapping.value
4635
? mapItems(internalItems, tableProps, flags)
4736
: tableProps.items ?? []
4837

0 commit comments

Comments
 (0)