Order DataTable with accents

Order DataTable with accents

GeaGea Posts: 33Questions: 13Answers: 1

Hi! So, i have a json that have names with accents, but when i start my app, the names with accents are in the end.
Example:
" if i have Angela, Ángela, Maria, Robert, it's seems like that:
Angela
Maria
Robert
Ángela
"
I want that the names with accents don't appear on the end, but like that:
"
Angela
Ángela
Maria
Robert
"
Anny idea? Thanks !!!!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Try this plug-in. Despite the name it will work for a number of languages since it uses localeCompare. The reason that isn't the default in DataTables is that its slower than a string compare (significantly slower) and there were bugs in its implementation in old versions of IE.

    There is a new i18n API in the Javascript standard which I'll be writing a plug-in for and blogging about soon. The WebKit folks are working on implementing it just now and I thin they are the last browser engine to implement it.

    Regards,
    Allan

  • GeaGea Posts: 33Questions: 13Answers: 1

    It's works for me!
    Thanks!

  • GeaGea Posts: 33Questions: 13Answers: 1

    Hello Allan, i got problems with the plug-in.
    When i tried to order columns with null value, the localeCompare displayed me an error.
    I changed the plug-in and now it works perfectly.
    Here is the code:

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "chinese-string-asc" : function (s1, s2) {
            if(s1 != null && s1 != undefined && s2 != null && s2 != undefined){
                return s1.localeCompare(s2);
            }else if(s2 == null || s2 == undefined){
                return s1;
            }else if(s1 == null || s1 == undefined){
                return s2;
            }
        },
    
        "chinese-string-desc" : function (s1, s2) {
            if(s1 != null && s1 != undefined && s2 != null && s2 != undefined){
                return s2.localeCompare(s1);
            }else if(s2 == null || s2 == undefined){
                return s1;
            }else if(s1 == null || s1 == undefined){
                return s2;
            }
     }
    } );
    

    Regards.
    Gea.

This discussion has been closed.