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

How to define data order as accent-insensitive? #16

Open
JMG74 opened this issue Apr 20, 2023 · 2 comments
Open

How to define data order as accent-insensitive? #16

JMG74 opened this issue Apr 20, 2023 · 2 comments

Comments

@JMG74
Copy link

JMG74 commented Apr 20, 2023

Hello, does anyone know how to define a FetchXML filter that sorts the data in an accent-insensitive way?
Because currently, the component lists our accented data (French) in an accent-sensitive order whereas in Dataverse the sorting lists the data in the expected accent-insensitive order.
Thank you in advance if any of you has any clue that could guide us to a solution. Best regards.

@NielsMinnee
Copy link
Owner

NielsMinnee commented Apr 20, 2023 via email

@JMG74
Copy link
Author

JMG74 commented Apr 21, 2023

Hi Niels, I did some more investigations in the code and I think I've found the source of the problem.
In fact, this is not due to the fetchXML expression used because the list of items displayed on screen is sorted by Javascript in file operation.tsx on line 34:
allOptions.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0))

Here is one example to illustrate the problem:

The array of French words to sort: ['Zoo','zoo','Zoé','zoé','Edition', 'Editeur', 'Editions', 'Édition','Éditeur', 'Éditions']
The expected result ['Editeur', 'Éditeur', 'Edition', 'Édition', 'Editions', 'Éditions', 'zoé', 'Zoé', 'zoo', 'Zoo']
Using current code : ['Zoo','zoo','Zoé','zoé','Edition','Editeur', 'Editions', 'Édition', 'Éditeur', 'Éditions'].sort((a,b) => (a > b) ? 1 : ((b > a) ? -1 : 0))
the result is: ['Editeur', 'Edition', 'Editions', 'Zoo', 'Zoé', 'zoo', 'zoé', 'Éditeur', 'Édition', 'Éditions']...
and the order is wrong!

To fix the problem, we can use Javascript function Intl.Collator().compare (I discovered it during my investigations!).
Using the code ['Zoo','zoo','Zoé','zoé','Edition','Editeur', 'Editions', 'Édition', 'Éditeur', 'Éditions'].sort((a,b) => Intl.Collator().compare(a,b)) is giving: ['Editeur', 'Éditeur', 'Edition', 'Édition', 'Editions', 'Éditions', 'zoé', 'Zoé', 'zoo', 'Zoo'] and it's matching perfectly what I'm expecting!

Function Intl.Collator().compare works perfectly for sorting French words but might need extra options for other languages like Finish or German to get a proper accent-insensitive sorting order. In such cases, it would be necessary to define 2 new optional parameters when configuring the NNDropDown component:

Finally, line 34 in operation.tsx could be replaced by something like:
allOptions.sort((a,b) => Intl.Collator(sortingLocale,sortingOptions).compare(a.text,b.text))

As I'm not used to work with Github nor with PCF components, I cannot do the changes (and the tests) on my side... and I would greatly appreciate that you make them for me.
Many thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants