Skip to content

Commit f265b81

Browse files
committed
Update CMSFilter.js
1 parent 6852a2c commit f265b81

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Dist/WebflowOnly/CMSFilter.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,32 +222,35 @@ class CMSFilter {
222222
}
223223

224224
SortItems() {
225-
if(!this.sortOptions) return;
225+
if (!this.sortOptions) return;
226226

227227
let [key, order] = this.sortOptions.value.split('-');
228228
this.filteredItems.sort((a, b) => {
229229
let aValue = a.dataset[key];
230230
let bValue = b.dataset[key];
231231

232+
if (aValue === undefined || bValue === undefined) {
233+
return 0; // If either value is undefined, consider them equal
234+
}
235+
232236
if (!isNaN(aValue) && !isNaN(bValue)) {
233237
aValue = parseFloat(aValue);
234238
bValue = parseFloat(bValue);
235-
}
236-
else if (Date.parse(aValue) && Date.parse(bValue)) {
239+
} else if (Date.parse(aValue) && Date.parse(bValue)) {
237240
aValue = new Date(aValue);
238241
bValue = new Date(bValue);
239242
} else {
240-
aValue = aValue.toString().toLowerCase();
241-
bValue = bValue.toString().toLowerCase();
243+
aValue = aValue ? aValue.toString().toLowerCase() : '';
244+
bValue = bValue ? bValue.toString().toLowerCase() : '';
242245
}
243246

244247
if (order === 'asc') {
245-
return aValue > bValue ? 1 : -1;
248+
return aValue > bValue ? 1 : aValue < bValue ? -1 : 0;
246249
} else {
247-
return aValue < bValue ? 1 : -1;
250+
return aValue < bValue ? 1 : aValue > bValue ? -1 : 0;
248251
}
249252
});
250-
}
253+
}
251254

252255
ApplyFilters() {
253256
const filters = this.GetFilters();

0 commit comments

Comments
 (0)