DataTables Multilingual Sorting

DataTables Multilingual Sorting

aaronloesaaronloes Posts: 10Questions: 0Answers: 0
edited November 2012 in General
I looked in the internationalization section of the site for this answer, but that only discusses how to change the displayed text for things.

My question is how does DataTables perform is sorting on textual content when the data is in different languages. For out implementation, we need to be able to sort properly for data given in different languages (e.g. English, French, German, Spanish, Chinese, Japanese, Korean, etc.). Does it sort it properly and is there a way to specify how to tell DataTables how to sort (I think I remember reading there was a way)?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    A sorting method that uses localeCompare ( https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/localeCompare ) would do the business. I did actually put that into DataTables core during the 1.8 betas, but IE9 completely screws it up in my unit tests, so I backed it out. However, if you are happy that the browsers you use are going to be able to use localCompare correctly, that is certainly the way to go.

    Allan
  • aaronloesaaronloes Posts: 10Questions: 0Answers: 0
    Thank you Allan.

    Is there a way to override the sorting mechanism?

    [quote]allan said: A sorting method that uses localeCompare ( https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/localeCompare ) would do the business. I did actually put that into DataTables core during the 1.8 betas, but IE9 completely screws it up in my unit tests, so I backed it out. However, if you are happy that the browsers you use are going to be able to use localCompare correctly, that is certainly the way to go.[/quote]

    How does it perform its default textual sort now?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Simple comparison: https://github.com/DataTables/DataTables/blob/master/media/js/jquery.dataTables.js#L11596 . You'd replace that with localeCompare.

    Allan
This discussion has been closed.