fix: default sort with multi filter target keys (#5404)

This commit is contained in:
ChengLei Shao 2024-10-13 12:58:38 +08:00 committed by GitHub
parent 22ab8f1e78
commit 5d11c3cb74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -138,10 +138,10 @@ export class OptionsParser {
sort = sort.split(','); sort = sort.split(',');
} }
let defaultSortField = this.model.primaryKeyAttribute; let defaultSortField: Array<string> | string = this.model.primaryKeyAttribute;
if (Array.isArray(this.collection.filterTargetKey) && this.collection.filterTargetKey.length == 1) { if (Array.isArray(this.collection.filterTargetKey)) {
defaultSortField = this.collection.filterTargetKey[0]; defaultSortField = this.collection.filterTargetKey;
} }
if (!defaultSortField && this.collection.filterTargetKey && !Array.isArray(this.collection.filterTargetKey)) { if (!defaultSortField && this.collection.filterTargetKey && !Array.isArray(this.collection.filterTargetKey)) {
@ -149,8 +149,11 @@ export class OptionsParser {
} }
if (defaultSortField && !this.options?.group) { if (defaultSortField && !this.options?.group) {
if (!sort.includes(defaultSortField)) { defaultSortField = lodash.castArray(defaultSortField);
sort.push(defaultSortField); for (const key of defaultSortField) {
if (!sort.includes(key)) {
sort.push(key);
}
} }
} }