From 9cee720ac9167e5f6aaa8a2c58c71a9dbb7c7881 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 8 Sep 2021 18:13:02 +0200 Subject: [PATCH] Fix sort order for table view --- src/views/list/views/Table.vue | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/views/list/views/Table.vue b/src/views/list/views/Table.vue index f6501da31..3deded876 100644 --- a/src/views/list/views/Table.vue +++ b/src/views/list/views/Table.vue @@ -286,10 +286,26 @@ export default { }, methods: { initTasks(page, search = '') { + // This makes sure an id sort order is always sorted last. + // When tasks would be sorted first by id and then by whatever else was specified, the id sort takes + // precedence over everything else, making any other sort columns pretty useless. + const sortKeys = Object.keys(this.sortBy) + let hasIdFilter = false + for (const s of sortKeys) { + if (s === 'id') { + sortKeys.splice(s, 1) + hasIdFilter = true + break + } + } + if (hasIdFilter) { + sortKeys.push('id') + } + const params = this.params params.sort_by = [] params.order_by = [] - Object.keys(this.sortBy).map(s => { + sortKeys.map(s => { params.sort_by.push(s) params.order_by.push(this.sortBy[s]) })