I have several entries in french (with accents). When i try to get all these entries in alphabetical order, the names beginning with a "À" ("a" with accent) are at the end.
Best Answer
T
Team Savie
said
over 6 years ago
Well, I think I found something
allMatters.sort(function(a, b){
var nameA = RemoveAccents(a[Object.keys(a)[0]]);
var nameB = RemoveAccents(b[Object.keys(b)[0]]);
if ( nameA < nameB )
return -1;
if ( nameA > nameB )
return 1;
return 0;
})
function RemoveAccents(str) {
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
str = str.split('');
var strLen = str.length;
var i, x;
for (i = 0; i < strLen; i++) {
if ((x = accents.indexOf(str[i])) != -1) {
str[i] = accentsOut[x];
}
}
return str.join('');
}
with this code, I can have the sorting that i want with the game name (in French)
You could try having a duplicate searchable field in the same document that doesn't have accented characters and use that field to sort your results, then when displaying them in game use the originally accented ones.
{
"myField": "À"
"mySearchableField": "A"
}
Let me know if that helps. I'll keep looking into this for you in the mean time.
Thanks,
Liam
T
Team Savie
said
over 6 years ago
Thanks. it will help
T
Team Savie
said
over 6 years ago
Answer
Well, I think I found something
allMatters.sort(function(a, b){
var nameA = RemoveAccents(a[Object.keys(a)[0]]);
var nameB = RemoveAccents(b[Object.keys(b)[0]]);
if ( nameA < nameB )
return -1;
if ( nameA > nameB )
return 1;
return 0;
})
function RemoveAccents(str) {
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
str = str.split('');
var strLen = str.length;
var i, x;
for (i = 0; i < strLen; i++) {
if ((x = accents.indexOf(str[i])) != -1) {
str[i] = accentsOut[x];
}
}
return str.join('');
}
with this code, I can have the sorting that i want with the game name (in French)
Team Savie
Hi,
I have several entries in french (with accents). When i try to get all these entries in alphabetical order, the names beginning with a "À" ("a" with accent) are at the end.
Well, I think I found something
with this code, I can have the sorting that i want with the game name (in French)
Hope that code will help others
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Savie,
You could try having a duplicate searchable field in the same document that doesn't have accented characters and use that field to sort your results, then when displaying them in game use the originally accented ones.
Let me know if that helps. I'll keep looking into this for you in the mean time.
Thanks,
Liam
Team Savie
Thanks. it will help
Team Savie
Well, I think I found something
with this code, I can have the sorting that i want with the game name (in French)
Hope that code will help others
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics