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

DataTable ignores sortFunction and sortField for initial sorting #2514

Closed
VsevolodGolovanov opened this issue Dec 13, 2021 · 1 comment · Fixed by #3060
Closed

DataTable ignores sortFunction and sortField for initial sorting #2514

VsevolodGolovanov opened this issue Dec 13, 2021 · 1 comment · Fixed by #3060
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@VsevolodGolovanov
Copy link

VsevolodGolovanov commented Dec 13, 2021

I'm submitting a ... (check one with "x")

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Codesandbox Case (Bug Reports)
https://codesandbox.io/s/datatable-ignores-sortfunction-and-sortfield-for-initial-sorting-4kuxe

Current behavior
DataTable correctly indicates initial sortField and sortOrder in header: "num" descending here. But the actual data is not sorted, the numbers are ascending:
image
This happens for both sortField or sortFunction.
But if you do

const [sortField, setSortField] = useState<string>("attributes.num");

 `field="attributes.num"

then you'd see that DataTable does in fact sort data initially, just ignoring sortField/sortFunction. This is especially painful, since it makes it harder to work around the problem by presorting the data yourself.

Expected behavior
DataTable should consult sortField/sortFunction.
You could click the "num" header twice, toggling the sortOrder, resorting the data. Then you'd see the correctly sorted data, as it should be after the initial render:
image

Minimal reproduction of the problem with instructions
Open linked codesandbox. See incorrectly sorted data.

Please tell us about your environment:

  • React version:

  • PrimeReact version:
    6.5.0, 7.1.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

  • Language: [all | TypeScript X.X | ES6/7 | ES5]

@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Mar 21, 2022
@yigitfindikli yigitfindikli added this to the 8.0.0 milestone Mar 21, 2022
@mertsincan mertsincan modified the milestones: 8.2.0, 9.0.0 Jul 6, 2022
@mertsincan mertsincan assigned cetincakiroglu and unassigned mcandu Jul 6, 2022
@melloware melloware added 👍 confirmed Type: Bug Issue contains a defect related to a specific component. and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Jul 6, 2022
emilytoy added a commit to emilytoy/primereact that referenced this issue Jul 13, 2022
…umnSortable and columnSortFunction refs when processing data. Otherwise, the refs are false and undefined, which results in the sortFunction not being run initially.
@emilytoy
Copy link
Contributor

I was still running into this issue in version 8.2.0. I just submitted #3060, which I believe fixes the issue.

@melloware melloware assigned emilytoy and unassigned cetincakiroglu Jul 13, 2022
melloware pushed a commit that referenced this issue Jul 13, 2022
* Fix #2514: If sortField is specified, determine and set columnSortable and columnSortFunction refs when processing data.  Otherwise, the refs are false and undefined, which results in the sortFunction not being run initially.

* Update var to const.
@mertsincan mertsincan modified the milestones: 9.0.0, 8.3.0 Jul 18, 2022
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.

7 participants