Skip to content

Commit b15c91c

Browse files
authored
Merge pull request #1630 from SenseNet/fix/1587-search_grid_no_sorting
Fix/1587 search grid no sorting
2 parents 173de69 + a4000ce commit b15c91c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

apps/sensenet/src/components/content-list/content-list.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
674674
}
675675

676676
const displayNameInArray = ['DisplayName']
677+
const sortableColumns = ['DisplayName', 'Path', 'Type', 'Name', 'Version', 'CreationDate', 'ModificationDate']
677678

678679
return (
679680
<div style={{ ...props.style, ...{ height: '100%' } }} {...props.containerProps}>
@@ -720,11 +721,24 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
720721
getSelectionControl={getSelectionControl}
721722
/* If the Order by Column Is The Display. The client will sort it. Due to some locale and indexing issues */
722723
items={
723-
currentOrder === 'DisplayName'
724+
sortableColumns.includes(String(currentOrder))
724725
? children?.sort((a, b) => {
725726
// If no display Name
726-
const nameA = a?.DisplayName ?? '' // Provide a default value if displayName is undefined
727-
const nameB = b?.DisplayName ?? '' // Provide a default value if displayName is undefined
727+
const nameA = String(a[currentOrder]) ?? '' // Provide a default value if displayName is undefined
728+
const nameB = String(b[currentOrder]) ?? '' // Provide a default value if displayName is undefined
729+
730+
if (currentDirection === 'asc') {
731+
return nameA.localeCompare(nameB)
732+
}
733+
return nameB.localeCompare(nameA)
734+
})
735+
: currentOrder === 'CreatedBy' || currentOrder === 'ModifiedBy'
736+
? children?.sort((a, b) => {
737+
const aTmp = a[currentOrder] as GenericContent
738+
const bTmp = b[currentOrder] as GenericContent
739+
740+
const nameA = String(aTmp?.DisplayName) ?? ''
741+
const nameB = String(bTmp?.DisplayName) ?? ''
728742

729743
if (currentDirection === 'asc') {
730744
return nameA.localeCompare(nameB)

0 commit comments

Comments
 (0)