Fix sorting on MySQL

This commit is contained in:
rijkvanzanten
2020-08-21 17:09:48 -06:00
parent bf5b991156
commit 4724b95384
2 changed files with 8 additions and 6 deletions

View File

@@ -54,20 +54,23 @@ export default class UtilsService {
// Make sure all rows have a sort value
const countResponse = await this.knex
.count('*')
.as('count')
.count('* as count')
.from(collection)
.whereNull(sortField)
.first();
if (countResponse?.count && +countResponse.count !== 0) {
const lastSortValueResponse = await this.knex.max(sortField).from(collection).first();
const lastSortValueResponse = await this.knex
.max(sortField)
.from(collection)
.first();
const rowsWithoutSortValue = await this.knex
.select(primaryKeyField, sortField)
.from(collection)
.whereNull(sortField);
let lastSortValue = lastSortValueResponse?.max || 0;
let lastSortValue = lastSortValueResponse ? Object.values(lastSortValueResponse)[0] : 0;
for (const row of rowsWithoutSortValue) {
lastSortValue++;

View File

@@ -304,8 +304,7 @@ export default defineComponent({
const sort = computed({
get() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return _viewQuery.value?.sort || primaryKeyField.value!.field;
return _viewQuery.value?.sort || primaryKeyField.value?.field;
},
set(newSort: string) {
page.value = 1;