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

Sorting strings with orthographic accent (spanish) #128

Open
imcarlosdev opened this issue Mar 18, 2017 · 2 comments
Open

Sorting strings with orthographic accent (spanish) #128

imcarlosdev opened this issue Mar 18, 2017 · 2 comments

Comments

@imcarlosdev
Copy link

Plugin is working very well but there is an issue with accents in spanish, when i sort the table with this content:

A
B
C
D
E
F
G
É <---------- This character must be after D letter but when i sort his position is at last of the rows.

@Mottie
Copy link
Collaborator

Mottie commented Apr 24, 2018

Hi @choquo!

Tablesorter includes a sortLocaleCompare option which uses localeCompare without any options to sort the content; but it doesn't work in this case.

What you'll need to do is create a parser to remove the accents (demo).

// Use to replace combining diacritics
var regex = /[\u0300-\u036f]/g;

$.tablesorter.addParser({
  id: 'diacritic',
  is: function() {
    return false;
  },
  format: function(s) {
    // .normalize() is only supported in newer browsers
    return s.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
  },
  type: 'text'
})

$('table').tablesorter({
  headers: {
    0: {
      sorter: 'diacritic'
    }
  }
});

This method still isn't ideal as it strips the diacritics instead of ordering them as they should be within the alphabet. To accomplish this, you'll need to use my fork of tablesorter along with Sugar.js' sorting algorithm (demo).

@imcarlosdev
Copy link
Author

Thanks for your help @Mottie

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