mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Fix sorting on MySQL
This commit is contained in:
@@ -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++;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user