Skip to content

Commit

Permalink
clientSortOptions compute from sortType and sortBy
Browse files Browse the repository at this point in the history
A hacky workaround, for reference only.

implementation of HC200ok#371

(sortBy sortType) => clientSortOptions => items
  • Loading branch information
childe committed Jun 6, 2024
1 parent aa77f92 commit 96a1248
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ const {
serverItemsLength,
serverOptions,
showIndex,
sortBy,
sortType,
_sortBy,
_sortType,
tableHeight,
tableMinHeight,
themeColor,
Expand All @@ -372,6 +372,9 @@ const {
preventContextMenuRow
} = toRefs(props);
const sortBy = ref(props.sortBy);
const sortType = ref(props.sortType);
// style related computed variables
const tableHeightPx = computed(() => (tableHeight.value ? `${tableHeight.value}px` : null));
const tableMinHeightPx = computed(() => `${tableMinHeight.value}px`);
Expand Down
21 changes: 10 additions & 11 deletions src/hooks/useHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function useHeaders(
return null;
};

const clientSortOptions = ref<ClientSortOptions | null>(generateClientSortOptions(sortBy.value, sortType.value));
const clientSortOptions = computed((): ClientSortOptions | null => generateClientSortOptions(sortBy.value, sortType.value));

// headers for render (integrating sortType,z checkbox...)
const headersForRender = computed((): HeaderForRender[] => {
Expand Down Expand Up @@ -148,22 +148,21 @@ export default function useHeaders(
const index = clientSortOptions.value.sortBy.indexOf(newSortBy);
if (index === -1) {
if (newSortType !== null) {
clientSortOptions.value.sortBy.push(newSortBy);
clientSortOptions.value.sortDesc.push(newSortType === 'desc');
sortBy.value.push(newSortBy);
sortType.value.push(newSortType);
}
} else if (newSortType === null) {
clientSortOptions.value.sortDesc.splice(index, 1);
clientSortOptions.value.sortBy.splice(index, 1);
sortType.value.splice(index, 1);
sortBy.value.splice(index, 1);
} else {
clientSortOptions.value.sortDesc[index] = newSortType === 'desc';
sortType.value[index] = newSortType ;
}
} else if (newSortType === null) {
clientSortOptions.value = null;
sortBy.value = '';
sortType.value = '';
} else {
clientSortOptions.value = {
sortBy: newSortBy,
sortDesc: newSortType === 'desc',
};
sortBy.value = newSortBy,
sortType.value = newSortType ;
}
emits('updateSort', {
sortType: newSortType,
Expand Down

0 comments on commit 96a1248

Please sign in to comment.