Skip to content

Commit fe96086

Browse files
committed
sneaky sorting bug for null vals
1 parent 6111351 commit fe96086

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: src/routes/collection.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export async function collectionRoute(req: HandlerRequest) {
129129
let query_sort = views[0]['query2'] ? views[0]['query2'].sort : undefined
130130

131131

132+
console.log('?!?!?!', query_sort)
132133

133134

134135

@@ -208,17 +209,18 @@ export async function collectionRoute(req: HandlerRequest) {
208209
query_sort.map((qsort:any)=>{
209210
let column = tableProps.find((c:any)=>c.property==qsort.property)
210211
if(column.type=='multi_select' || column.type=='select') { // sort by column options array rank of first item, rather than a-z
212+
211213
if(qsort.direction=='ascending') {
212214
tableData.rows = tableData.rows.sort((a:any,b:any) => { // get the column ranks by matching against the value and getting their index, then sorting by col index
213-
let _a = column.options.findIndex((e:any)=>e.value==a[column.name][0])
214-
let _b = column.options.findIndex((e:any)=>e.value==b[column.name][0])
215+
let _a = column.options.findIndex((e:any)=>e.value==a[column.name] && a[column.name][0])
216+
let _b = column.options.findIndex((e:any)=>e.value==b[column.name] && b[column.name][0])
215217
return _a < _b ? -1 : 1
216218
})
217219
}
218220
else {
219221
tableData.rows = tableData.rows.sort((a:any,b:any) => { // get the column ranks by matching against the value and getting their index, then sorting by col index
220-
let _a = column.options.findIndex((e:any)=>e.value==a[column.name][0])
221-
let _b = column.options.findIndex((e:any)=>e.value==b[column.name][0])
222+
let _a = column.options.findIndex((e:any)=>e.value==a[column.name] && a[column.name][0])
223+
let _b = column.options.findIndex((e:any)=>e.value==b[column.name] && b[column.name][0])
222224
return _a > _b ? -1 : 1
223225
})
224226
}

0 commit comments

Comments
 (0)