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

TreeTable: sortFunction is not called when custom sort is used #6115

Closed
BAISTM opened this issue Mar 8, 2024 · 9 comments · Fixed by #6436
Closed

TreeTable: sortFunction is not called when custom sort is used #6115

BAISTM opened this issue Mar 8, 2024 · 9 comments · Fixed by #6436
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@BAISTM
Copy link

BAISTM commented Mar 8, 2024

Describe the bug

The column's custom sort function is not called when sorting a column.

Reproducer

https://stackblitz.com/edit/vqw5gi-jmmcd5?file=src%2FApp.jsx

PrimeReact version

10.3.1

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

The multi sort mode should allow users to customize the sort of a column.

@BAISTM BAISTM added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 8, 2024
@melloware
Copy link
Member

melloware commented Mar 10, 2024

Duplicate of: #6083 but leaving this one open and closing that one because yours contains a reproducer and the other ticket does not.

@melloware melloware changed the title TreeTable: sortFunction is not called when multi sort mode is enabled TreeTable: sortFunction is not called when custom sort is used Mar 10, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 10, 2024
@MBelniak
Copy link
Contributor

MBelniak commented Apr 8, 2024

You need to pass 'custom' as a sortable prop to make it work:
sortable={'custom'}
It's working nice on my side. The only problem I had was missing typings, which I created an issue for: #5591

BUT
I have a problem, that the custom sort function is not called for the default sorted column. You can use 'sortField' and 'sortOrder' props on DataTable or TreeTable to set the default sorting on column, but the data is sorted using some default algorithm instead of sortFunction. @melloware Maybe it's something that doesn't take much to fix?

@MBelniak
Copy link
Contributor

Oh, I see there's been a change recently here https://github.com/primefaces/primereact/blob/master/components/lib/treetable/TreeTable.js#L227 so sortable={'custom'} is no longer needed, just sortable is enough.

@melloware
Copy link
Member

@MBelniak so its all working?

@melloware melloware added Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior Type: Bug Issue contains a defect related to a specific component. and removed Type: Bug Issue contains a defect related to a specific component. Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior labels Apr 20, 2024
@melloware
Copy link
Member

@MBelniak it looks like @BAISTM Stackblitz above is still not working and he is using sortable can you take a look?

@MBelniak
Copy link
Contributor

I believe the problem with custom sort function not being called for column with default sorting is still there. I'm checking right now. It might be it's a one liner change with setting a default value for columnField ref

@MBelniak
Copy link
Contributor

@melloware I can confirm that custom sortFunction is not called when sortMode is 'multiple'. The function sortMultipleNodes is called in such case and it does not care about custom sortFunction

@MBelniak
Copy link
Contributor

Okay, the fix for default sorting with custom sortFunction will not be so simple. The TreeTableHeader needs to pass info about sortFunction and sortable props of Column to state of TreeTable in order to reference them in onSort. I will investigate further later.

@MBelniak
Copy link
Contributor

Turned out to be not so difficult, PR: #6436

@melloware melloware added this to the 10.6.4 milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants