diff --git a/frontend/src/lib/components/instance-views/ComparisonView.svelte b/frontend/src/lib/components/instance-views/ComparisonView.svelte index 7e60a767..68b2cdcc 100644 --- a/frontend/src/lib/components/instance-views/ComparisonView.svelte +++ b/frontend/src/lib/components/instance-views/ComparisonView.svelte @@ -85,29 +85,29 @@ } }); - // trigger this function when clicking column header to sort function updateSort(model: string | undefined) { if (model === undefined) return; - // when clicking different model columns, reset compareSort sortModel = model; - // deep copy to not mutate object - let compareColumnObj = JSON.parse( - JSON.stringify( - $columns.filter( - (col) => col.name == $comparisonColumn?.name && col.model == $comparisonModel - )[0] - ) + let sortColumnObjects = $columns.filter( + (col) => col.name == $comparisonColumn?.name && col.model == model ); + // if no column found for model, model is "", find col for any model. + if (sortColumnObjects.length === 0) { + sortColumnObjects = $columns.filter((col) => col.name == $comparisonColumn?.name); + } + + // deep copy to not mutate object + let compareColumnObj = JSON.parse(JSON.stringify(sortColumnObjects[0])); + // set ID to blank, telling backend to sort by difference. if (sortModel === '') { compareColumnObj.id = ''; } let compareSortString = JSON.stringify($compareSort[0]); let newHeaderString = JSON.stringify(compareColumnObj); - if (compareSortString !== newHeaderString) { compareSort.set([compareColumnObj, true]); } else if (compareSortString === newHeaderString && $compareSort[1]) {