Merge pull request #16675 from strapi/fix/list-view-sort

Fix: Fix toOne sorting in CM list-view
This commit is contained in:
Gustav Hansen 2023-05-11 11:11:48 +02:00 committed by GitHub
commit aa749f4022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -34,7 +34,12 @@ export default (layout) => {
}),
searchable: false,
sortable: true,
mainField: 'name',
mainField: {
name: 'name',
schema: {
type: 'string',
},
},
},
cellFormatter({ strapi_reviewWorkflows_stage }) {
// if entities are created e.g. through lifecycle methods

View File

@ -52,7 +52,7 @@ const TableHead = ({
// relations always have to be sorted by their main field instead of only the
// attribute name; sortBy e.g. looks like: &sortBy=attributeName[mainField]:ASC
if (fieldSchema?.type === 'relation' && mainField) {
isSorted = sortBy === `${name}[${mainField}]`;
isSorted = sortBy === `${name.split('.')[0]}[${mainField.name}]`;
}
const sortLabel = formatMessage(
@ -67,7 +67,7 @@ const TableHead = ({
// relations always have to be sorted by their main field instead of only the
// attribute name; nextSort e.g. looks like: &nextSort=attributeName[mainField]:ASC
if (fieldSchema?.type === 'relation' && mainField) {
nextSort = `${name}[${mainField}]`;
nextSort = `${name.split('.')[0]}[${mainField.name}]`;
}
setQuery({