Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1587 search grid no sorting #1630

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -669,6 +669,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 @@ -715,11 +716,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
Loading