Fix error with table manual sort (#9010)

This commit is contained in:
Oreille
2021-10-21 18:31:00 +02:00
committed by GitHub
parent 2318347206
commit 7facfb1616

View File

@@ -164,7 +164,9 @@ export default defineLayout<LayoutOptions, LayoutQuery>({
function useTable() {
const tableSort = computed(() => {
if (sort.value?.[0].startsWith('-')) {
if (!sort.value?.[0]) {
return null;
} else if (sort.value?.[0].startsWith('-')) {
return { by: sort.value[0].substring(1), desc: true };
} else {
return { by: sort.value[0], desc: false };
@@ -275,6 +277,10 @@ export default defineLayout<LayoutOptions, LayoutQuery>({
function onSortChange(newSort: { by: string; desc: boolean }) {
let sortString = newSort.by;
if (!newSort.by) {
sort.value = [];
return;
}
if (newSort.desc === true) {
sortString = '-' + sortString;
}