Sorting problems with some "strange" letters (in .NET)

Sorting problems with some "strange" letters (in .NET)

SwanSwan Posts: 17Questions: 0Answers: 0
edited March 2011 in General
Hello!

In some of the discussions where people were facing similar problems when sorting non-english letters some suggest using of localeCompare function (http://datatables.net/forums/comments.php?DiscussionID=397). However this options doesn't work in all browsers (I've found out that is not working in version of Chrome I'm using) or it's maybe dependant of the language settings of browsers.

My coworker implemented this solution in classic ASP:
[code]
"string-asc": function ( a, b )
{
var x = a.replace(/?/g, "CZ").toLowerCase();
x = x.replace(/?/g, "CZ").toLowerCase();
x = x.replace(/?/g, "DZ").toLowerCase();
x = x.replace(/Š/g, "SZ").toLowerCase();
x = x.replace(/Ž/g, "ZZ").toLowerCase();
x = x.replace(/?/g, "cz").toLowerCase();
x = x.replace(/?/g, "cz").toLowerCase();
x = x.replace(/?/g, "dz").toLowerCase();
x = x.replace(/š/g, "sz").toLowerCase();
x = x.replace(/ž/g, "zz").toLowerCase();
var y = b.replace(/?/g, "CZ").toLowerCase();
y = y.replace(/?/g, "CZ").toLowerCase();
y = y.replace(/?/g, "DZ").toLowerCase();
y = y.replace(/Š/g, "SZ").toLowerCase();
y = y.replace(/Ž/g, "ZZ").toLowerCase();
y = y.replace(/?/g, "cz").toLowerCase();
y = y.replace(/?/g, "cz").toLowerCase();
y = y.replace(/?/g, "dz").toLowerCase();
y = y.replace(/š/g, "sz").toLowerCase();
y = y.replace(/ž/g, "zz").toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
},

"string-desc": function ( a, b )
{
var x = a.replace(/?/g, "CZ").toLowerCase();
x = x.replace(/?/g, "CZ").toLowerCase();
x = x.replace(/?/g, "DZ").toLowerCase();
x = x.replace(/Š/g, "SZ").toLowerCase();
x = x.replace(/Ž/g, "ZZ").toLowerCase();
x = x.replace(/?/g, "cz").toLowerCase();
x = x.replace(/?/g, "cz").toLowerCase();
x = x.replace(/?/g, "dz").toLowerCase();
x = x.replace(/š/g, "sz").toLowerCase();
x = x.replace(/ž/g, "zz").toLowerCase();
var y = b.replace(/?/g, "CZ").toLowerCase();
y = y.replace(/?/g, "CZ").toLowerCase();
y = y.replace(/?/g, "DZ").toLowerCase();
y = y.replace(/Š/g, "SZ").toLowerCase();
y = y.replace(/Ž/g, "ZZ").toLowerCase();
y = y.replace(/?/g, "cz").toLowerCase();
y = y.replace(/?/g, "cz").toLowerCase();
y = y.replace(/?/g, "dz").toLowerCase();
y = y.replace(/š/g, "sz").toLowerCase();
y = y.replace(/ž/g, "zz").toLowerCase();
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
},
[/code]

In the "big file" for DataTables plugin.

However this doesn't work in ASP.NET pages. I was breaking my head and trying different thing before realize that problem lays in page not in javascript code.

In .NET you have to put CodePage="1250" in the .ASPX page where class inheritance is defined.

However this can have some drawbacks with your current code - especially if you are exporting data from tables to Excel so you should look for other codePages as well.

I remembered this codePage "thing" since it helped when I have to export some table to Excel all "special" characters were screwed up.

Loos like the sorting is working now.

And IMPORTANT: don't forget to tell your plugin that it must sort columns as string. Otherwise this won't work.
This discussion has been closed.