Skip to content

Commit

Permalink
sneaky sorting bug for null vals
Browse files Browse the repository at this point in the history
  • Loading branch information
janzheng committed Nov 29, 2021
1 parent 6111351 commit fe96086
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/routes/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export async function collectionRoute(req: HandlerRequest) {
let query_sort = views[0]['query2'] ? views[0]['query2'].sort : undefined


console.log('?!?!?!', query_sort)



Expand Down Expand Up @@ -208,17 +209,18 @@ export async function collectionRoute(req: HandlerRequest) {
query_sort.map((qsort:any)=>{
let column = tableProps.find((c:any)=>c.property==qsort.property)
if(column.type=='multi_select' || column.type=='select') { // sort by column options array rank of first item, rather than a-z

if(qsort.direction=='ascending') {
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
let _a = column.options.findIndex((e:any)=>e.value==a[column.name][0])
let _b = column.options.findIndex((e:any)=>e.value==b[column.name][0])
let _a = column.options.findIndex((e:any)=>e.value==a[column.name] && a[column.name][0])
let _b = column.options.findIndex((e:any)=>e.value==b[column.name] && b[column.name][0])
return _a < _b ? -1 : 1
})
}
else {
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
let _a = column.options.findIndex((e:any)=>e.value==a[column.name][0])
let _b = column.options.findIndex((e:any)=>e.value==b[column.name][0])
let _a = column.options.findIndex((e:any)=>e.value==a[column.name] && a[column.name][0])
let _b = column.options.findIndex((e:any)=>e.value==b[column.name] && b[column.name][0])
return _a > _b ? -1 : 1
})
}
Expand Down

0 comments on commit fe96086

Please sign in to comment.