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

Issue in Grid sorting, null values not handled in sortMultiple function (when sortMode=multiple) #2157

Closed
yashkk3640 opened this issue Jul 2, 2021 · 4 comments · Fixed by #2440
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@yashkk3640
Copy link

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)
Please fork the codesandbox below and create a case demonstrating your bug report. Issues without a codesandbox have much less possibility to be reviewed.

https://codesandbox.io/s/wonderful-lederberg-2cvgy?file=/src/demo/DataTableSortDemo.js
image

Current behavior
Sorting not working properly when sortMode=multiple

Expected behavior
It's should be sort properly all types of data don't matter user sorting single or multiple sorts when sortMode=multiple

@yashkk3640 yashkk3640 changed the title Issue in Grid sorting null values not handled in sortMultiple function (when sortMode=multiple) Issue in Grid sorting, null values not handled in sortMultiple function (when sortMode=multiple) Jul 2, 2021
@Liam-OShea
Copy link

Liam-OShea commented Jul 5, 2021

I am also experiencing this issue, additionally the null values appear to break the sort so that even without the null values the rows are out of order. The issue is resolved if sortMode=multiple is removed.

Additionally, should null values be sorted to the bottom of the table, regardless of asc or desc sort order?
(Note I have a template setup to display -- when a null cell is encountered)

NullMultipleSort

@Liam-OShea
Copy link

Please note this issue can be fixed by applying a sort function rather than using the table's default sort function. I used this one from a previous issue:

#348

However I am not sure how to import Objectutils. I ended up copying and pasting the resolveFieldData and isFunction methods.

@ursfan
Copy link

ursfan commented Nov 8, 2021

Unfortunately this issue wasn't fixed yet and can't be solved by #348 in our case. In my opinion the implementations of the primereact datatable's sorting functions for single and multiple sort should treat the null values in the same way. Currently the null values are only treated correctly for "sortSingle", but not for "sortMultiple". In the case of multiple columns selected the sort function of the datatable.js file treats NULL-values as number values.

The code is as follows in the function "multisortField" of datatable.js:
...
if (typeof value1 === 'string' || value1 instanceof String) {
if (value1.localeCompare && value1 !== value2) {
return multiSortMeta[index].order * value1.localeCompare(value2, undefined, {
numeric: true
});
}
} else {
result = value1 < value2 ? -1 : 1;
}
...

while the function "sortSingle" is currently implemented as follows for the datatable.js:
...
if (value1 == null && value2 != null) result = -1;else if (value1 != null && value2 == null) result = 1;else if (value1 == null && value2 == null) result = 0;else if (typeof value1 === 'string' && typeof value2 === 'string') result = value1.localeCompare(value2, undefined, {
numeric: true
});else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
...

At the moment the only workaround for this is to hand over all null-values as empty strings to the datatable, but this has consequences in other parts of our application.

Is there a chance that issue will be solved in a future version of primereact?

@melloware
Copy link
Member

PR Submitted

@mertsincan mertsincan added the Type: Bug Issue contains a defect related to a specific component. label Dec 10, 2021
@mertsincan mertsincan added this to the 8.0.0 milestone Dec 10, 2021
mertsincan added a commit that referenced this issue Dec 10, 2021
@mertsincan mertsincan modified the milestones: 8.0.0, 7.1.0 Dec 13, 2021
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.

5 participants