Open Jpsstack opened 9 years ago
Here is an example how you can provide your own sort function https://github.com/mleibman/SlickGrid/blob/master/examples/example-multi-column-sort.html
Yeah, you should use localeCompare for your custom sorting method.
["aa", "bb", "cc", "åå", "dd", "ää"].sort(function(a,b){
return a.localeCompare(b);
});
// Output is ["aa", "åå", "ää", "bb", "cc", "dd"]
@jcready, Thanks Dude... :) I tried that one.But it doesn't support in Safari at all :(
Given that you can define a sort function, this is a javascript problem, not a SlickGrid problem. How do you sort strings in your non SlickGrid related javascript ?
@Jpsstack have you tried passing a locale to localeCompare
?
Hi all,
Thanks for the support :)
I have tried localCompare with the grid.But it seems that it doesn't supported in Safari browser at all.
function localeSort(string1, string2) { return string1.toString().localeCompare(string2.toString()); }
var se=['a','ä','å','b','ö']; // Swedish
for (i=0;i<se.length;i++)
{
document.write(se[i] + "
");
}
var sortedarr1=new Array();
sortedarr1=se.sort(localeSort);
for (i=0;i<sortedarr1.length;i++)
{
document.write(sortedarr1[i] + "
");
}
a ä å b ö
a å ä b ö
a b å ä ö
// The letters other than English should come after the 'Z' in the order.Currently, the grid sorts like a b, .............. z ä // this is not right as per the Swedish alphabet. 'å' should come first instead of 'ä' å ö
Regards, Jp
After googling LocaleCompare, there seem to be a lot of issues with it AND it's incredibly slow. You're probably better to roll your own comparer. Can you convert the swedish chars to ints that you can then compare ? Perhaps a look-up array to get the correct ordering ?
@6pac, you are right. I am currently developing a look-up array for this one. Because, it needed for entire languages. But the issue related to the performance while we using this array prototype when the grid having one Lakh of data is also rolled out the concept here.
One lakh is not that much really. If you use a fast char-to-int conversion (unicode might end up two ints or an int64), some smarts to isolate the char ranges you're having problems with (the actual language chars are probably quite a small range, clearly you don't care much about esoteric punctuation or unicode chars etc), and a lookup array for those ranges, that's the best performance you're going to get under any circumstances. It's really hard for most of us to offer good suggestions as we're not familiar with the character issues and character encodings you're using. Localisation is a specialised activity all to itself! I would say however that all Swedish smart websites would have to deal with this problem. There must be a ton of prior work out there.
I used slick grid for a Domino designer application and stuck with the column sorting that have Swedish language. I guess, the grid is treats any word apart from the English as a special character.
Ex: an array have the structure : {aa,bb,cc,åå,dd,ää}
and the sorted array is : {aa,bb,cc,dd,åå,ää}
Have any idea about this one ?