Skip to content

Commit

Permalink
enh: view sorting
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Mar 12, 2024
1 parent 8de3ec2 commit 7da8113
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/modules/main/partials/editViewPartials/sort/SortForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div v-for="(sortingRule, i) in mutableSort" :key="sortingRule.columnId ?? '' + i">
<SortEntry
:sort-entry="sortingRule"
:columns="unusedColumns(sortingRule.columnId)"
:columns="eligibleColumns(sortingRule.columnId)"
:class="{'locallyAdded': isLocallyAdded(sortingRule)}"
@delete-sorting-rule="deleteSortingRule(i)" />
</div>
Expand Down Expand Up @@ -110,9 +110,9 @@ export default {
isSameEntry(object, searchObject) {
return Object.keys(searchObject).every((key) => object[key] === searchObject[key])
},
unusedColumns(selectedId) {
if (this.hadHiddenSortingRules || !this.viewSort) return this.columns
return this.columns.filter(col => !this.viewSort.map(entry => entry.columnId).includes(col.id) || col.id === selectedId)
eligibleColumns(selectedId) { // filter sortable and unused columns
if (this.hadHiddenSortingRules || !this.viewSort) return this.columns?.filter(col => col.canSort())
return this.columns.filter(col => col.canSort() && (!this.viewSort.map(entry => entry.columnId).includes(col.id) || col.id === selectedId))
},
deleteSortingRule(index) {
this.mutableSort.splice(index, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/main/sections/MainWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default {
this.viewSetting = {}
if (this.isView && this.element?.sort?.length) {
this.viewSetting.sorting = [...this.element.sort]
this.viewSetting.presetSorting = [...this.element.sort]
}
await this.$store.dispatch('loadColumnsFromBE', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
</NcActionButton>
</template>
<template v-else>
<NcActionCaption v-if="canSort" :name="t('tables', 'Sorting')" />
<NcActionButtonGroup v-if="canSort">
<NcActionCaption v-if="!hasPresetSorting && canSort" :name="t('tables', 'Sorting')" />
<NcActionButtonGroup v-if="!hasPresetSorting && canSort">
<NcActionButton :class="{ selected: getSortMode === 'ASC' }" :aria-label="t('tables', 'Sort asc')" @click="sort('ASC')">
<template #icon>
<SortAsc :size="20" />
Expand Down Expand Up @@ -225,8 +225,11 @@ export default {
canSort() {
return this.column.canSort()
},
hasPresetSorting() {
return this.localViewSetting?.presetSorting?.find(item => item.columnId === this.column?.id)
},
getSortMode() {
const sortObject = this.localViewSetting?.sorting?.find(item => item.columnId === this.column?.id)
const sortObject = this.localViewSetting?.presetSorting?.find(item => item.columnId === this.column?.id) ?? this.localViewSetting?.sorting?.find(item => item.columnId === this.column?.id)
if (sortObject) {
return sortObject.mode
}
Expand Down
8 changes: 6 additions & 2 deletions src/shared/components/ncTable/sections/CustomTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ export default {
},
getSearchedAndFilteredAndSortedRows() {
// if we have to sort
if (this.viewSetting?.presetSorting) {
const sortColumn = this.columns.find(item => item.id === this.viewSetting.presetSorting?.[0].columnId)
return [...this.getSearchedAndFilteredRows].sort(sortColumn?.sort?.(this.viewSetting.presetSorting[0].mode))
}
if (this.viewSetting?.sorting) {
const sortColumn = this.columns.find(item => item.id === this.viewSetting.sorting?.[0].columnId)
return [...this.getSearchedAndFilteredRows].sort(sortColumn?.sort?.(this.viewSetting.sorting[0].mode))
const sortColumn = this.columns.find(item => item.id === this.viewSetting.sorting[0].columnId)
return [...this.getSearchedAndFilteredRows].sort(sortColumn.sort(this.viewSetting.sorting[0].mode))
}
return this.getSearchedAndFilteredRows
},
Expand Down

0 comments on commit 7da8113

Please sign in to comment.