fixes order_by

This commit is contained in:
buttle 2021-11-24 14:40:53 +01:00
parent 16ea5ef123
commit dc9d4e03ff
3 changed files with 34 additions and 5 deletions

View File

@ -200,4 +200,7 @@ export default {
.activeColumn { .activeColumn {
color: black; color: black;
} }
.accordion-title {
cursor: pointer;
}
</style> </style>

View File

@ -48,7 +48,6 @@ export default {
.then(function (response) { .then(function (response) {
//console.log(response.data) //console.log(response.data)
self.setFilteredSites(Object.assign({}, local_search_result, response.data)) self.setFilteredSites(Object.assign({}, local_search_result, response.data))
//self.setFilteredSites(response.data)
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);

View File

@ -30,13 +30,11 @@ const store = new Vuex.Store({
state.page_count = state.page_count +1 state.page_count = state.page_count +1
}, },
setFilteredSites(state, filtered_site_ids) { setFilteredSites(state, filtered_site_ids) {
console.log('filtered_site_ids')
console.log(filtered_site_ids) console.log(filtered_site_ids)
var sites = [] var sites = []
for (const [site_id, weight] of Object.entries(filtered_site_ids)) { for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
var site = state.sites.find(x => x.id == site_id) var site = state.sites.find(x => x.id == site_id)
if (site) { if (site) {
console.log('push')
sites.push(site) sites.push(site)
} }
} }
@ -44,12 +42,16 @@ const store = new Vuex.Store({
state.page_count = 1 state.page_count = 1
}, },
setColumnOrder(state, payload) { setColumnOrder(state, payload) {
state.sites = _.sortBy(state.sites, payload.column_name) //state.sites = _.sortBy(state.sites, payload.column_name)
state.filtered_sites = _.sortBy(state.filtered_sites, payload.column_name) //state.filtered_sites = _.sortBy(state.filtered_sites, payload.column_name)
state.sites = order_items(state.sites, payload.column_name, payload.order)
state.filtered_sites = order_items(state.filtered_sites, payload.column_name, payload.order)
/*
if (payload.order == 'desc') { if (payload.order == 'desc') {
state.sites.reverse() state.sites.reverse()
state.filtered_sites.reverse() state.filtered_sites.reverse()
} }
*/
}, },
}, },
getters: { getters: {
@ -96,5 +98,30 @@ const store = new Vuex.Store({
}, },
} }
}) })
function order_items(items, field_name, ascending) {
items.sort(function compareFn(first_el, second_el) {
if (field_name == 'artist') {
field_name = 'currator'
}
if (field_name == 'date') {
field_name = 'project_date'
}
console.log("sss: "+ field_name)
console.log(first_el)
if (first_el[field_name] === undefined || first_el[field_name] === ""){
return -1
}
if (second_el[field_name] === undefined || second_el[field_name] === ""){
return 1
}
first_el = first_el[field_name].toLowerCase()
second_el = second_el[field_name].toLowerCase()
if (first_el < second_el) {
return -1;
}
return 1;
})
return ascending == 'asc' ? items : items.reverse()
}
export default store export default store