Skip to content

Commit

Permalink
Merge pull request #1630 from SenseNet/fix/1587-search_grid_no_sorting
Browse files Browse the repository at this point in the history
Fix/1587 search grid no sorting
  • Loading branch information
NoelKova authored Aug 5, 2024
2 parents 173de69 + a4000ce commit b15c91c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/sensenet/src/components/content-list/content-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
}

const displayNameInArray = ['DisplayName']
const sortableColumns = ['DisplayName', 'Path', 'Type', 'Name', 'Version', 'CreationDate', 'ModificationDate']

return (
<div style={{ ...props.style, ...{ height: '100%' } }} {...props.containerProps}>
Expand Down Expand Up @@ -720,11 +721,24 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
getSelectionControl={getSelectionControl}
/* If the Order by Column Is The Display. The client will sort it. Due to some locale and indexing issues */
items={
currentOrder === 'DisplayName'
sortableColumns.includes(String(currentOrder))
? children?.sort((a, b) => {
// If no display Name
const nameA = a?.DisplayName ?? '' // Provide a default value if displayName is undefined
const nameB = b?.DisplayName ?? '' // Provide a default value if displayName is undefined
const nameA = String(a[currentOrder]) ?? '' // Provide a default value if displayName is undefined
const nameB = String(b[currentOrder]) ?? '' // Provide a default value if displayName is undefined

if (currentDirection === 'asc') {
return nameA.localeCompare(nameB)
}
return nameB.localeCompare(nameA)
})
: currentOrder === 'CreatedBy' || currentOrder === 'ModifiedBy'
? children?.sort((a, b) => {
const aTmp = a[currentOrder] as GenericContent
const bTmp = b[currentOrder] as GenericContent

const nameA = String(aTmp?.DisplayName) ?? ''
const nameB = String(bTmp?.DisplayName) ?? ''

if (currentDirection === 'asc') {
return nameA.localeCompare(nameB)
Expand Down

0 comments on commit b15c91c

Please sign in to comment.